购物车逻辑兼容

This commit is contained in:
liu 2024-06-29 15:06:41 +08:00
parent f96538a4b4
commit af4af0d1ed
2 changed files with 26 additions and 9 deletions
app/api
controller/order
logic/order

@ -48,7 +48,11 @@ class CartController extends BaseApiController
return $this->fail('库存数量不足');
}
if ($result) {
$res = CartLogic::edit($params);
if(isset($params['type']) && $params['type'] == 1){
$res = CartLogic::add($params);
}else{
$res = CartLogic::edit($params);
}
} else {
$res = CartLogic::add($params);
}

@ -33,16 +33,29 @@ class CartLogic extends BaseLogic
}
Db::startTrans();
try {
$cart = Cart::create([
//check
$check = Cart::where([
'uid' => $params['uid'],
'type' => $params['type']??'',
'store_id' => $params['store_id'],
'product_id' => $params['product_id'],
'store_id' => $params['store_id']??0,
'staff_id' => $params['staff_id']??0,
'product_attr_unique' => '',
'cart_num' => $params['cart_num'],
'is_new' => $params['is_new']??0,
]);
'is_pay'=>0
])->field('id')->find();
if($check){
Cart::where('id',$check['id'])->inc('cart_num',$params['cart_num'])
->update();
$cart['id'] = $check['id'];
}else{
$cart = Cart::create([
'uid' => $params['uid'],
'type' => $params['type']??'',
'product_id' => $params['product_id'],
'store_id' => $params['store_id']??0,
'staff_id' => $params['staff_id']??0,
'product_attr_unique' => '',
'cart_num' => $params['cart_num'],
'is_new' => $params['is_new']??0,
]);
}
StoreProductLog::create([
'type'=>'cart',
'uid' => $params['uid'],