From 2e37a6ac46a79c63d258781fe573ccce03b22a3f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 24 Aug 2024 10:27:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductLogic.php | 36 ++++++++++++++++++- .../logic/store_product/StoreProductLogic.php | 4 ++- .../WarehouseProductLogic.php | 3 +- app/common/logic/PayNotifyLogic.php | 27 +++++++------- 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index 71dd4de28..6de8c8246 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\store_branch_product; use app\admin\logic\store_product\StoreProductLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\logic\BaseLogic; +use app\common\model\store_product\StoreProduct; use think\facade\Db; use Webman\RedisQueue\Redis; @@ -41,7 +42,6 @@ class StoreBranchProductLogic extends BaseLogic } } - /** * @notes 编辑门店商品 * @param array $params @@ -74,6 +74,40 @@ class StoreBranchProductLogic extends BaseLogic return false; } } + /** + * @notes 库存管理 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/07 13:56 + */ + public static function stock(array $params,$type=1): bool + { + Db::startTrans(); + try { + if($type==1){ + StoreBranchProduct::where('id', $params['id'])->inc('stock',$params['nums'])->update(); + $find=StoreProduct::where('id', $params['product_id'])->find(); + if($find){ + $stock=bcadd($find['stock'],$params['nums'],2); + $find->update(['stock'=>$stock,'total_price'=>bcmul($stock,$find['purchase'],2)]); + } + }else{ + StoreBranchProduct::where('id', $params['id'])->dec('stock',$params['nums'])->update(); + $find=StoreProduct::where('id', $params['product_id'])->find(); + if($find){ + $stock=bcsub($find['stock'],$params['nums'],2); + $find->update(['stock'=>$stock,'total_price'=>bcmul($stock,$find['purchase'],2)]); + } + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } /** * @notes 删除门店商品 * @param array $params diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 29a8b1e2c..dcd2fb31d 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -82,7 +82,9 @@ class StoreProductLogic extends BaseLogic if ($params['is_store_all'] == 1) { $store_arr = SystemStore::where('is_show', 1)->column('id'); foreach ($store_arr as $store_id) { - Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]); + if ($store_id != 5) { + Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]); + } } } else { if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index b063802b3..277a10efa 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -2,6 +2,7 @@ namespace app\admin\logic\warehouse_product; +use app\admin\logic\store_branch_product\StoreBranchProductLogic; use app\admin\logic\store_product\StoreProductLogic; use app\common\model\warehouse_product\WarehouseProduct; use app\common\logic\BaseLogic; @@ -56,7 +57,7 @@ class WarehouseProductLogic extends BaseLogic $storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct); } if ($params['nums'] > 0&&$type==1) { - StoreBranchProduct::where('id', $storeBranchProduct['id'])->inc('stock',$params['nums'])->update(); + StoreBranchProductLogic::stock(['id'=>$storeBranchProduct['id'],'product_id'=>$params['product_id'],'nums'=>$params['nums']]); } } else { $after_nums = $storege['nums'] + $params['nums']; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 3b1a47d38..98cec7915 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -572,25 +572,22 @@ class PayNotifyLogic extends BaseLogic */ public static function afterPay($order, $transaction_id = 0) { - $updateData = []; - $updateDataTwo = []; StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]); $arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select(); foreach ($arr as $k => $v) { - $updateData[] = [ - 'store_id' => $v['store_id'], - 'product_id' => $v['product_id'], - 'sales' => ['inc', $v['cart_num']], - 'stock' => ['dec', $v['cart_num']], - ]; - - $updateDataTwo[] = [ - 'id' => $v['product_id'], - 'sales' => ['inc', $v['cart_num']] - ]; + $branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find(); + if($branchProduct){ + $stock=bcsub($branchProduct['stock'],$v['cart_num'],2); + $branchProduct->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2), + 'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]); + } + $storeProduct=StoreProduct::where('id', $v['product_id'])->find(); + if($storeProduct){ + $stock=bcsub($storeProduct['stock'],$v['cart_num'],2); + $storeProduct->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2), + 'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]); + } } - (new StoreBranchProduct())->saveAll($updateData); - (new StoreProduct())->saveAll($updateDataTwo); $financeLogic = new StoreFinanceFlowLogic(); $off_activity = Config::where('name', 'off_activity')->value('value'); $village_uid = 0;