<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class SignAction extends MemberAction
{
    public function run()
    {
        if (IS_MOBILE || isUCWeb())
        {
            throw new iSystemException('尊贵的会员，系统监测到你当前可以进行抽奖<br/>'.getAdsLinks('&lt;&lt;马上进去抽奖&gt;&gt;',1));
        }

        $check = $this->db()->getValue('SELECT COUNT(*) FROM '.SignLog::table().' WHERE `date`='.S::sqlEscape(CDATE).' AND uid = '.$this->uid());
        if ($check)
        {
            throw new iSystemException('您今天已经签过到了，明天继续^_^');
        }
        $credit = rand(20, 40);
        $this->db()->insert(SignLog::table())->value(array('uid'=>$this->uid(),'credit'=>$credit,'date'=>CDATE,'createdate'=>CDATETIME,'ua'=>S::getServer('HTTP_USER_AGENT')))->q();
        iCredits::single($this->uid(), $this->userName())->addMoney($credit);

        $message[] = '恭喜您签到成功，获得'.$credit.setting('creditname').'奖励，无法抽奖的用户每天都有一次签到机会哦';
        $message[] = '返回'.backLink('上级').'.'.memberLink().'.'.indexLink();
        $this->showMessage($message);
    }
}
