Browse Source

mainId补充

shish 4 năm trước cách đây
mục cha
commit
fb2c3794fb

+ 22 - 17
biz-ghs/order/classes/OrderClass.php

@@ -201,10 +201,14 @@ class OrderClass extends BaseClass
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
-
-        $shop->unSendOrder -= 1;
-        $shop->finishOrder += 1;
-        $shop->save();
+        $mainId = $shop->mainId ?? 0;
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
+        $main->unSendOrder -= 1;
+        $main->finishOrder += 1;
+        $main->save();
 
         $kiloFee = $shop->kiloFee ?? 0;
         $miniKilo = $shop->miniKilo ?? 0;
@@ -257,14 +261,14 @@ class OrderClass extends BaseClass
                 $refund = RefundOrderClass::add($refundData, true);
 
                 //余额减少
-                ShopClass::ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice);
+                ShopClass::ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice);
 
                 //总支出增加
-                $currentTotalExpend = bcadd($shop->totalExpend, $refundPrice, 2);
-                $shop->totalExpend = $currentTotalExpend;
-                $totalRefund = bcadd($shop->totalRefund, $refundPrice, 2);
-                $shop->totalRefund = $totalRefund;
-                $shop->save();
+                $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
+                $main->totalExpend = $currentTotalExpend;
+                $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
+                $main->totalRefund = $totalRefund;
+                $main->save();
 
                 //支出流水
                 $thisType = dict::getDict('capitalType', 'ghsBookRefund', 'id');
@@ -279,14 +283,15 @@ class OrderClass extends BaseClass
                     'sjId' => $sjId,
                     'shopId' => $shopId,
                     'event' => $event,
+                    'mainId' => $mainId,
                 ];
                 ShopCapitalClass::addCapital($capitalData);
                 //支出统计
-                StatOutClass::updateOrInsert($shop, $refundPrice);
+                StatOutClass::updateOrInsert($main, $shop, $refundPrice);
 
                 //退款统计
                 $payWay = $order->payWay ?? 0;
-                StatRefundClass::replace($shop, $payWay, $refundPrice);
+                StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
 
                 //供应商预订单退款给客户,客户采购金额减少
                 StatKhCgClass::ghsBookOrderChange(false, $order, $refundPrice);
@@ -298,14 +303,14 @@ class OrderClass extends BaseClass
                 $order->debt = OrderClass::DEBT_YES;
                 $order->save();
 
-                $currentTotalIncome = bcadd($shop->totalIncome, $currentDebt, 2);
-                $shop->totalIncome = $currentTotalIncome;
-                $shop->save();
+                $currentTotalIncome = bcadd($main->totalIncome, $currentDebt, 2);
+                $main->totalIncome = $currentTotalIncome;
+                $main->save();
 
                 $payWay = dict::getDict('payWay', 'debtPay');
 
                 //收入增加
-                StatIncomeClass::updateOrInsert($shop, $currentDebt);
+                StatIncomeClass::updateOrInsert($main, $shop, $currentDebt);
                 //收入流水增加
                 $orderId = $order->id;
                 $capitalType = dict::getDict('capitalType', 'ghsBookOrderGetBack', 'id');
@@ -334,7 +339,7 @@ class OrderClass extends BaseClass
                 //各渠道收入金额统计
                 StatKdClass::replace($shop, $currentDebt, $payWay);
                 //每天销售收入统计
-                StatSaleClass::replace($shop, $currentDebt);
+                StatSaleClass::replace($main, $shop, $currentDebt);
                 //预订单,客户补款给供应商,客户采购金额增加
                 StatKhCgClass::ghsBookOrderChange(true, $order, $currentDebt);
             }

+ 1 - 1
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -282,7 +282,7 @@ class PurchaseOrderClass extends BaseClass
 
             //采购统计
             $cgNum = $order->itemNum ?? 0;
-            StatCgClass::replace($shop, $currentPrice, $cgNum);
+            StatCgClass::replace($main, $shop, $currentPrice, $cgNum);
             //采购按供货商统计
             StatCgGhsClass::ghsReplace($order);
 

+ 27 - 14
biz-ghs/order/classes/StockInOrderClass.php

@@ -10,6 +10,7 @@ use biz\stat\classes\StatStockOutClass;
 use bizGhs\order\models\StockOutOrderItem;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
+use bizGhs\shop\classes\MainClass;
 use bizGhs\stock\classes\StockRecordClass;
 use bizHd\stat\classes\StatIncomeClass;
 use common\components\dict;
@@ -200,11 +201,16 @@ class StockInOrderClass extends BaseClass
             if (empty($shop)) {
                 util::fail('没有找到出库门店');
             }
-            $outCurrentTotalIncome = bcadd($shop->totalIncome, $outTotalCost, 2);
-            $currentTotalStockOut = bcadd($shop->totalStockOut, $outTotalCost, 2);
-            $shop->totalIncome = $outCurrentTotalIncome;
-            $shop->totalStockOut = $currentTotalStockOut;
-            $shop->save();
+            $mainId = $shop->mainId ?? 0;
+            $main = MainClass::getLockById($mainId);
+            if (empty($main)) {
+                util::fail('没有main信息');
+            }
+            $outCurrentTotalIncome = bcadd($main->totalIncome, $outTotalCost, 2);
+            $currentTotalStockOut = bcadd($main->totalStockOut, $outTotalCost, 2);
+            $main->totalIncome = $outCurrentTotalIncome;
+            $main->totalStockOut = $currentTotalStockOut;
+            $main->save();
             $capitalData = [
                 'capitalType' => $outCapitalType,
                 'io' => 1,
@@ -214,13 +220,14 @@ class StockInOrderClass extends BaseClass
                 'sjId' => $outOrderInfo['sjId'] ?? 0,
                 'shopId' => $outShopId,
                 'event' => $outEvent,
+                'mainId' => $mainId,
             ];
             ShopCapitalClass::addCapital($capitalData);
             //每天和每月收入统计,出库也算收入
-            StatIncomeClass::updateOrInsert($shop, $outTotalCost);
+            StatIncomeClass::updateOrInsert($main, $shop, $outTotalCost);
 
             //出库每日和每月统计
-            StatStockOutClass::replace($shop, $outTotalCost);
+            StatStockOutClass::replace($main, $shop, $outTotalCost);
 
             //入库门店
             $inEvent = '入库';
@@ -229,11 +236,16 @@ class StockInOrderClass extends BaseClass
             if (empty($inShop)) {
                 util::fail('没有找到入库门店');
             }
-            $inCurrentTotalExpend = bcadd($inShop->totalExpend, $inTotalCost, 2);
-            $inShop->totalExpend = $inCurrentTotalExpend;
-            $currentTotalStockIn = bcadd($inShop->totalStockIn, $inTotalCost, 2);
-            $inShop->totalStockIn = $currentTotalStockIn;
-            $inShop->save();
+            $inMainId = $inShop->mainId ?? 0;
+            $inMain = MainClass::getLockById($inMainId);
+            if (empty($inMain)) {
+                util::fail('没有main信息');
+            }
+            $inCurrentTotalExpend = bcadd($inMain->totalExpend, $inTotalCost, 2);
+            $inMain->totalExpend = $inCurrentTotalExpend;
+            $currentTotalStockIn = bcadd($inMain->totalStockIn, $inTotalCost, 2);
+            $inMain->totalStockIn = $currentTotalStockIn;
+            $inMain->save();
             $capitalData = [
                 'capitalType' => $inCapitalType,
                 'io' => 0,
@@ -243,12 +255,13 @@ class StockInOrderClass extends BaseClass
                 'sjId' => $orderData['sjId'] ?? 0,
                 'shopId' => $shopId,
                 'event' => $inEvent,
+                'mainId' => $mainId,
             ];
             ShopCapitalClass::addCapital($capitalData);
             //当天和当月支出统计,调拨入库算支出
-            StatOutClass::updateOrInsert($shop, $inTotalCost);
+            StatOutClass::updateOrInsert($main, $shop, $inTotalCost);
             //入库每天和每月统计
-            StatStockInClass::replace($inShop, $inTotalCost);
+            StatStockInClass::replace($inMain, $inShop, $inTotalCost);
 
             $transaction->commit();
 

+ 23 - 17
biz-ghs/order/services/OrderService.php

@@ -16,6 +16,7 @@ use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderExpressClass;
 use bizGhs\order\classes\OrderSendClass;
 use bizGhs\product\classes\ProductClass;
+use bizGhs\shop\classes\MainClass;
 use bizGhs\stat\classes\StatYjClass;
 use bizGhs\ws\services\WsService;
 use bizHd\cg\services\CgRefundService;
@@ -656,28 +657,33 @@ class OrderService extends BaseService
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
-        $shop->unPayOrder -= 1;
+        $mainId = $shop->mainId ?? 0;
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
+        $main->unPayOrder -= 1;
         //预订单的待发货订单增加
         if ($book == 1) {
-            $shop->unSendOrder += 1;
+            $main->unSendOrder += 1;
         } else {
-            $shop->finishOrder += 1;
+            $main->finishOrder += 1;
         }
-        $shop->totalOrderNum += 1;
-        $currentTotalIncome = bcadd($shop->totalIncome, $amount, 2);
-        $shop->totalIncome = $currentTotalIncome;
-        $totalSale = bcadd($shop->totalSale, $amount, 2);
-        $shop->totalSale = $totalSale;
+        $main->totalOrderNum += 1;
+        $currentTotalIncome = bcadd($main->totalIncome, $amount, 2);
+        $main->totalIncome = $currentTotalIncome;
+        $totalSale = bcadd($main->totalSale, $amount, 2);
+        $main->totalSale = $totalSale;
         if ($payWay == dict::getDict('payWay', 'debtPay')) {
             //客户欠款支付会增加【应收客户款】
-            $currentGathering = bcadd($shop->mayGathering, $realPrice, 2);
-            $shop->mayGathering = $currentGathering;
+            $currentGathering = bcadd($main->mayGathering, $realPrice, 2);
+            $main->mayGathering = $currentGathering;
             //客户第一次欠款的增加一个欠款客户
             if ($custom->debtNum == 0) {
-                $shop->mayGatheringNum += 1;
+                $main->mayGatheringNum += 1;
             }
         }
-        $shop->save();
+        $main->save();
 
         $orderId = $order->id;
         $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
@@ -690,7 +696,6 @@ class OrderService extends BaseService
                 $event = $custom->name . '采购';
             }
         }
-        $mainId = $shop->mainId ?? 0;
         $sjId = $order->sjId ?? 0;
         $shopId = $order->shopId ?? 0;
         $capital = [
@@ -706,6 +711,7 @@ class OrderService extends BaseService
             'shopId' => $shopId,
             'shopAdminId' => $shopAdminId,
             'shopAdminName' => $shopAdminName,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capital);
 
@@ -713,7 +719,7 @@ class OrderService extends BaseService
         if ($isPurchase == true) {
             //余额支付和在线支付(微信支付、支付宝支付)会增加余额
             if ($order->onlinePay == dict::getDict('onlinePay', 'yes') || $payWay == dict::getDict('payWay', 'balancePay')) {
-                ShopClass::customKdAddBalance($shop, $realPrice, $order, $capitalType);
+                ShopClass::customKdAddBalance($main, $shop, $realPrice, $order, $capitalType);
             }
         }
 
@@ -754,13 +760,13 @@ class OrderService extends BaseService
         $custom->save();
 
         //收入统计
-        StatIncomeClass::updateOrInsert($shop, $amount);
+        StatIncomeClass::updateOrInsert($main, $shop, $amount);
         //各渠道收入金额统计
         StatKdClass::replace($shop, $amount, $payWay);
         //今日订单+1
-        StatOrderClass::updateOrInsert($shop);
+        StatOrderClass::updateOrInsert($main, $shop);
         //销售统计
-        StatSaleClass::replace($shop, $amount);
+        StatSaleClass::replace($main, $shop, $amount);
         //客户采购统计
         StatKhCgClass::replace($order, $amount);
 

+ 18 - 12
biz-ghs/order/services/RefundOrderService.php

@@ -15,6 +15,7 @@ use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderItemClass;
 use bizGhs\order\classes\RefundOrderClass;
 use bizGhs\order\classes\RefundOrderItemClass;
+use bizGhs\shop\classes\MainClass;
 use bizGhs\stock\classes\StockRecordClass;
 use bizHd\purchase\classes\PurchaseClass;
 use common\components\dict;
@@ -139,12 +140,16 @@ class RefundOrderService extends BaseService
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
         //总支出增加
-        $currentTotalExpend = bcadd($shop->totalExpend, $refundPrice, 2);
-        $shop->totalExpend = $currentTotalExpend;
-        $totalRefund = bcadd($shop->totalRefund, $refundPrice, 2);
-        $shop->totalRefund = $totalRefund;
-        $shop->save();
+        $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
+        $main->totalExpend = $currentTotalExpend;
+        $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
+        $main->totalRefund = $totalRefund;
+        $main->save();
 
         //支出流水
         $thisType = dict::getDict('capitalType', 'saleRefund', 'id');
@@ -159,12 +164,13 @@ class RefundOrderService extends BaseService
             'sjId' => $sjId,
             'shopId' => $shopId,
             'event' => $event,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capitalData);
         //当天和当月支出统计
-        StatOutClass::updateOrInsert($shop, $refundPrice);
+        StatOutClass::updateOrInsert($main, $shop, $refundPrice);
         //退款统计
-        StatRefundClass::replace($shop, $payWay, $refundPrice);
+        StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
         StatKhCgClass::refundReplace($refund);
 
         //记录总的退款金额
@@ -191,7 +197,7 @@ class RefundOrderService extends BaseService
             $order->save();
 
             //门店余额减少
-            ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
+            ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
         } elseif ($payWay == dict::getDict('payWay', 'debtPay')) {
 
             $clearId = $order->clearId;
@@ -200,12 +206,12 @@ class RefundOrderService extends BaseService
             }
 
             //门店应收款减少
-            $currentMayGathering = bcsub($shop->mayGathering, $refundPrice, 2);
+            $currentMayGathering = bcsub($main->mayGathering, $refundPrice, 2);
             if ($currentMayGathering < 0) {
                 util::fail('应付款有问题');
             }
-            $shop->mayGathering = $currentMayGathering;
-            $shop->save();
+            $main->mayGathering = $currentMayGathering;
+            $main->save();
 
             //订单总金额需要减掉退款部分
             $currentRefund = bcadd($order->refundPrice, $refundPrice, 2);
@@ -252,7 +258,7 @@ class RefundOrderService extends BaseService
             $order->save();
 
             //门店余额减少
-            ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
+            ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
         } else {
             util::fail('此支付方式暂不支持线上退款');
         }

+ 14 - 8
biz-hd/cg/services/CgRefundService.php

@@ -14,6 +14,7 @@ use bizHd\cg\classes\CgRefundClass;
 use bizHd\cg\classes\CgRefundItemClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseItemClass;
+use bizHd\shop\classes\MainClass;
 use bizHd\stat\classes\StatIncomeClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
@@ -55,6 +56,10 @@ class CgRefundService extends BaseService
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
 
         $data = [];
         $data['status'] = CgRefundClass::STATUS_COMPLETE;
@@ -129,9 +134,9 @@ class CgRefundService extends BaseService
         }
 
         //门店总收入增加
-        $currentTotalIncome = bcadd($shop->totalIncome, $refundPrice, 2);
-        $shop->totalIncome = $currentTotalIncome;
-        $shop->save();
+        $currentTotalIncome = bcadd($main->totalIncome, $refundPrice, 2);
+        $main->totalIncome = $currentTotalIncome;
+        $main->save();
 
         $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
 
@@ -235,12 +240,12 @@ class CgRefundService extends BaseService
             $cg->save();
 
             //门店应付总款减少
-            $currentMayPay = bcsub($shop->mayPay, $refundPrice, 2);
+            $currentMayPay = bcsub($main->mayPay, $refundPrice, 2);
             if ($currentMayPay < 0) {
                 util::fail('应付款有问题');
             }
-            $shop->mayPay = $currentMayPay;
-            $shop->save();
+            $main->mayPay = $currentMayPay;
+            $main->save();
 
 
             //应付供应商款减少
@@ -265,7 +270,7 @@ class CgRefundService extends BaseService
             $cg->save();
 
             //门店余额增加
-            ShopClass::cgRefundAddBalance($shop, $refundPrice, $cgRefund, $ghs);
+            ShopClass::cgRefundAddBalance($main, $shop, $refundPrice, $cgRefund, $ghs);
 
         } else {
             util::fail('支付方式没有找到哦!');
@@ -283,11 +288,12 @@ class CgRefundService extends BaseService
             'sjId' => $sjId,
             'shopId' => $shopId,
             'event' => $event,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capitalData);
 
         //每天每月收入
-        StatIncomeClass::updateOrInsert($shop, $refundPrice);
+        StatIncomeClass::updateOrInsert($main, $shop, $refundPrice);
 
         //微信付款的不需要通知,微信官方会通知
         if ($payWay != dict::getDict('payWay', 'wxPay')) {

+ 1 - 0
biz-hd/goods/classes/GoodsClass.php

@@ -158,6 +158,7 @@ class GoodsClass extends BaseClass
             'amount' => $orderPrice,
             'mainId' => $mainId,
             'event' => $event,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capitalData);
         //采购总量统计

+ 15 - 8
biz-hd/order/classes/OrderClass.php

@@ -12,6 +12,7 @@ use biz\stat\classes\StatOrderCountClass;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\stat\classes\StatYjClass;
 use bizGhs\ws\services\WsService;
+use bizHd\shop\classes\MainClass;
 use bizHd\stat\classes\StatIncomeClass;
 use bizHd\stat\classes\StatOrderClass;
 use bizHd\user\classes\UserClass;
@@ -214,11 +215,16 @@ class OrderClass extends BaseClass
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
-        $shop->unSendOrder += 1;
-        $shop->unPayOrder -= 1;
-        $currentTotalIncome = bcadd($shop->totalIncome, $realPrice, 2);
-        $shop->totalIncome = $currentTotalIncome;
-        $shop->save();
+        $mainId = $shop->mainId ?? 0;
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
+        $main->unSendOrder += 1;
+        $main->unPayOrder -= 1;
+        $currentTotalIncome = bcadd($main->totalIncome, $realPrice, 2);
+        $main->totalIncome = $currentTotalIncome;
+        $main->save();
 
         $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
         $shopAdminId = $order->shopAdminId ?? 0;
@@ -237,17 +243,18 @@ class OrderClass extends BaseClass
             'shopAdminId' => $shopAdminId,
             'shopAdminName' => $shopAdminName,
             'amount' => $realPrice,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capital);
         //每天和每月收入增加
-        StatIncomeClass::updateOrInsert($shop, $realPrice);
+        StatIncomeClass::updateOrInsert($main, $shop, $realPrice);
         //今日订单+1
-        StatOrderClass::updateOrInsert($shop);
+        StatOrderClass::updateOrInsert($main, $shop);
 
         //客户在线支付下单增加商家可提现余额
         if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
             $amount = $order->actPrice;
-            ShopClass::customKdAddBalance($shop, $amount, $order, $capitalType);
+            ShopClass::customKdAddBalance($main, $shop, $amount, $order, $capitalType);
         }
         if (in_array($order->fromType, [dict::getDict("fromType", "shop"), dict::getDict("fromType", "friend")])) {
             //您有新的收入提醒

+ 27 - 17
biz-hd/purchase/classes/PurchaseClass.php

@@ -144,10 +144,13 @@ class PurchaseClass extends BaseClass
         if (empty($shop)) {
             util::fail('没有找到零售店的门店');
         }
-
-        $shop->cgUnSend -= 1;
-        $shop->cgFinish += 1;
-        $shop->save();
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
+        $main->cgUnSend -= 1;
+        $main->cgFinish += 1;
+        $main->save();
 
         $cgRefund = null;
         $bookPrice = $cg->bookPrice ?? 0;
@@ -177,12 +180,12 @@ class PurchaseClass extends BaseClass
             $cgRefund = CgRefundClass::add($refundData, true);
 
             //门店收入增加
-            $currentTotalIncome = bcadd($shop->totalIncome, $refundPrice, 2);
-            $shop->totalIncome = $currentTotalIncome;
-            $shop->save();
+            $currentTotalIncome = bcadd($main->totalIncome, $refundPrice, 2);
+            $main->totalIncome = $currentTotalIncome;
+            $main->save();
 
             //供应商退款,向供应商采购总金额减少
-            StatCgClass::replace($shop, $refundPrice, 0, false);
+            StatCgClass::replace($main, $shop, $refundPrice, 0, false);
             //供应商退款,按供应商分别采购的金额减少
             StatCgGhsClass::hdCgGhsReplace(false, $cg, $refundPrice, 0);
 
@@ -199,10 +202,11 @@ class PurchaseClass extends BaseClass
                 'sjId' => $sjId,
                 'shopId' => $shopId,
                 'event' => $event,
+                'mainId' => $mainId,
             ];
             ShopCapitalClass::addCapital($capitalData);
             //收入统计
-            StatIncomeClass::updateOrInsert($shop, $refundPrice);
+            StatIncomeClass::updateOrInsert($main, $shop, $refundPrice);
 
             //微信收款的原路退回
             ini_set('date.timezone', 'Asia/Shanghai');
@@ -259,15 +263,15 @@ class PurchaseClass extends BaseClass
             $payWay = dict::getDict('payWay', 'debtPay');
 
             //支出统计
-            StatOutClass::updateOrInsert($shop, $currentDebt);
+            StatOutClass::updateOrInsert($main, $shop, $currentDebt);
             //支出流水
             $capitalType = dict::getDict('capitalType', 'hdBookFinalPay', 'id');
             $sjId = $info->sjId ?? 0;
             $shopId = $info->shopId ?? 0;
 
-            $currentExpend = bcadd($shop->totalExpend, $currentDebt, 2);
-            $shop->totalExpend = $currentExpend;
-            $shop->save();
+            $currentExpend = bcadd($main->totalExpend, $currentDebt, 2);
+            $main->totalExpend = $currentExpend;
+            $main->save();
 
             $event = "预订单{$orderSn}补尾款欠款";
             $capitalData = [
@@ -279,10 +283,11 @@ class PurchaseClass extends BaseClass
                 'sjId' => $sjId,
                 'shopId' => $shopId,
                 'event' => $event,
+                'mainId' => $mainId,
             ];
             ShopCapitalClass::addCapital($capitalData);
             //补款给供应商,采购总金额增加
-            StatCgClass::replace($shop, $currentDebt, 0, true);
+            StatCgClass::replace($main, $shop, $currentDebt, 0, true);
             //补款给供应商,按供货商分别统计采购量增加
             StatCgGhsClass::hdCgGhsReplace(true, $cg, $currentDebt, 0);
 
@@ -837,9 +842,14 @@ class PurchaseClass extends BaseClass
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
-        $shop->cgSending -= 1;
-        $shop->cgFinish += 1;
-        $shop->save();
+        $mainId = $shop->mainId ?? 0;
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
+        $main->cgSending -= 1;
+        $main->cgFinish += 1;
+        $main->save();
 
         /********订单完成后加库存 lqh 2021-05-10*********/
         $orderSn = $purchase->orderSn;

+ 1 - 0
biz-hd/purchase/services/PurchaseService.php

@@ -404,6 +404,7 @@ class PurchaseService extends BaseService
             'sjId' => $sjId,
             'shopId' => $shopId,
             'event' => $event,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capitalData);
 

+ 13 - 7
biz-hd/px/classes/PxApplyClass.php

@@ -4,6 +4,7 @@ namespace bizHd\px\classes;
 
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
+use bizHd\shop\classes\MainClass;
 use bizHd\stat\classes\StatIncomeClass;
 use bizHd\stat\classes\StatStudentClass;
 use common\components\dict;
@@ -78,16 +79,20 @@ class PxApplyClass extends BaseClass
             Yii::info("没有找到门店 PxApplyClass::complete() orderId:{$order->id}");
             util::fail('没有找到门店');
         }
-        $currentTotalIncome = bcadd($shop->totalIncome, $actPrice, 2);
-        $shop->totalIncome = $currentTotalIncome;
-        $shop->studentNum += 1;
-        $shop->save();
+        $mainId = $shop->mainId ?? 0;
+        $main = MainClass::getLockById($mainId);
+        if (empty($main)) {
+            util::fail('没有main信息');
+        }
+        $currentTotalIncome = bcadd($main->totalIncome, $actPrice, 2);
+        $main->totalIncome = $currentTotalIncome;
+        $main->save();
 
         $capitalType = dict::getDict('capitalType', 'pxApply', 'id');
 
         //客户付款报名的,增加门店余额
         if (isset($order->customId) && !empty($order->customId)) {
-            ShopClass::customKdAddBalance($shop, $actPrice, $order, $capitalType);
+            ShopClass::customKdAddBalance($main, $shop, $actPrice, $order, $capitalType);
         }
 
         $sjId = $order->sjId ?? 0;
@@ -102,12 +107,13 @@ class PxApplyClass extends BaseClass
             'sjId' => $sjId,
             'shopId' => $shopId,
             'event' => $event,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capitalData);
         //增加新学员数量
-        StatStudentClass::addStudent($shop);
+        //StatStudentClass::addStudent($shop);
         //每天和每月收入
-        StatIncomeClass::updateOrInsert($shop, $order->actPrice);
+        StatIncomeClass::updateOrInsert($main, $shop, $order->actPrice);
     }
 
 }

+ 1 - 0
biz-hd/refund/services/HdRefundService.php

@@ -218,6 +218,7 @@ class HdRefundService extends BaseService
             'sjId' => $sjId,
             'shopId' => $shopId,
             'event' => $event,
+            'mainId' => $mainId,
         ];
         ShopCapitalClass::addCapital($capitalData);
         //当天和当月支出统计

+ 3 - 3
biz-hd/stat/classes/StatIncomeClass.php

@@ -15,7 +15,7 @@ class StatIncomeClass extends BaseClass
 
     //更新当前商家的数据 lqh 2021.4.15
     // 收入更新,若无则新增
-    public static function updateOrInsert($shop, $amount)
+    public static function updateOrInsert($main, $shop, $amount)
     {
         $time = date('Ymd');
         $mainId = $shop->mainId ?? 0;
@@ -29,10 +29,10 @@ class StatIncomeClass extends BaseClass
         //查id行级锁
         $stat = StatIncomeClass::getLockById($id);
         $stat->amount = bcadd($amount, $stat->amount, 2);
-        $stat->totalAmount = $shop->totalIncome;
+        $stat->totalAmount = $main->totalIncome;
         $stat->save();
         //每月
-        StatIncomeMonthClass::updateOrInsert($shop, $amount);
+        StatIncomeMonthClass::updateOrInsert($main, $shop, $amount);
     }
 
     //查询当天收入金额

+ 3 - 3
biz-hd/stat/classes/StatIncomeMonthClass.php

@@ -11,21 +11,21 @@ class StatIncomeMonthClass extends BaseClass
 
     public static $baseFile = '\bizHd\stat\models\StatIncomeMonth';
 
-    public static function updateOrInsert($shop, $amount)
+    public static function updateOrInsert($main, $shop, $amount)
     {
         $time = date('Ym');
         $mainId = $shop->mainId ?? 0;
         $where = ['mainId' => $mainId, 'time' => $time,];
         $model = self::getByCondition($where, true);
         if (empty($model)) {
-            $data = ['mainId' => $mainId, 'time' => $time, 'amount' => 0, 'totalAmount' => $shop->totalIncome, 'createTime' => date('Y-m-d H:i:s')];
+            $data = ['mainId' => $mainId, 'time' => $time, 'amount' => 0, 'totalAmount' => $main->totalIncome, 'createTime' => date('Y-m-d H:i:s')];
             $model = self::add($data, true);
         }
         $id = $model->id;
         //查id行级锁
         $stat = StatIncomeMonthClass::getLockById($id);
         $stat->amount = bcadd($amount, $stat->amount, 2);
-        $stat->totalAmount = $shop->totalIncome;
+        $stat->totalAmount = $main->totalIncome;
         $stat->save();
     }
 

+ 3 - 3
biz-hd/stat/classes/StatOrderClass.php

@@ -11,14 +11,14 @@ class StatOrderClass extends BaseClass
     public static $baseFile = '\bizHd\stat\models\StatOrder';
 
     //今日订单+1
-    public static function updateOrInsert($shop)
+    public static function updateOrInsert($main, $shop)
     {
         $time = date('Ymd');
         $mainId = $shop->mainId ?? 0;
         $where = ['mainId' => $mainId, 'time' => $time];
         $model = self::getByCondition($where, true);
         if (empty($model)) {
-            $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $shop->totalOrderNum], true);
+            $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrderNum], true);
         }
         $id = $model->id;
         //查id行级锁
@@ -28,7 +28,7 @@ class StatOrderClass extends BaseClass
         $stat->save();
 
         //本月订单+1
-        StatOrderMonthClass::updateOrInsert($shop);
+        StatOrderMonthClass::updateOrInsert($main, $shop);
     }
 
     public static function getRiseNumToday($shopId)

+ 2 - 2
biz-hd/stat/classes/StatOrderMonthClass.php

@@ -24,14 +24,14 @@ class StatOrderMonthClass extends BaseClass
     }
 
     //月订单+1
-    public static function updateOrInsert($shop)
+    public static function updateOrInsert($main, $shop)
     {
         $time = date('Ym');
         $mainId = $shop->mainId ?? 0;
         $where = ['mainId' => $mainId, 'time' => $time];
         $model = self::getByCondition($where, true);
         if (empty($model)) {
-            $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $shop->totalOrderNum], true);
+            $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrderNum], true);
         }
         $id = $model->id;
         //查id行级锁

+ 1 - 1
biz/pt/classes/PtAssetClass.php

@@ -109,7 +109,7 @@ class PtAssetClass extends BaseClass
             'event' => $event,
             'sjId' => $order->sjId,
             'shopId' => $order->shopId,
-            'mainId'=>$order->mainId ?? 0,
+            'mainId' => $order->mainId ?? 0,
             'tx' => $tx,
             'ptStyle' => $ptStyle,
             'shopName' => $shop->shopName,

+ 18 - 23
biz/shop/classes/ShopClass.php

@@ -244,13 +244,8 @@ class ShopClass extends BaseClass
     }
 
     //客户下单引起的余额增加 ssh 20210520
-    public static function customKdAddBalance($shop, $amount, $order, $capitalType)
+    public static function customKdAddBalance($main, $shop, $amount, $order, $capitalType)
     {
-        $mainId = $shop->mainId ?? 0;
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有找到资产信息');
-        }
         //门店余额增加
         $currentBalance = bcadd($main->balance, $amount, 2);
         $main->balance = $currentBalance;
@@ -400,13 +395,13 @@ class ShopClass extends BaseClass
     }
 
     //零售采购退款
-    public static function cgRefundAddBalance($shop, $refundPrice, $cgRefund, $ghs)
+    public static function cgRefundAddBalance($main, $shop, $refundPrice, $cgRefund, $ghs)
     {
         //客户余额增加
-        $currentBalance = bcadd($shop->balance, $refundPrice, 2);
-        $shop->balance = $currentBalance;
-        $shop->save();
-        $currentTxBalance = $shop->txBalance;
+        $currentBalance = bcadd($main->balance, $refundPrice, 2);
+        $main->balance = $currentBalance;
+        $main->save();
+        $currentTxBalance = $main->txBalance;
         $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
         $id = $cgRefund->id;
         $ptStyle = $shop->ptStyle;
@@ -436,14 +431,14 @@ class ShopClass extends BaseClass
     }
 
     //供应商预订被多付了退款减少余额 ssh 20220324
-    public static function ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice)
+    public static function ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice)
     {
-        $currentBalance = bcsub($shop->balance, $refundPrice, 2);
+        $currentBalance = bcsub($main->balance, $refundPrice, 2);
         if ($currentBalance < 0) {
             util::fail('余额不足,请先充值');
         }
-        $shop->balance = $currentBalance;
-        $currentTx = $shop->txBalance;
+        $main->balance = $currentBalance;
+        $currentTx = $main->txBalance;
         if ($currentTx > 0) {
             if ($refundPrice > $currentTx) {
                 $currentTx = 0;
@@ -451,8 +446,8 @@ class ShopClass extends BaseClass
                 $currentTx = bcsub($currentTx, $refundPrice, 2);
             }
         }
-        $shop->txBalance = $currentTx;
-        $shop->save();
+        $main->txBalance = $currentTx;
+        $main->save();
 
         $currentType = dict::getDict('capitalType', 'ghsBookRefund');
         $id = $refund->id;
@@ -545,15 +540,15 @@ class ShopClass extends BaseClass
     }
 
     //销售单退款减少余额 ssh 2021.2.21
-    public static function saleRefundReduceBalance($shop, $refund, $refundPrice)
+    public static function saleRefundReduceBalance($main, $shop, $refund, $refundPrice)
     {
         //门店余额减少
-        $currentBalance = bcsub($shop->balance, $refundPrice, 2);
+        $currentBalance = bcsub($main->balance, $refundPrice, 2);
         if ($currentBalance < 0) {
             util::fail('余额不足,请先充值');
         }
-        $shop->balance = $currentBalance;
-        $currentTx = $shop->txBalance;
+        $main->balance = $currentBalance;
+        $currentTx = $main->txBalance;
         if ($currentTx > 0) {
             if ($refundPrice > $currentTx) {
                 $currentTx = 0;
@@ -561,8 +556,8 @@ class ShopClass extends BaseClass
                 $currentTx = bcsub($currentTx, $refundPrice, 2);
             }
         }
-        $shop->txBalance = $currentTx;
-        $shop->save();
+        $main->txBalance = $currentTx;
+        $main->save();
 
         $currentType = dict::getDict('capitalType', 'saleRefund');
         $id = $refund->id;

+ 3 - 3
biz/stat/classes/StatRefundClass.php

@@ -19,7 +19,7 @@ class StatRefundClass extends BaseClass
     }
 
     //退款统计 ssh 20210827
-    public static function replace($shop, $payWay, $amount, $date = null)
+    public static function replace($main, $shop, $payWay, $amount, $date = null)
     {
         $sjId = $shop->sjId ?? 0;
         $shopId = $shop->id ?? 0;
@@ -32,7 +32,7 @@ class StatRefundClass extends BaseClass
         $unique = self::getLockById($id);
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalRefund;
+        $unique->totalAmount = $main->totalRefund;
         $unique->num += 1;
 
         $map = dict::getDict('payWay');
@@ -65,7 +65,7 @@ class StatRefundClass extends BaseClass
         }
 
         $unique->save();
-        StatRefundMonthClass::replace($shop, $payWay, $amount, $time);
+        StatRefundMonthClass::replace($main, $shop, $payWay, $amount, $time);
     }
 
 }

+ 2 - 2
biz/stat/classes/StatRefundMonthClass.php

@@ -12,7 +12,7 @@ class StatRefundMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatRefundMonth';
 
     //退款统计 ssh 20210827
-    public static function replace($shop, $payWay, $amount, $date = null)
+    public static function replace($main, $shop, $payWay, $amount, $date = null)
     {
         if ($date == null) {
             $time = date('Ym');
@@ -34,7 +34,7 @@ class StatRefundMonthClass extends BaseClass
         $unique = self::getLockById($id);
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalRefund;
+        $unique->totalAmount = $main->totalRefund;
         $unique->num += 1;
 
         $map = dict::getDict('payWay');

+ 3 - 3
biz/stat/classes/StatSaleClass.php

@@ -23,7 +23,7 @@ class StatSaleClass extends BaseClass
     }
 
     //销售统计 ssh 20210827
-    public static function replace($shop, $amount, $date = null)
+    public static function replace($main, $shop, $amount, $date = null)
     {
         $mainId = $shop->mainId ?? 0;
         $time = $date == null ? date('Ymd') : $date;
@@ -35,10 +35,10 @@ class StatSaleClass extends BaseClass
         $unique = self::getLockById($id);
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalSale;
+        $unique->totalAmount = $main->totalSale;
         $unique->num += 1;
         $unique->save();
-        StatSaleMonthClass::replace($shop, $amount, $time);
+        StatSaleMonthClass::replace($main, $shop, $amount, $time);
     }
 
 }

+ 2 - 2
biz/stat/classes/StatSaleMonthClass.php

@@ -11,7 +11,7 @@ class StatSaleMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatSaleMonth';
 
     //销售统计 ssh 20210827
-    public static function replace($shop, $amount, $date = null)
+    public static function replace($main, $shop, $amount, $date = null)
     {
         if ($date == null) {
             $time = date('Ym');
@@ -32,7 +32,7 @@ class StatSaleMonthClass extends BaseClass
         $unique = self::getLockById($id);
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalSale;
+        $unique->totalAmount = $main->totalSale;
         $unique->num += 1;
         $unique->save();
     }

+ 4 - 4
biz/stat/classes/StatStockInClass.php

@@ -13,12 +13,12 @@ class StatStockInClass extends BaseClass
     //获取总和 ssh 20210829
     public static function getSum($where)
     {
-        $amount = self::sum($where,'amount');
+        $amount = self::sum($where, 'amount');
         return empty($amount) ? 0 : $amount;
     }
 
     //入库添加或更新 ssh 20210526
-    public static function replace($shop, $amount)
+    public static function replace($main, $shop, $amount)
     {
         $sjId = $shop->sjId;
         $shopId = $shop->id;
@@ -34,10 +34,10 @@ class StatStockInClass extends BaseClass
         }
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalStockIn;
+        $unique->totalAmount = $main->totalStockIn;
         $unique->save();
         //当月
-        StatStockInMonthClass::replace($shop, $amount);
+        StatStockInMonthClass::replace($main, $shop, $amount);
     }
 
 }

+ 2 - 2
biz/stat/classes/StatStockInMonthClass.php

@@ -11,7 +11,7 @@ class StatStockInMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatStockInMonth';
 
     //入库添加或更新 ssh 20210526
-    public static function replace($shop, $amount)
+    public static function replace($main, $shop, $amount)
     {
         $time = date('Ym');
         $year = date('Y');
@@ -29,7 +29,7 @@ class StatStockInMonthClass extends BaseClass
         }
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalStockIn;
+        $unique->totalAmount = $main->totalStockIn;
         $unique->save();
     }
 

+ 3 - 3
biz/stat/classes/StatStockOutClass.php

@@ -18,7 +18,7 @@ class StatStockOutClass extends BaseClass
     }
 
     //出库添加或更新 ssh 20210526
-    public static function replace($shop, $amount)
+    public static function replace($main, $shop, $amount)
     {
         $sjId = $shop->sjId;
         $shopId = $shop->id;
@@ -34,10 +34,10 @@ class StatStockOutClass extends BaseClass
         }
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalStockOut;
+        $unique->totalAmount = $main->totalStockOut;
         $unique->save();
         //当月
-        StatStockOutMonthClass::replace($shop, $amount);
+        StatStockOutMonthClass::replace($main, $shop, $amount);
     }
 
     //今天出库金额 ssh 20210526

+ 2 - 2
biz/stat/classes/StatStockOutMonthClass.php

@@ -10,7 +10,7 @@ class StatStockOutMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatStockOutMonth';
 
     //出库添加或更新 ssh 20210526
-    public static function replace($shop, $amount)
+    public static function replace($main, $shop, $amount)
     {
         $time = date('Ym');
         $year = date('Y');
@@ -28,7 +28,7 @@ class StatStockOutMonthClass extends BaseClass
         }
         $currentAmount = bcadd($unique->amount, $amount, 2);
         $unique->amount = $currentAmount;
-        $unique->totalAmount = $shop->totalStockOut;
+        $unique->totalAmount = $main->totalStockOut;
         $unique->save();
     }