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

/**
 * 高级评论处罚
 *
 * @author yzxh24
 */
class PunishAction extends BaseAction
{
    public function run()
    {
        $id = intval($_GET['id']);
        $reply = BookPostReplys::model()->findByPk($id);
        if (empty($reply))
        {
            throw new CHttpException(500, '不存在的高级评论');
        }
        if (!$reply->isfirst)
        {
            throw new CHttpException(500, '非主题贴不能处罚');
        }
        if ($reply->ispunish)
        {
            throw new CHttpException(500, '此贴已经处罚过，请不要重复处罚');
        }

        $reply->ispunish = 1;
        $reply->save();
        
        // 扣除会员相应的积分
        Member::model()->updateCounters(array('extcredits1'=>-100),'uid='.$reply->uid);

        // 发站内信通知
        $subject = '[系统信息]违规高级贴删除通知';
        $message= '亲爱的书友,经其他书友举报,您发布的高级贴《'.$reply->subject.'》违反规定,经查证属实,给予删除并处罚扣除'.setting('creditname').'100个,敬请遵守高级贴发帖规定,感谢您的配合与谅解';
        
        Messages::model()->create($subject,$message,$reply->uid);

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