2024-06-01 17:22:46 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\api\controller\order;
|
|
|
|
|
|
|
|
|
|
use app\api\logic\order\CartLogic;
|
|
|
|
|
use app\api\validate\CartValidate;
|
|
|
|
|
use app\api\controller\BaseApiController;
|
|
|
|
|
use app\api\lists\order\CartList;
|
|
|
|
|
use app\common\model\order\Cart;
|
2024-06-04 16:51:26 +08:00
|
|
|
|
use hg\apidoc\annotation as ApiDoc;
|
|
|
|
|
#[ApiDoc\NotParse()]
|
2024-06-01 17:22:46 +08:00
|
|
|
|
|
|
|
|
|
class CartController extends BaseApiController
|
|
|
|
|
{
|
|
|
|
|
public function list(){
|
|
|
|
|
return $this->dataLists(new CartList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 添加购物车
|
|
|
|
|
*/
|
2024-06-04 11:58:51 +08:00
|
|
|
|
public function create(){
|
2024-06-01 17:22:46 +08:00
|
|
|
|
$params = (new CartValidate())->post()->goCheck('add');
|
|
|
|
|
$params['uid']=$this->request->userId;
|
2024-06-04 11:58:51 +08:00
|
|
|
|
$result=Cart::where(['uid'=>$params['uid'],'store_id'=>$params['store_id'],'product_id'=>$params['product_id'],'is_fail'=>0,'delete_time'=>null])->find();
|
|
|
|
|
$count=Cart::where(['uid'=>$params['uid'],'delete_time'=>null,'is_pay'=>0])->count();
|
2024-06-01 17:22:46 +08:00
|
|
|
|
if($count>100){
|
|
|
|
|
return $this->fail('购物车商品不能大于100个,请先结算');
|
|
|
|
|
}
|
|
|
|
|
if($result){
|
|
|
|
|
$res=CartLogic::edit($params);
|
|
|
|
|
}else{
|
|
|
|
|
$res=CartLogic::add($params);
|
|
|
|
|
}
|
|
|
|
|
if($res){
|
|
|
|
|
return $this->success('添加成功');
|
|
|
|
|
}else{
|
|
|
|
|
return $this->fail(CartLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 修改购物车
|
|
|
|
|
*/
|
|
|
|
|
public function change(){
|
|
|
|
|
$params = (new CartValidate())->post()->goCheck('change');
|
|
|
|
|
$params['uid']=$this->request->userId;
|
|
|
|
|
$res=CartLogic::edit($params,'dec');
|
|
|
|
|
if($res){
|
|
|
|
|
return $this->success('修改成功');
|
|
|
|
|
}else{
|
|
|
|
|
return $this->fail(CartLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @notes 删除购物车
|
|
|
|
|
*/
|
|
|
|
|
public function delete(){
|
|
|
|
|
$params = (new CartValidate())->post()->goCheck('delete');
|
|
|
|
|
$params['uid']=$this->request->userId;
|
|
|
|
|
$res=CartLogic::delete($params);
|
|
|
|
|
if($res){
|
|
|
|
|
return $this->success('删除成功');
|
|
|
|
|
}else{
|
|
|
|
|
return $this->fail(CartLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-06-04 16:51:26 +08:00
|
|
|
|
|
|
|
|
|
}
|