购物车逻辑兼容

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('库存数量不足'); return $this->fail('库存数量不足');
} }
if ($result) { if ($result) {
$res = CartLogic::edit($params); if(isset($params['type']) && $params['type'] == 1){
$res = CartLogic::add($params);
}else{
$res = CartLogic::edit($params);
}
} else { } else {
$res = CartLogic::add($params); $res = CartLogic::add($params);
} }

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