<?php
/**
 * Created by JetBrains PhpStorm.
 * User: yzxh24
 * Date: 11-11-7
 * Time: 下午4:20
 * To change this template use File | Settings | File Templates.
 */
class RewardAction extends BaseAction
{
    public function run()
    {
        $id = Yii::app()->request->getQuery('id');
        $respone = TaskRespone::model()->findByPk($id);
        
        $task = Task::model()->findByPk($respone->task_id);
        $subject = '[系统消息]任务完成奖励';
        $content = '恭喜您完成了任务《'.$task->subject.'》，获得'.$task->reward.setting('creditname').'奖励！<br/>[url=http://25800.net/system.php?s=member&c=task]马上参加更多活动&gt;&gt;[/url]';
        Messages::model()->create($subject, $content, $respone->uid);

        $tasker = Tasker::model()->find(array('condition' => $respone->tasker_id));
        $tasker->status = 3;
        $tasker->updatedate = date('Y-m-d H:i:s');
        $tasker->save();

        $respone->status = 1;
        $respone->save();

        $task->count = $task->count + 1;
        $task->save();

        $iCredit = iCredits::single($respone->uid, $respone->username);
        $iCredit->setUid($respone->uid);
        $iCredit->setUserName($respone->username);
        $iCredit->addMoney($task->reward);
        
        $this->getController()->redirect(array('respone'));
    }
}