<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 高级贴投诉奖励
 *
 * @author yzxh24
 */
class AwardAction extends BaseAction
{
    public function run()
    {
        $id = intval($_GET['id']);
        $complaints = BookPostComplaint::model()->findByPk($id);

        if (empty($complaints))
        {
            throw new CHttpException(500, '不存在的投诉');
        }
        if ($complaints->isaward)
        {
            throw new CHttpException(500, '此投诉已经奖励过');
        }

        $reply = BookPostReplys::model()->find('postid='.$complaints->postid.' AND isfirst=1');
        if (empty($reply))
        {
            throw new CHttpException(500, '当前被投诉的高级贴不存在，可能已经被删除，不能再奖励');
        }

        $complaints->isaward = 1;
        $complaints->save();

        // 给会员加上相应的积分
        Member::model()->updateCounters(array('extcredits1'=>20),'uid='.$complaints->uid);

        // 发站内信通知
        $subject = '[系统信息]举报违规高级贴奖励通知';
        $message= '亲爱的'.setting('webname').'书友,您所举报的高级贴《'.$reply->subject.'》违反规定,经查证属实,给予'.setting('creditname').'奖励20个,感谢您的支持';
        Messages::model()->create($subject,$message,$complaints->uid);

        $this->getController()->redirect(array('list'));
    }
}