/**
* 访问产品前先将当前产品库存队列
* @access public
* @author bieanju
*/
public function _before_detail(){
$where[‘goods_id‘] = $this->goods_id;
$where[‘start_time‘] = array("lt",time());
$where[‘end_time‘] = array("gt",time());
$goods = M("goods")->where($where)->field(‘goods_num,start_time,end_time‘)->find();
!$goods && $this->error("当前秒杀已结束!");
if($goods[‘goods_num‘] > $goods[‘order_num‘]){
$redis = $this->connectRedis();
$getUserRedis = $redis->hGetAll("{$this->user_queue_key}");
$gnRedis = $redis->llen("{$this->goods_number_key}");
/* 如果没有会员进来队列库存 */
if(!count($getUserRedis) && !$gnRedis){
for ($i = 0; $i < $goods[‘goods_num‘]; $i ++) {
$redis->lpush("{$this->goods_number_key}", 1);
}
}
$resetRedis = $redis->llen("{$this->goods_number_key}");
if(!$resetRedis){
$this->error("系统繁忙,请稍后抢购!");
}
}else{
$this->error("当前产品已经秒杀完!");
}
}