...
|
...
|
@@ -70,6 +70,9 @@ class GoodsController extends RestBaseController |
|
|
if ($user_score<$param['price']){
|
|
|
$this->error('用户积分不足',2);
|
|
|
}
|
|
|
if (Db::name('goods_order')->where('id',$param['id'])->find()['stock']<$param['count']){
|
|
|
$this->error('商品库存不足',3);
|
|
|
}
|
|
|
$re=Db::name('goods_order')->insert([
|
|
|
'user_id'=>$this->getUserId(),
|
|
|
'goods_id'=>$param['goods_id'],
|
...
|
...
|
@@ -82,10 +85,11 @@ class GoodsController extends RestBaseController |
|
|
]);
|
|
|
if ($re) {
|
|
|
Db::name('user')->where('id',$this->getUserId())->setDec('score',$param['score']);
|
|
|
Db::name('user_score_log')->insert(['user_id'=>$this->getUserId(),'score'=>-$param['score'],'action'=>'消费','now_score'=>$user_score-$param]);
|
|
|
Db::name('user_score_log')->insert(['user_id'=>$this->getUserId(),'score'=>-$param['score'],'action'=>'消费','now_score'=>$user_score-$param['score']]);
|
|
|
Db::name('goods')->where('id',$param['goods_id'])->setDec('stock',$param['count']);
|
|
|
$this->success('兑换成功',1);
|
|
|
}else{
|
|
|
$this->error('兑换失败',3);
|
|
|
$this->error('兑换失败',4);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|