最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
北京赛车pk10
时间:2017-11-15 19:49:49 编辑:猪哥 来源:转载
废话不多说了,直接给大家贴代码了,具体代码如下所示:
db->createCommand("select * from goods ")->queryAll(); return $this->render('index',['data'=>$data]); } Public function actionXx() { $id=yii::$app->request->get('id'); $data=yii::$app->db->createCommand("select * from goods where id='$id'")->queryOne(); return $this->render('info',['data'=>$data]); } Public function actionAdd() { $a=yii::$app->redis; if (Yii::$app->request->isPost) { $data=yii::$app->request->post(); $res=yii::$app->db->createCommand()->insert('goods',$data)->execute(); if($res) { for ($i=0; $i <$data['counts'] ; $i++) { $a->lpush('goods',1); } return $this->redirect(array('goods/info')); } else { echo "添加失败"; } } else { return $this->render('add'); } } public function actionOrder() { $redis=yii::$app->redis; $count=$redis->lpop('goods'); if(empty($count)) { echo "库存不足";die; } $res=yii::$app->db->createCommand("update goods set counts=counts-1 where id=1 and counts>0")->execute(); if($res) { echo "秒杀成功"; } else { echo "秒杀失败"; } } } ?>
相关文章
- YII框架批量插入数据的方法07-06
- YII中Ueditor富文本编辑器文件和图片上传的配置图文教程06-28
- Yii 2.0中场景的使用教程06-05
- 利用Yii框架实现图片上传05-22
- Yii框架如何使用魔术方法实现跨文件调用功能05-22
- 实例:YII2框架中使用yii.js实现的post请求04-13
文章评论