作者 潘浩文
1 个管道 的构建 通过 耗费 3 秒

个人中心接口

@@ -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