<?php
/**
 * 添加永久自动书签
 */
require_once dirname(dirname(__FILE__)) . '/init.php';
$uid = $argv[1];
$day = $argv[2];
if (empty($uid))
{
    die("请输入UID\n");
}

try
{
    $member = Members::single()->getOne($uid);
}
catch (MemberNotExistsException $exce)
{
    die($exce->getMessage()."\n");
}

//$option = 'a:2:{s:5:"class";i:2;s:6:"expire";s:10:"1609257600";}';
$time = !empty($day) && is_numeric($day) ? strtotime("+$day day") : 1609257600;
$option = serialize(array('class'=>2,'expire' => $time));

$check = $db->getValue('SELECT COUNT(*) FROM '.PropertyMember::table().' WHERE uid='.$uid.' AND property_id = 13');
if (!$check)
{
    $db->insert(PropertyMember::table())->value(array('uid'=>$uid,'username'=>$member['username'],'property_id'=>13,'option'=>$option))->q();
}
else
{
    $db->update(PropertyMember::table())->value(array('option'=>$option))->where('uid='.$uid.' AND property_id = 13')->q();
}
$db->update(MemberExts::table())->value(array('autoprogress'=>$time))->where('uid='.$uid)->q();