From b31a2fff151e440a64f260164c5c8639a03d4206 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 20 Aug 2024 20:27:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(CapitalFlowLogic):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=E8=B5=84=E9=87=91=E6=B5=81=E6=B0=B4=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E4=BA=86=E4=BB=A3=E7=A0=81=E7=9A=84=E5=8F=AF=E8=AF=BB=E6=80=A7?= =?UTF-8?q?=E5=92=8C=E7=A8=B3=E5=AE=9A=E6=80=A7=EF=BC=8C=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86=E7=9B=B8=E5=85=B3API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CapitalFlowLogic.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index 35247600a..221d2e9ea 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -116,7 +116,7 @@ class CapitalFlowLogic extends BaseLogic $model->mark = empty($mark) ? $model->title : $mark; $model->save(); //这里有bug 要修改 - $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]); + // $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]); return $model->id; } @@ -146,7 +146,7 @@ class CapitalFlowLogic extends BaseLogic $model->mark = empty($mark) ? $model->title : $mark; $model->save(); //这里有bug 要修改 - $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]); + // $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]); return $model->id; } From bc2ed0635a25e2c80d8a50d3cd4df6a17de2a394 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 20 Aug 2024 21:09:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(StoreFinanceFlowLogic):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E8=B4=A2=E5=8A=A1=E6=B5=81=E6=B0=B4=E9=80=80?= =?UTF-8?q?=E8=BF=98=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=95=86=E6=88=B7ID=E5=8F=82=E6=95=B0=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BA=86=E9=80=80=E6=AC=BE=E6=B5=81=E7=A8=8B=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E4=BA=86=E8=B5=84=E9=87=91=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=9A=84=E5=87=86=E7=A1=AE=E6=80=A7=EF=BC=8C=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86=E7=9B=B8=E5=85=B3API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/DemoPayNotifyLogic.php | 2 +- app/common/logic/PayNotifyLogic.php | 3 ++- app/common/logic/StoreFinanceFlowLogic.php | 21 +++++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/common/logic/DemoPayNotifyLogic.php b/app/common/logic/DemoPayNotifyLogic.php index 3576484c4..6f0e903bd 100644 --- a/app/common/logic/DemoPayNotifyLogic.php +++ b/app/common/logic/DemoPayNotifyLogic.php @@ -357,7 +357,7 @@ class DemoPayNotifyLogic extends BaseLogic //微信日志 user_order_refund $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1); //处理财务流水退还 - (new StoreFinanceFlowLogic())->store_finance_back($orderSn); + (new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']); self::addStock($order['id']); //微信 return true; // self::afterPay($order,$extra['transaction_id']); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 2c525a636..681993271 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -324,7 +324,7 @@ class PayNotifyLogic extends BaseLogic StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); //处理财务流水退还 - (new StoreFinanceFlowLogic())->store_finance_back($orderSn); + (new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 $user = User::where('id', $order['uid'])->findOrEmpty(); @@ -393,6 +393,7 @@ class PayNotifyLogic extends BaseLogic //增加数量 self::addStock($order['id']); StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); + (new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']); return true; } diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 9320689ae..7fd7b23da 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -176,39 +176,44 @@ class StoreFinanceFlowLogic extends BaseLogic * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function store_finance_back($orderSn) + public function store_finance_back($orderSn, $store_id) { - $list=StoreFinanceFlow::where('order_sn', $orderSn) + $list = StoreFinanceFlow::where('order_sn', $orderSn) ->where(['financial_pm' => 1, 'status' => 1]) ->select(); foreach ($list as $k => $value) { //用户 switch ($value['type']) { case 0: - if ($value['financial_type'] == 12&& $value['other_uid']>0) { + if ($value['financial_type'] == 12 && $value['other_uid'] > 0) { $user = User::where('id', $value['other_uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); - $user->now_money = bcsub($user['now_money'],$value['number'], 2); + $user->now_money = bcsub($user['now_money'], $value['number'], 2); $user->save(); // Log::error('aa'.$a); // Log::error('aa'.$user['now_money']); // Log::error('aa'.$value['number']); - $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'],'',$value['pay_type']); + $capitalFlowDao->userExpense('user_order_promotion_refund', 'system_back', $value['order_id'], $value['number'], '', $value['pay_type']); } break; //商户 case 1: + $store = SystemStore::where('id', $store_id)->find(); + $capitalFlowDao = new CapitalFlowLogic($store, 'store'); if ($value['number'] > 0 && $value['financial_type'] == 2) { SystemStore::where('id', $value['store_id'])->dec('store_money', $value['number'])->update(); + $capitalFlowDao->storeExpense('store_paid_deposit_dec', 'order', $value['order_id'],$value['number']); + } if ($value['number'] > 0 && $value['financial_type'] == 16) { SystemStore::where('id', $value['store_id'])->dec('attrition', $value['number'])->update(); + $capitalFlowDao->storeExpense('store_attrition_dec', 'order', $value['order_id'], $value['number']); + } break; } - } - $find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status',1)->find(); + $find = StoreFinanceFlow::where('order_sn', $orderSn)->where('financial_type', 11)->where('status', 1)->find(); if ($find && $find['number'] > 0) { SystemStore::where('id', $find['store_id'])->dec('paid_deposit', $find['number'])->update(); } @@ -220,7 +225,7 @@ class StoreFinanceFlowLogic extends BaseLogic // $value['financial_type'] = OrderEnum::PAY_BACK; // $value['create_time'] = time(); // } - StoreFinanceFlow::where('order_sn', $orderSn)->update(['status'=>-1]); + StoreFinanceFlow::where('order_sn', $orderSn)->update(['status' => -1]); // (new StoreFinanceFlow)->saveAll($data); } } From 22ed5fefddb005e401aa759a7fa5cefb83a91639 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 21 Aug 2024 10:03:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=8D=95=E9=97=A8=E5=BA=97=E5=92=8C=E5=A4=9A=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98=E7=9A=84=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BA=86=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_product/StoreProductController.php | 78 +++++++++++++++++++ .../WarehouseOrderController.php | 45 +++-------- .../WarehouseProductLists.php | 2 +- .../logic/store_product/StoreProductLogic.php | 22 +----- 4 files changed, 91 insertions(+), 56 deletions(-) diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 4f539d8d6..99970956e 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -101,5 +101,83 @@ class StoreProductController extends BaseAdminController public function import() { return $this->fail('接口已关闭'); + $product_arr = $this->request->post('product_arr'); + $store_arr = $this->request->post('store_arr'); + $stock_type = $this->request->post('stock_type', 1); + $warehouse_id = $this->request->post('warehouse_id'); + $count = count($store_arr); + foreach ($product_arr as $key => $arr) { + $stock = bcmul($arr['stock'], $count); + $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums'); + if ($nums < $stock) { + return $this->fail('商品库存不足'); + } + } + if ($count == 1) { + $store_id = $store_arr[0]; + foreach ($product_arr as $key => $arr) { + $data = [ + 'warehouse_id' => $warehouse_id, + 'product_id' => $arr['id'], + 'store_id' => $store_id, + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $arr['stock'], + 'status' => 1, + 'admin_id' => $this->adminId, + ]; + if ($arr['stock'] == 0) { + $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + } else { + WarehouseProductLogic::add($data); + $find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find(); + if ($find) { + StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update(); + } else { + $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update(); + } + } + // StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + + // Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]); + } + } else { + foreach ($product_arr as $key => $arr) { + foreach ($store_arr as $k => $store_id) { + $data = [ + 'warehouse_id' => $warehouse_id, + 'product_id' => $arr['id'], + 'store_id' => $store_id, + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $arr['stock'], + 'status' => 1, + 'admin_id' => $this->adminId, + ]; + if ($arr['stock'] == 0) { + $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + } else { + WarehouseProductLogic::add($data); + $find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find(); + if ($find) { + StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update(); + } else { + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update(); + } + } + + // $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + // StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + // Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]); + } + } + } + return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); + } } diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 11c06ab17..8095e168c 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -19,6 +19,7 @@ use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\common\service\xlsx\OrderDetail; use app\common\service\xlsx\WarehouseOrdeRentry; use support\exception\BusinessException; +use support\Log; use think\facade\Db; /** @@ -108,54 +109,28 @@ class WarehouseOrderController extends BaseAdminController 'status' => 1, 'admin_id' => $this->adminId, ]; - $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); + $storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); if ($arr['stock'] == 0) { - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); + StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct); } else { - $data['total_price'] = bcmul($arr['stock'], $find['purchase'], 2); - $data['purchase'] = $find['purchase']; + $data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2); + $data['purchase'] = $storeProduct['purchase']; $data['oid'] = $res['id']; WarehouseProductLogic::add($data); $find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find(); if ($find) { StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update(); } else { - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update(); + $ordinary=StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct); + if(empty($ordinary)){ + throw new BusinessException('商品不存在'); + } + StoreBranchProduct::where('id', $ordinary['id'])->inc('stock', $arr['stock'])->update(); } $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']]); } } - } else { - return $this->fail('暂不支持多门店入库'); - foreach ($product_arr as $key => $arr) { - foreach ($store_arr as $k => $store_id) { - $data = [ - 'warehouse_id' => $warehouse_id, - 'product_id' => $arr['id'], - 'store_id' => $store_id, - 'financial_pm' => 0, - 'batch' => 1, - 'nums' => $arr['stock'], - 'status' => 1, - 'admin_id' => $this->adminId, - ]; - if ($arr['stock'] == 0) { - $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - } else { - WarehouseProductLogic::add($data); - $find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find(); - if ($find) { - StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update(); - } else { - StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id); - StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update(); - } - } - } - } } Db::commit(); } catch (\Throwable $e) { diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index 7a5079ba4..bd04f5ae7 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -33,7 +33,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt public function setSearch(): array { return [ - '=' => ['warehouse_id', 'financial_pm', 'store_id','oid'], + '=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id'], 'between_time' => 'create_time' ]; } diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 7c54be70b..cb192b491 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -395,7 +395,7 @@ class StoreProductLogic extends BaseLogic /**普通 */ - public static function ordinary($product_arr, $store_id, $admin_id, $find, $warehouse_id) + public static function ordinary($product_arr, $store_id, $admin_id, $find) { $store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); if ($find && !$store_find) { @@ -439,32 +439,14 @@ class StoreProductLogic extends BaseLogic 'bar_code' => $attr_value['bar_code'] ]; StoreBranchProductAttrValue::create($arr); - // if ($product_arr['stock'] > 0) { - // self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id); - // } Db::commit(); - return true; + return $branch; } catch (\Throwable $e) { Db::rollback(); Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); return false; } } - // else { - // //更新门店库存 - // Db::startTrans(); - // try { - // // if ($product_arr['stock'] > 0) { - // // self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id); - // // } - // Db::commit(); - // return true; - // } catch (\Exception $e) { - // Db::rollback(); - // Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - // return false; - // } - // } } /**兑换 */ From 219c372ca84029e5dc059811fe2fc38d56e971b5 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 21 Aug 2024 10:04:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix(WarehouseOrderController):=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4debug=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E4=B8=9A=E5=8A=A1=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/warehouse_order/WarehouseOrderController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 8095e168c..0b6a4d0f9 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -135,7 +135,6 @@ class WarehouseOrderController extends BaseAdminController Db::commit(); } catch (\Throwable $e) { Db::rollback(); - d($e); throw new BusinessException($e->getMessage()); } return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);