//现在初始化里面定义后边要使用的redis参数
public function_initialize(){
PHPweb批量更新文章parent::_initialize();
$goods_id = I("goods_id",'0','intval');
if($goods_id){
$this->goods_id = $goods_id;
$this->user_queue_key = "goods_".$goods_id."_user";//当前商品队列的用户情况
$this->goods_number_key = "goods".$goods_id;//当前商品的库存队列
}
$this->user_id = $this->user_id ? $this->user_id : $_SESSION['uid'];
}
2.4. 第二步就是关键所在,用户在进入商品详情页前先将当前商品的库存进行队列存入redis如下:
* 访问产品前先将当前产品库存队列
* @access public
* @author bieanju
*/
publicfunction_before_detail(){
$where['goods_id'] = $this->goods_id;
$where['start_time'] = array("lt"PHPweb批量添加产品,time());
$where['end_time'] = array("gt",time());
$goods= M("goods")->where($where)->field('goods_num,start_timePHPweb批量删除关键词 ,end_time')->find();
!$goods&& $this->error("当前秒杀已结束PHPweb批量上传内容 !");
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}"PHPweb批量助手 , 1);
}
}
$resetRedis= $redis->llen("{$this->goods_number_key}");
if(!$resetRedis){
$this->error("系统繁忙,请稍后抢购PHPweb批量添加栏目!");
}
}else{
$this->error("当前产品已经秒杀完!");
}
}
接下来要做的就是用ajax来异步的处理用户点击购买按钮进行符合条件的数据进入购买的排队队列(如果当前用户没在当前产品用户的队列就进入排队并且pop一个库存队列,如果在就抛出,):
下一篇:留住用户,比拉新更重要
文章地址:https://www.tianxianmao.com/article/other/xzcshlmdyhbysydrediscs.html