正在显示
1 个修改的文件
包含
6 行增加
和
2 行删除
@@ -70,6 +70,9 @@ class GoodsController extends RestBaseController | @@ -70,6 +70,9 @@ class GoodsController extends RestBaseController | ||
70 | if ($user_score<$param['price']){ | 70 | if ($user_score<$param['price']){ |
71 | $this->error('用户积分不足',2); | 71 | $this->error('用户积分不足',2); |
72 | } | 72 | } |
73 | + if (Db::name('goods_order')->where('id',$param['id'])->find()['stock']<$param['count']){ | ||
74 | + $this->error('商品库存不足',3); | ||
75 | + } | ||
73 | $re=Db::name('goods_order')->insert([ | 76 | $re=Db::name('goods_order')->insert([ |
74 | 'user_id'=>$this->getUserId(), | 77 | 'user_id'=>$this->getUserId(), |
75 | 'goods_id'=>$param['goods_id'], | 78 | 'goods_id'=>$param['goods_id'], |
@@ -82,10 +85,11 @@ class GoodsController extends RestBaseController | @@ -82,10 +85,11 @@ class GoodsController extends RestBaseController | ||
82 | ]); | 85 | ]); |
83 | if ($re) { | 86 | if ($re) { |
84 | Db::name('user')->where('id',$this->getUserId())->setDec('score',$param['score']); | 87 | Db::name('user')->where('id',$this->getUserId())->setDec('score',$param['score']); |
85 | - Db::name('user_score_log')->insert(['user_id'=>$this->getUserId(),'score'=>-$param['score'],'action'=>'消费','now_score'=>$user_score-$param]); | 88 | + Db::name('user_score_log')->insert(['user_id'=>$this->getUserId(),'score'=>-$param['score'],'action'=>'消费','now_score'=>$user_score-$param['score']]); |
89 | + Db::name('goods')->where('id',$param['goods_id'])->setDec('stock',$param['count']); | ||
86 | $this->success('兑换成功',1); | 90 | $this->success('兑换成功',1); |
87 | }else{ | 91 | }else{ |
88 | - $this->error('兑换失败',3); | 92 | + $this->error('兑换失败',4); |
89 | } | 93 | } |
90 | } | 94 | } |
91 | 95 |
-
请 注册 或 登录 后发表评论