diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php index 51b8ccabd..25cdf8eca 100644 --- a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -176,4 +176,11 @@ class BeforehandOrderCartInfoController extends BaseAdminController return $this->success('操作成功', [], 1, 1); } + public function setStoreSale() + { + $params = $this->request->post(); + BeforehandOrderCartInfoLogic::setStoreSale($params); + return $this->success('操作成功', [], 1, 1); + } + } \ No newline at end of file diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php index 59e00eb82..1667ce5ee 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -77,7 +77,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe } } $list = BeforehandOrderCartInfo::where($this->searchWhere) - ->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id']) + ->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id', 'store_sale']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) use ($system_store, $order_mark) { diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 056c2af68..63699f9a3 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -2,6 +2,7 @@ namespace app\admin\logic\beforehand_order; +use app\admin\logic\store_branch_product\StoreBranchProductLogic; use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\api\logic\order\CartLogic; @@ -397,6 +398,7 @@ class BeforehandOrderLogic extends BaseLogic ]; $arr['delivery_time'] = strtotime($delivery_time); $res = WarehouseOrder::create($arr); + $totalPrice = '0.00'; foreach ($info as $key => $arr) { if ($user_ship == 0) { $price = 0; @@ -421,11 +423,16 @@ class BeforehandOrderLogic extends BaseLogic 'code' => $res['code'], 'unit' => $arr['unit'] ?? 0, ]; - WarehouseProductLogic::setOutbound($data, 1, $admin_id); + $totalPrice = bcadd($totalPrice, $arr['total_price'], 2); + if ($arr['store_sale'] == 1) { + StoreBranchProductLogic::decStock($store_id, $arr['product_id'], $arr['cart_num']); + } else { + WarehouseProductLogic::setOutbound($data, 1, $admin_id); + } } $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); - WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); - $order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $finds['total_price']]); + WarehouseOrder::where('id', $res['id'])->update(['total_price' => $totalPrice, 'nums' => $finds['nums']]); + $order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $totalPrice]); BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]); Db::commit(); return true; diff --git a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php index 22b456f3b..05302dad7 100644 --- a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -339,4 +339,15 @@ class BeforehandOrderCartInfoLogic extends BaseLogic (new BeforehandOrderCartInfo())->saveAll($update); } + public static function setStoreSale($params) + { + $cartInfo = BeforehandOrderCartInfo::where('id', $params['id'])->find(); + if ($cartInfo['store_sale'] == 1) { + $update = ['store_sale' => 0]; + } else { + $update = ['store_sale' => 1]; + } + BeforehandOrderCartInfo::where('id', $params['id'])->update($update); + } + } diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index b66cf1c2c..4d2ea5a4a 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -120,4 +120,27 @@ class StoreBranchProductLogic extends BaseLogic { return StoreBranchProduct::findOrEmpty($params['id'])->toArray(); } + + public static function decStock($storeId, $productId, $num) + { + $branchProduct = StoreBranchProduct::where('store_id', $storeId)->where('product_id', $productId)->find(); + if ($branchProduct) { + $stock = bcsub($branchProduct['stock'], $num, 2); + StoreBranchProduct::update([ + 'stock' => $stock, + 'total_price' => bcmul($stock, $branchProduct['purchase'], 2), + 'sales' => bcadd($branchProduct['sales'], $num, 2) + ], ['id' => $branchProduct['id']]); + SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url()); + } else { + $storeProduct = StoreProduct::where('id', $productId)->find(); + $branchProduct = StoreProductLogic::ordinary(['id' => $productId], $storeId, 0, $storeProduct); + StoreBranchProduct::update([ + 'stock' => -$num, + 'sales' => $num + ], ['product_id' => $productId,'store_id'=>$storeId]); + SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url()); + } + } + }