<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DeleteBookAction extends BcartAction
{
    public function run()
    {
        $bcart = $this->check();
        $bid = S::gp('bid', 'G', 2);

        if (!$_GET['confirm'])
        {
            $message[] = '确定要删除吗？删除后将不可恢复！';
            $message[] = $this->getController()->link('删除',url('system',array('s'=>'bcart','c'=>'member','a'=>'dbook','id'=>$bcart['id'], 'bid'=>$bid,'confirm'=>1))).'|'.$this->getController()->link('取消',url('system',array('s'=>'bcart','a'=>'view','id'=>$bcart['id'])));
            $this->showMessage($message);
        }

        $this->db()->update(BcartSubject::table())->value(array('isdelete'=>1))->where(array('id'=>$bid))->q();

        $bNum = $this->db()->getValue('SELECT COUNT(*) FROM '.BcartSubject::table().' WHERE uid='.S::sqlEscape($this->uid()).' AND isdelete = 0 AND bcid='.S::sqlEscape($bcart['id']));
        $update['bnum'] = $bNum;
        if ($bNum < 3)
        {
            $update['display'] = 0;
        }
        $this->db()->update(Bcarts::table())->value($update)->where(array('id'=>$bcart['id']))->q();
        
        iforward(url('system', array('s'=>'bcart','a'=>'view', 'id'=>$bcart['id'])));
    }
}
