diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 0655e349d..6ef86a0d9 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -33,32 +33,32 @@ class WarehouseProductLogic extends BaseLogic { // Db::startTrans(); // try { - $data = [ - 'warehouse_id' => $params['warehouse_id'], - 'store_id' => $params['store_id']??0, - 'product_id' => $params['product_id'], - 'financial_pm' => $params['financial_pm'], - 'batch' => 0, - 'nums' => $params['nums'], - 'price' => $params['price'] ?? '', - 'purchase' => $params['purchase'] ?? '', - 'cost' => $params['cost'] ?? '', - 'total_price' => $params['total_price'] ?? '', - 'admin_id' => $params['admin_id'], - 'code' => $params['code'] ?? '', - 'status' => $params['status'] ?? 0, - 'mark' => $params['mark'] ?? '', - ]; - if (isset($params['manufacture']) && $params['manufacture'] != '') { - $data['manufacture'] = strtotime($params['manufacture']); - } - if (isset($params['expiration_date']) && $params['expiration_date'] != '') { - $data['expiration_date'] = strtotime($params['expiration_date']); - } - $res = WarehouseProduct::create($data); - self::enter($res['id'], $params['financial_pm']); - // Db::commit(); - return $res; + $data = [ + 'warehouse_id' => $params['warehouse_id'], + 'store_id' => $params['store_id'] ?? 0, + 'product_id' => $params['product_id'], + 'financial_pm' => $params['financial_pm'], + 'batch' => 0, + 'nums' => $params['nums'], + 'price' => $params['price'] ?? '', + 'purchase' => $params['purchase'] ?? '', + 'cost' => $params['cost'] ?? '', + 'total_price' => $params['total_price'] ?? '', + 'admin_id' => $params['admin_id'], + 'code' => $params['code'] ?? '', + 'status' => $params['status'] ?? 0, + 'mark' => $params['mark'] ?? '', + ]; + if (isset($params['manufacture']) && $params['manufacture'] != '') { + $data['manufacture'] = strtotime($params['manufacture']); + } + if (isset($params['expiration_date']) && $params['expiration_date'] != '') { + $data['expiration_date'] = strtotime($params['expiration_date']); + } + $res = WarehouseProduct::create($data); + self::enter($res['id'], $params['financial_pm']); + // Db::commit(); + return $res; // } catch (\Exception $e) { // Db::rollback(); // Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine()); @@ -119,25 +119,17 @@ class WarehouseProductLogic extends BaseLogic $find = WarehouseProduct::where('id', $id)->find(); $find->status = 1; - $find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm,'store_id'=>$find['store_id']])->count(); + $find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm, 'store_id' => $find['store_id']])->count(); $find->save(); $storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find(); - // if ($financial_pm == 0) { - // StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update(); - // } else { - // StoreProduct::where('id', $find['product_id'])->inc('stock', $find['nums'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]); - // StoreBranchProduct::where('product_id', $find['product_id'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]); - // } if ($storege) { if ($financial_pm == 0) { - $storege->nums = bcsub($storege->nums, $find['nums']); + WarehouseProductStorege::where('id',$storege['id'])->dec('nums', $find['nums'])->update(); } else { - - $storege->nums = bcadd($storege->nums, $find['nums']); + WarehouseProductStorege::where('id',$storege['id'])->inc('nums', $find['nums'])->update(); } - $storege->save(); } else { WarehouseProductStorege::create([ 'warehouse_id' => $find['warehouse_id'], @@ -157,27 +149,26 @@ class WarehouseProductLogic extends BaseLogic */ public static function delete(array $params): bool { - $res=WarehouseProduct::where('id',$params['id'])->find(); - if($res){ + $res = WarehouseProduct::where('id', $params['id'])->find(); + if ($res) { $res->delete(); - if($res['financial_pm']==1){ - WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->dec('nums',$res['nums'])->update(); - }elseif($res['financial_pm']==0){ - $find=SystemStoreStorage::where(['outbound_id'=>$res['id']])->find(); - if($find){ - $stock=StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->value('stock'); - if($stock<$res['nums']){ + if ($res['financial_pm'] == 1) { + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->dec('nums', $res['nums'])->update(); + } elseif ($res['financial_pm'] == 0) { + $find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find(); + if ($find) { + $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock'); + if ($stock < $res['nums']) { self::setError('商品库存不足,无法退回'); return false; } $find->delete(); - StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->dec('stock',$res['nums'])->update(); + StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update(); } - WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->inc('nums',$res['nums'])->update(); + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->inc('nums', $res['nums'])->update(); } - - return true; + return true; } return false; }