php 中的秒杀

 1 控制器层
 2  //秒杀 首先要判断库存  其次高并发  然后入库
 3     public function goods_do()
 4     {
 5         $gid=input("get.gid");
 6         $user_name=Session::get("user_name");
 7         $obj = new Goods();
 8         $ku_num=$obj->getNum($gid);
 9         if($ku_num<1)
10         {//库存不够
11             return 1;
12         }
13 
14         /*$redis=new \Redis();
15         $redis->connect('127.0.0.1','6379');
16         $redis->lPush("spick",$user_name);*/
17 
18         $data['user_name']=$user_name;
19         $data['g_id']=$gid;
20         $data['add_time']=time();
21         $data['payment']=0;
22         $paymentObj = new Payment();
23         $id=$paymentObj->add_payment($data);
24         Session::set('id',$id);
25         if($id)
26         {
27             return 1;
28 //            $this->success("秒杀成功,正在跳转支付页面",'payment_show');
29         }
30     }

 

posted @ 2019-04-04 15:23  PHP小媛  阅读(408)  评论(0编辑  收藏  举报