...
|
...
|
@@ -194,6 +194,63 @@ class Car extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (编辑购物车)
|
|
|
* @ApiSummary (编辑购物车)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/car/editCar)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name=car_id, type=string, required=true, description="购物车id")
|
|
|
* @ApiParams (name=number, type=string, required=true, description="数量")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "SUCCESS",
|
|
|
"time": "1587472510",
|
|
|
"data": {
|
|
|
"total": 1,
|
|
|
"list": [
|
|
|
{
|
|
|
"content": "content", 评论内容
|
|
|
"images": [
|
|
|
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
|
|
|
],
|
|
|
"createtime": "2020-04-20", 评论日期
|
|
|
"avatar": "avatar", 用户头像
|
|
|
"nickname": "admin" 用户昵称
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function editCar(){
|
|
|
$userId = $this->getUserId();
|
|
|
$data = $this->request->param();
|
|
|
$data['user_id'] = $userId;
|
|
|
$validate = new Validate([
|
|
|
'car_id' => 'require',
|
|
|
'number' => 'require',
|
|
|
]);
|
|
|
|
|
|
$validate->message([
|
|
|
'car_id' => '缺少参数 car_id!',
|
|
|
'number' => '缺少参数 number!',
|
|
|
]);
|
|
|
|
|
|
if (!$validate->check($data)) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
if ($data['number'] == 0) $this->error('数量不能为0');
|
|
|
$carInfo = $this->carModel->where('id',$data['car_id'])->find();
|
|
|
|
|
|
$stock_num = Db::name('goods')->where(['id'=>$carInfo['goods_id']])->value('stock_num');
|
|
|
if (empty($stock_num) || $stock_num < $data['number']) $this->error('库存不足');
|
|
|
|
|
|
$res = $this->carModel->where('id',$data['car_id'])->update(['number'=>$data['number']]);
|
|
|
|
|
|
if ($res) $this->success('SUCCESS');
|
|
|
else $this->error('ERROR');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (购物车数量递增)
|
|
|
* @ApiSummary (购物车数量递增)
|
|
|
* @ApiMethod (POST)
|
...
|
...
|
|