|
|
@@ -54,6 +54,9 @@ class ShopCartLogic extends BaseLogic
|
|
|
}
|
|
|
$model = ShopCart::where(['shop_goods_id'=>$params['shop_goods_id'],'goods_specs_inventory_id'=>$params['goods_specs_inventory_id'],'worker_id'=>$params['worker_id']])->findOrEmpty();
|
|
|
if(!$model->isEmpty()){
|
|
|
+ if($goodSpecInventoryModel->remaining_inventory < $params['number'] + $model->number){
|
|
|
+ throw new \Exception('库存不足');
|
|
|
+ }
|
|
|
$model->number = $model->number + $params['number'];
|
|
|
$model->save();
|
|
|
Db::commit();
|
|
|
@@ -78,6 +81,7 @@ class ShopCartLogic extends BaseLogic
|
|
|
|
|
|
public static function delete($params)
|
|
|
{
|
|
|
+ Db::startTrans();
|
|
|
try{
|
|
|
ShopCart::whereIn('id',$params['ids'])->where('worker_id',$params['worker_id'])->delete();
|
|
|
Db::commit();
|
|
|
@@ -91,6 +95,7 @@ class ShopCartLogic extends BaseLogic
|
|
|
|
|
|
public static function edit($params)
|
|
|
{
|
|
|
+ Db::startTrans();
|
|
|
try{
|
|
|
$cartModel = ShopCart::findOrEmpty($params['id']);
|
|
|
if($cartModel->isEmpty()){
|
|
|
@@ -99,6 +104,13 @@ class ShopCartLogic extends BaseLogic
|
|
|
if($cartModel->worker_id != $params['worker_id']){
|
|
|
throw new \Exception('非法操作');
|
|
|
}
|
|
|
+ $goodSpecInventoryModel = ShopGoodSpecsInventory::findOrEmpty($cartModel->goods_specs_inventory_id);
|
|
|
+ if($goodSpecInventoryModel->isEmpty()){
|
|
|
+ throw new \Exception('规格不存在');
|
|
|
+ }
|
|
|
+ if($params['number'] > $goodSpecInventoryModel->remaining_inventory){
|
|
|
+ throw new \Exception('库存不足');
|
|
|
+ }
|
|
|
$cartModel->number = $params['number'];
|
|
|
$cartModel->save();
|
|
|
Db::commit();
|