作者 景龙
1 个管道 的构建 失败 耗费 1 秒

增加删除购物车

... ... @@ -110,4 +110,41 @@ class Cars extends Api
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (购物车列表)
* @ApiSummary (购物车列表)
* @ApiMethod (GET)
* @ApiRoute (/api/cars/clearCar)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="string", required=true, description="购物车id(多个以逗号隔开)")
* @ApiReturn({
"code": 1,
"msg": "删除成功",
"time": "1555504723",
"data": 2
})
*/
public function clearCar(){
if($this->request->isGet()){
$c_id = $this->request->get('id');//购物车id,以逗号隔开字符(“1,2,3”)
$rule = config('site.cars');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$c_id])) {
$this->error($validate->getError());
}
$c_ids = explode(',',$c_id);
$data = Db::table('gc_car')
->whereIn('id',$c_ids)
->where(['uid'=>$this->user_id])
->delete();
if($data){
$this->success('删除成功',$data);
}else{
$this->error('删除失败');
}
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -308,4 +308,12 @@ return array (
'type' => '请选择支付类型',
]
],
'cars' => [
'rule' => [
'id' => 'require',
],
'msg' => [
'id.require' => '购物车id不能为空',
]
],
);
\ No newline at end of file
... ...
此 diff 太大无法显示。