<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DigAction extends ForumAction
{
    public function run()
    {
        $this->getController()->isLogin();
        
        $bookPostReply = BookPostReply::single();
        $postId = S::gp('cid','G',2);
        $allowDo = array('good','bad');
        $do = S::gp('do','G');
        if (!in_array($do, $allowDo))
        {
            throw new iSystemException('非法操作');
        }
    
        $thread = $bookPostReply->getThread($postId);
        if (empty($thread))
        {
            throw new iSystemException('不存在的主题贴');
        }
    
        if ($bookPostReply->mustBuy($thread))
        {
            $bookPostReply->halt($thread);
        }
    
        if (in_array($this->uid(), explode(',',$thread['good'])) || in_array($this->uid(), explode(',', $thread['bad'])))
        {
            throw new iSystemException('您已经评价过此贴了');
        }
        
        $this->db()->update($bookPostReply->table())->value(array($do=>$thread[$do].','.$this->uid()))->where(array('postid'=>$postId,'isfirst'=>1))->q();
        $url = url('system',array('s'=>'forum','c'=>'advance','a'=>'read','id'=>$this->id(),'cid'=>$postId));
        iforward($url);
    }
}