<?php
/**
 * 增值服务排队
 *
 */
class VasQueueLimit extends Vas{
 public function __construct($table = 'vas_limit') {
        parent::__construct($table);
    }


    /**
     * 根据服务类型查询目前的购买次数
     * @param string $type 服务类型
     * @return array
     */
    public function findtypenum($type) {
        $sql = SqlCombinHelper::select_sql($this->table, 'number',
                "type = '".$type."'");
        return $this->db->getOne($sql);
    }


        /**
     * 根据服务类型查询目前的购买次数
     * @param string $type 服务类型
     * @return array
     */
    public function findtypelimitnum($type) {
        $fieldsMKey = 'findtypenum'.$type;
         $limitnum = $this->mc->get($fieldsMKey);
         if(empty($limitnum)){
        $sql = SqlCombinHelper::select_sql($this->table, 'limit_num',
                "type = '".$type."'");
        $limitnum = $this->dbback->getOne($sql);
        $this->mc->set($fieldsMKey, $limitnum, 3600);
         }
        return $limitnum;
    }
    
    
     /**
     * 根据类型增加减少排队人数
     * @param int $type 类型
     * @param int $number 排队人数
     * @return boolean 成功返回true，失败返回false
     */
    public function addNumberToOneType($type, $number) {
        $number = $number > 0 ? '+' . $number : $number;
        $arrField['number'] =   $number;
        $sql = SqlCombinHelper::updateSelf_sql($this->table, $arrField, 
                "type = '".$type."'");
        return $this->db->execute($sql);
    }
    
    
    
    
}
