Переглянути джерело

Merge branch 'debt' into dev

shish 1 рік тому
батько
коміт
7feafcc3c3

+ 1 - 8
app-ghs/controllers/ConsoleController.php

@@ -22,13 +22,6 @@ class ConsoleController extends BaseController
     //总览
     public function actionStat()
     {
-        $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
-        $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
-        $pfDebt = $pfDebt === null ? 0 : $pfDebt;
-        $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
-        $lsDebt = $lsDebt === null ? 0 : $lsDebt;
-        $totalDebt = bcadd($pfDebt, $lsDebt, 2);
-
         $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost,virtualStock,delStatus', null, true);
         $totalItemNum = 0;
         $totalCost = 0;
@@ -52,7 +45,7 @@ class ConsoleController extends BaseController
         $overview = [
             ['name' => "库存数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
             ['name' => "库存值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
-            ['name' => "总赊账", "url" => '/admin/shop/debtChange', 'value' => $totalDebt, 'type' => 1],
+            ['name' => "总赊账", "url" => '/admin/custom/showTotalBalance', 'value' => 0, 'type' => 1],
             ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
             ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
             ['name' => "总订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],

+ 17 - 0
app-ghs/controllers/CustomController.php

@@ -1043,4 +1043,21 @@ class CustomController extends BaseController
         util::success($info);
     }
 
+    //总赊账和总余额汇总 ssh 20250620
+    public function actionShowTotalBalance()
+    {
+        $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
+        if($lookMoney == 0){
+            util::fail('无法查看哦');
+        }
+
+        $pfShop = $this->shop;
+        $lsShopId = $pfShop->lsShopId;
+        $pfShopId = $this->shopId;
+        $respond = CustomClass::showTotalBalance($pfShopId, $lsShopId);
+        $respond['pfShopId'] = $pfShopId;
+        $respond['lsShopId'] = $lsShopId;
+        util::success($respond);
+    }
+
 }

+ 2 - 1
app-hd/controllers/BaseController.php

@@ -17,7 +17,7 @@ class BaseController extends PublicController
 {
 
     public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
-    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdmin;
+    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdminName, $shopAdmin;
     public $appId;
     public $isWx = false;
     public $isLogin = false;
@@ -77,6 +77,7 @@ class BaseController extends PublicController
             }
             $this->shopAdmin = $shopAdmin;
             $this->shopAdminId = $shopAdmin->id ?? 0;
+            $this->shopAdminName = $shopAdmin->name ?? '';
             $sjId = $shop->sjId;
             $this->sjId = $sjId;
             $sj = SjClass::getById($sjId, true);

+ 3 - 10
app-hd/controllers/ConsoleController.php

@@ -19,13 +19,6 @@ class ConsoleController extends BaseController
     //总览
     public function actionStat()
     {
-        $where = ['mainId' => $this->mainId, 'debt' => 1]; // 重新赋值
-        $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
-        $pfDebt = $pfDebt === null ? 0 : $pfDebt;
-        $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
-        $lsDebt = $lsDebt === null ? 0 : $lsDebt;
-        $totalDebt = bcadd($pfDebt, $lsDebt, 2);
-
         $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
         $totalItemNum = 0;
         $totalCost = 0;
@@ -45,10 +38,10 @@ class ConsoleController extends BaseController
         $totalVisit = $main->totalVisit ?? 0;
         $totalOrder = $main->finishOrder ?? 0;
         $overview = [
+            ['name' => "花材数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
+            ['name' => "花材值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
+            ['name' => "总赊账", "url" => '/admin/custom/showTotalBalance', 'value' => 0, 'type' => 1],
             ['name' => "花束", "url" => '/admin/stat/stock', 'value' => 10, 'type' => 1],
-            ['name' => "花材", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
-            ['name' => "库存值", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
-            ['name' => "总欠款", "url" => '/admin/home/member', 'value' => $totalDebt, 'type' => 4],
             ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
             ['name' => "订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],
         ];

+ 17 - 0
app-hd/controllers/CustomController.php

@@ -560,4 +560,21 @@ class CustomController extends BaseController
         util::success($user);
     }
 
+    //总赊账和总余额汇总 ssh 20250620
+    public function actionShowTotalBalance()
+    {
+        $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
+        if($lookMoney == 0){
+            util::fail('无法查看哦');
+        }
+
+        $lsShop = $this->shop;
+        $pfShopId = $lsShop->pfShopId;
+        $lsShopId = $this->shopId;
+        $respond = \bizGhs\custom\classes\CustomClass::showTotalBalance($pfShopId, $lsShopId);
+        $respond['pfShopId'] = $pfShopId;
+        $respond['lsShopId'] = $lsShopId;
+        util::success($respond);
+    }
+
 }

+ 0 - 25
app-hd/controllers/CustomDebtController.php

@@ -1,25 +0,0 @@
-<?php
-
-namespace hd\controllers;
-
-use common\components\dict;
-use common\components\util;
-use Yii;
-
-class CustomDebtController extends BaseController
-{
-
-    public $guestAccess = [];
-
-    public function actionList()
-    {
-        $get = Yii::$app->request->get();
-        $ptStyle = dict::getDict('ptStyle', 'hd');
-        $where = [];
-        $where['shopId'] = $this->shopId;
-        $where['ptStyle'] = $ptStyle;
-        $list = CustomDebtChangeClass::getChangeList($where);
-        util::success($list);
-    }
-
-}

+ 34 - 0
app-hd/controllers/CustomDebtRecordController.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace hd\controllers;
+
+use bizHd\custom\classes\CustomClass;
+use bizHd\custom\classes\CustomDebtRecordClass;
+use common\components\dict;
+use common\components\util;
+use Yii;
+
+class CustomDebtRecordController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $ptStyle = dict::getDict('ptStyle', 'hd');
+        $customId = $get['customId'] ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        if ($custom->shopId != $this->shopId) {
+            util::fail('不是你的客户');
+        }
+        $where = [];
+        $where['customId'] = $customId;
+        $list = CustomDebtRecordClass::getChangeList($where);
+        util::success($list);
+    }
+
+}

+ 12 - 1
app-hd/controllers/OrderController.php

@@ -176,7 +176,18 @@ class OrderController extends BaseController
             $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
             $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
         }
-        $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
+        $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice']);
+        if (!empty($list)) {
+            foreach ($list as $key => $value) {
+                $debtPrice = $value['debtPrice'] ?? 0;
+                $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
+                $hasPayDebt = 0;
+                if ($debtPrice > $remainDebtPrice) {
+                    $hasPayDebt = bcsub($debtPrice, $remainDebtPrice, 2);
+                }
+                $list[$key]['hasPayDebt'] = floatval($hasPayDebt);
+            }
+        }
         $result = ['customInfo' => $info, 'list' => $list];
         util::success($result);
     }

+ 5 - 0
app-hd/controllers/RechargeController.php

@@ -9,6 +9,7 @@ use biz\shop\classes\ShopClass;
 use biz\sj\classes\SjClass;
 use bizGhs\custom\classes\CustomClass;
 use bizHd\custom\classes\HdClass;
+use bizHd\order\classes\SettleClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\imgUtil;
@@ -105,6 +106,10 @@ class RechargeController extends BaseController
                 'side' => 0,
             ];
             \bizHd\recharge\classes\RechargeClass::complete($recharge, $payWay, $params);
+
+            //这边要有销账单的动作
+            SettleClass::clearSettle();
+
             $transaction->commit();
             util::success($post);
         } catch (\Exception $e) {

+ 87 - 18
app-hd/controllers/SettleController.php

@@ -2,9 +2,13 @@
 
 namespace hd\controllers;
 
+use bizHd\custom\classes\CustomClass;
+use bizHd\custom\classes\HdClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\SettleClass;
+use bizHd\recharge\classes\RechargeClass;
 use common\components\dict;
+use common\components\orderSn;
 use common\components\util;
 use Yii;
 
@@ -20,28 +24,93 @@ class SettleController extends BaseController
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-
             $staff = $this->shopAdmin;
             $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
-            $id = $post['id'] ?? '';
-            if (is_numeric($id)) {
-                $order = OrderClass::getById($id, true);
-                if (empty($order)) {
-                    util::fail('没有找到订单');
-                }
-                OrderClass::valid($order, $this->mainId);
-                SettleClass::confirmSettle($order, $payWay, $staff);
-            } else {
-                $idArr = json_decode($id, true);
-                $ids = array_column($idArr, 'id');
-                $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
-                if (!empty($orderList)) {
-                    foreach ($orderList as $order) {
-                        OrderClass::valid($order, $this->mainId);
-                        SettleClass::confirmSettle($order, $payWay, $staff);
-                    }
+            $idData = $post['id'] ?? '';
+            if (is_numeric($idData)) {
+                util::fail('请求参数错误哦');
+            }
+            $customId = $post['customId'] ?? 0;
+            $custom = CustomClass::getLockById($customId);
+            if (empty($custom)) {
+                util::fail('没有找到客户');
+            }
+            $hdId = $custom->hdId ?? 0;
+            $hd = HdClass::getlockById($hdId);
+            if (empty($hd)) {
+                util::fail('客户信息缺失');
+            }
+            //先充值
+            $mayClearAmount = 0;
+            $idList = json_decode($idData, true);
+            $ids = array_column($idList, 'id');
+            if (empty($ids)) {
+                util::fail('请选择订单');
+            }
+            $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+            if (empty($orderList)) {
+                util::fail('请选择订单呢');
+            }
+            foreach ($orderList as $order) {
+                if ($order->mainId != $this->mainId) {
+                    util::fail('不是你的订单哦');
                 }
+                $remainDebtPrice = $order->remainDebtPrice ?? 0;
+                $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
+            }
+            if (empty($mayClearAmount)) {
+                util::fail('不需要销账');
+            }
+            $staffId = $this->shopAdminId;
+            $staffName = $this->shopAdminName;
+            $customName = $custom->name ?? '';
+            $userId = $custom->userId;
+            $hdName = $hd->name;
+            $shopId = $this->shopId;
+            $mainId = $this->mainId;
+            $orderSn = orderSn::getRechargeSn();
+            $shop = $this->shop;
+            $settleParams = [];
+
+            $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
+            if (!empty($hasSettle)) {
+                util::fail('这个客户名下有待结账单,请先取消');
             }
+
+            //创建待账单
+            $settle = SettleClass::addSettle(0, $orderList, $shop, $custom, $hd, $staff, $settleParams);
+            $settleId = $settle->id;
+            $settleAmount = $settle->actPrice;
+
+            $addData = [
+                'orderSn' => $orderSn,
+                'modPrice' => 1,
+                'payWay' => $payWay,
+                'style' => 1,
+                'shopId' => $shopId,
+                'mainId' => $mainId,
+                'hdId' => $hdId,
+                'hdName' => $hdName,
+                'onlinePay' => 1,
+                'amount' => $mayClearAmount,
+                'staffId' => $staffId,
+                'staffName' => $staffName,
+                'payStatus' => 0,
+                'payTime' => '0000-00-00 00:00:00',
+                'status' => 0,
+                'clearId' => $settleId,
+                'clearAmount' => $settleAmount,
+                'remark' => '',
+                'customId' => $customId,
+                'customName' => $customName,
+                'userId' => $userId,
+            ];
+            $respond = RechargeClass::addRecharge($addData);
+            $retId = $respond->id;
+            //充值成功并且销账成功
+            $recharge = RechargeClass::getLockById($retId);
+            $params = ['onlinePay' => 1, 'side' => 0];
+            RechargeClass::complete($recharge, $payWay, $params);
             $transaction->commit();
             util::complete();
         } catch (\Exception $exception) {

+ 41 - 24
app-mall/controllers/BaseController.php

@@ -5,6 +5,7 @@ namespace mall\controllers;
 use biz\shop\classes\ShopClass;
 use biz\sj\classes\SjClass;
 use bizHd\custom\classes\CustomClass;
+use bizMall\hd\classes\HdClass;
 use bizMall\merchant\services\MerchantExtendService;
 use bizMall\merchant\services\MerchantService;
 use bizMall\shop\classes\MainClass;
@@ -22,42 +23,58 @@ class BaseController extends PublicController
 
     public $validate = true;
     public $guestAccess = [];
-    public $userId = 0, $user = null, $shopId, $shop;
-    public $sjId, $sj, $sjExtend, $customId = 0, $custom = [], $mainId = 0, $main = [];
+    public $userId = 0, $user, $shopId, $shop;
+    public $sjId, $sj, $sjExtend, $customId = 0, $custom, $hd, $mainId = 0, $main;
     public $isWx;
 
     public function beforeAction($action)
     {
         Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
         $this->isWx = util::isWx();
-        $shopId = Yii::$app->request->get('account', 0);
-        $this->shopId = $shopId;
-        if (!empty($shopId)) {
-            $shop = ShopClass::getById($shopId, true);
-            if (!empty($shop)) {
-                $mainId = $shop->mainId ?? 0;
-                $main = MainClass::getById($mainId, true);
-                $this->main = $main;
-                $this->mainId = $mainId;
-                $this->shop = $shop;
-                $sjId = $shop->sjId ?? 0;
-                $this->sjId = $sjId;
-                $sj = SjClass::getById($this->sjId, true);
-                if (empty($sj)) {
-                    util::fail('没有商家信息');
-                }
-                $this->sj = $sj;
-                $this->sjExtend = MerchantExtendService::getBySjId($this->sjId);
-            }
-        }
         $userId = jwt::getLoginId();
         if (!empty($userId)) {
             $this->userId = $userId;
             $user = UserClass::getById($userId, true);
-            if (!empty($user)) {
-                $this->user = $user;
+            if (empty($user)) {
+                if (!in_array($action->id, $this->guestAccess)){
+                    util::fail('请先登录');
+                }
+            }
+            $this->user = $user;
+            $shopId = Yii::$app->request->get('account', 0);
+            if (!empty($shopId)) {
+                $this->shopId = $shopId;
+                $shop = ShopClass::getById($shopId, true);
+                if (!empty($shop)) {
+                    $this->shop = $shop;
+                    $mainId = $shop->mainId ?? 0;
+                    $main = MainClass::getById($mainId, true);
+                    $this->main = $main;
+                    $this->mainId = $mainId;
+                    $hdId = Yii::$app->request->get('hdId', 0);
+                    $hd = HdClass::getById($hdId, true);
+                    if (!empty($hd)) {
+                        if ($hd->userId != $this->userId) {
+                            util::fail('不是你的花店,无法访问哦');
+                        }
+                        if ($shopId != $hd->shopId) {
+                            util::fail('花店信息有问题哦');
+                        }
+                        $this->hd = $hd;
+                        $customId = $hd->customId ?? 0;
+                        $custom = CustomClass::getById($customId, true);
+                        $this->custom = $custom;
+                    } else {
+                        $respond = CustomClass::buildRelation($shop, $user);
+                        $hd = $respond['hd'];
+                        $custom = $respond['custom'];
+                        $this->hd = $hd;
+                        $this->custom = $custom;
+                    }
+                }
             }
         }
+
         return parent::beforeAction($action);
     }
 

+ 19 - 0
app-mall/controllers/ConsoleController.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace mall\controllers;
+
+use common\components\dict;
+use common\components\util;
+use Yii;
+
+class ConsoleController extends BaseController
+{
+
+    //常用初始化 ssh 20250628
+    public function actionInit()
+    {
+        $dict = dict::get($this->mainId);
+        util::success(['dict' => $dict]);
+    }
+
+}

+ 22 - 0
app-mall/controllers/HdController.php

@@ -3,6 +3,7 @@
 namespace mall\controllers;
 
 use bizHd\custom\classes\HdClass;
+use common\components\imgUtil;
 use common\components\util;
 use bizHd\custom\classes\CustomClass;
 use Yii;
@@ -10,6 +11,27 @@ use Yii;
 class HdController extends BaseController
 {
 
+    //花店详情 ssh 20250627
+    public function actionDetail()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $hd = \bizMall\hd\classes\HdClass::getById($id);
+        if (empty($hd)) {
+            util::fail('没有花店信息');
+        }
+        if ($hd['userId'] != $this->userId) {
+            util::fail('不是你的店');
+        }
+        $shortAvatar = !empty($val['avatar']) ? $val['avatar'] : 'hhb_small.png';
+        $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+        $bigAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+        $hd['shortAvatar'] = $shortAvatar;
+        $hd['smallAvatar'] = $smallAvatar;
+        $hd['bigAvatar'] = $bigAvatar;
+        util::success($hd);
+    }
+
     //花店信息 ssh 20230111
     public function actionInfo()
     {

+ 31 - 4
app-mall/controllers/OrderController.php

@@ -14,6 +14,7 @@ use bizMall\order\services\OrderService;
 use bizMall\promote\services\CouponService;
 use bizMall\saas\services\RegionService;
 use bizMall\user\services\UserService;
+use common\components\dateUtil;
 use common\components\dict;
 use common\components\httpUtil;
 use common\components\noticeUtil;
@@ -27,6 +28,32 @@ use common\components\lakala\Lakala;
 class OrderController extends BaseController
 {
 
+    //记账单列表 ssh 20250627
+    public function actionDebtList()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $where = [];
+        $where['userId'] = $this->userId;
+        if (!empty($id)) {
+            $hd = \bizMall\hd\classes\HdClass::getById($id, true);
+            if (empty($hd)) {
+                util::fail('无效的花店');
+            }
+            $where['hdId'] = $id;
+        }
+        $where['debt'] = 1;
+        $searchTime = $get['searchTime'] ?? '';
+        if (!empty($searchTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
+            $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+        $respond = OrderClass::getDebtList($where);
+        util::success($respond);
+    }
+
     //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
     public function actionFreight()
     {
@@ -63,7 +90,7 @@ class OrderController extends BaseController
         //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
         $mainId = $this->mainId;
         if (getenv('YII_ENV') == 'production') {
-            if (in_array($mainId, [40057, 7779, 42940, 26374,10536])) {
+            if (in_array($mainId, [40057, 7779, 42940, 26374, 10536])) {
                 util::fail('暂时无法访问');
             }
         } else {
@@ -162,7 +189,7 @@ class OrderController extends BaseController
             $user = $this->user;
             $post['bookMobile'] = $user->mobile ?? '';
             $post['bookName'] = $user->name ?? '';
-            $return = OrderService::createOrder($post,$custom);
+            $return = OrderService::createOrder($post, $custom);
 
             if (isset($return->shopId)) {
                 if ($return->shopId == 7610) {
@@ -464,7 +491,7 @@ class OrderController extends BaseController
                 'orderSn' => $oldOrderSn,
             ];
             $response = $laResource->close($closeParams);
-            if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+            if (!isset($response['code']) || $response['code'] != 'BBS00000') {
                 $msg = $response['msg'] ?? '';
                 noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg, '15280215347');
                 util::fail('出错了哦,请重新下一单');
@@ -511,7 +538,7 @@ class OrderController extends BaseController
             'couponId' => $couponId,
         ];
         $response = $laResource->driveWxPay($wxParams);
-        if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
             $errMsg = $response['msg'] ?? '';
             noticeUtil::push($errMsg, '15280215347');
             util::fail('支付失败');

+ 112 - 2
app-mall/controllers/RechargeController.php

@@ -19,6 +19,112 @@ class RechargeController extends BaseController
 
     public $guestAccess = ['recharge'];
 
+    //用微信支付进行充值 ssh 20250709
+    public function actionWxPayRecharge()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'] ?? '';
+        //避免重复提交
+        util::checkRepeatCommit($id, 8);
+        $recharge = RechargeClass::getById($id, true);
+        if (empty($recharge)) {
+            util::fail('没有充值单');
+        }
+        $userId = $this->userId;
+        $shopId = $this->shopId;
+        if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
+            util::fail('不是你的充值单');
+        }
+        $shop = $this->shop;
+        $user = $this->user;
+        if (empty($shop)) {
+            util::fail('没有门店信息');
+        }
+        $shop = $this->shop;
+        $orderSn = $recharge->orderSn;
+
+        $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
+        if (empty($openId)) {
+            $openId = !empty($user['miniOpenId']) ? $user['miniOpenId'] : '';
+        }
+        if (empty($openId)) {
+            util::fail('没有找到openId');
+        }
+        $name = '充值销账,单号' . $orderSn;
+        $totalFee = $recharge->amount ?? 0;
+        $orderId = $recharge->id;
+        $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
+
+        $sjExtend = WxOpenClass::getMallWxInfo();
+        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
+        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
+        $params = [
+            'appid' => 'OP00002119',
+            'serial_no' => '018b08cfddbd',
+            'merchant_no' => $shop->lklSjNo,
+            'term_no' => $shop->lklScanTermNo,
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
+        $wxParams = [
+            'orderSn' => $orderSn,
+            'amount' => $totalFee,
+            'capitalType' => $capitalType,
+            'notifyUrl' => $notifyUrl,
+            'wxAppId' => $sjExtend['miniAppId'],
+            'openId' => $openId,
+            'subject' => $name,
+            'couponId' => 0,
+        ];
+        $response = $laResource->driveWxPay($wxParams);
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
+            $errMsg = $response['msg'] ?? '';
+            noticeUtil::push($errMsg, '15280215347');
+            util::fail('充值失败');
+        }
+        $respData = $response['resp_data'] ?? [];
+        $accRespFields = $respData['acc_resp_fields'] ?? [];
+        if (empty($accRespFields)) {
+            util::fail('充值失败,没有找到支付数据');
+        }
+        $appId = $accRespFields['app_id'] ?? '';
+        $nonceStr = $accRespFields['nonce_str'] ?? '';
+        $paySign = $accRespFields['pay_sign'] ?? '';
+        $package = $accRespFields['package'] ?? '';
+        $signType = $accRespFields['sign_type'] ?? '';
+        $timeStamp = $accRespFields['time_stamp'] ?? '';
+        $new = [
+            'id' => $orderId,
+            'appId' => $appId,
+            'nonceStr' => $nonceStr,
+            'paySign' => $paySign,
+            'package' => $package,
+            'signType' => $signType,
+            'timeStamp' => $timeStamp,
+            'orderSn' => $orderSn,
+        ];
+        util::success($new);
+    }
+
+    //获取充值订单的详情 ssh 20250709
+    public function actionGetDetail()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $recharge = RechargeClass::getById($id, true);
+        if (empty($recharge)) {
+            util::fail('没有找到充值订单');
+        }
+        $userId = $this->userId;
+        $shopId = $this->shopId;
+        if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
+            util::fail('不是你的充值单');
+        }
+        util::success($recharge);
+    }
+
     //充值 ssh 20240507
     public function actionRecharge()
     {
@@ -44,8 +150,12 @@ class RechargeController extends BaseController
         if (empty($hd)) {
             util::fail('没有找到花店哦!');
         }
-        if (empty($salt) || $hd->salt != $salt) {
-            util::fail('不是你的花店哦');
+        if (empty($salt)) {
+
+        }else{
+            if($hd->salt != $salt){
+                util::fail('不是你的花店哦');
+            }
         }
         $customId = $hd->customId ?? 0;
         $custom = CustomClass::getById($customId, true);

+ 117 - 0
app-mall/controllers/SettleController.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace mall\controllers;
+
+use bizHd\order\classes\SettleClass;
+use bizHd\recharge\classes\RechargeClass;
+use bizHd\wx\classes\WxOpenClass;
+use bizMall\order\classes\OrderClass;
+use common\components\dict;
+use common\components\lakala\Lakala;
+use common\components\noticeUtil;
+use common\components\orderSn;
+use common\components\util;
+use Yii;
+
+class SettleController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    //创建结账和充值单 ssh 20250709
+    public function actionCreateOrder()
+    {
+        $post = Yii::$app->request->post();
+
+        $shop = $this->shop;
+        if (empty($shop)) {
+            util::fail('没有门店信息');
+        }
+        $hd = $this->hd;
+        if (empty($hd)) {
+            util::fail('没有花店信息呢');
+        }
+        $custom = $this->custom;
+        if (empty($custom)) {
+            util::fail('花店信息缺失');
+        }
+
+        $idList = $post['ids'] ?? '';
+        $idList = trim($idList);
+        if (empty($idList)) {
+            util::fail('请选择订单');
+        }
+        $ids = explode(',', $idList);
+        if (empty($ids)) {
+            util::fail('请选择订单哦');
+        }
+        $mayClearAmount = 0;
+        $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+        if (empty($orderList)) {
+            util::fail('没有选订单');
+        }
+        foreach ($orderList as $order) {
+            if ($order->mainId != $this->mainId) {
+                util::fail('不是你的订单呢');
+            }
+            $remainDebtPrice = $order->remainDebtPrice ?? 0;
+            $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
+        }
+        if (empty($mayClearAmount)) {
+            util::fail('不需要销账');
+        }
+        $orderSn = orderSn::getRechargeSn();
+        $payWay = 0;
+        $shopId = $this->shopId;
+        $mainId = $this->mainId;
+        $hdId = $hd->id;
+        $hdName = $hd->name;
+        $staffId = 0;
+        $staffName = '';
+        $customId = $custom->id;
+        $customName = $custom->name;
+        $userId = $this->userId;
+        $settleParams = [];
+        $staff = [];
+
+        //避免重复提交
+        util::checkRepeatCommit($userId, 8);
+
+        $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
+        if (!empty($hasSettle)) {
+            util::fail('这个客户名下有待结账单,请先取消');
+        }
+
+        //创建待账单
+        $settle = SettleClass::addSettle(1, $orderList, $shop, $custom, $hd, $staff, $settleParams);
+        $settleId = $settle->id;
+        $settleAmount = $settle->actPrice;
+
+        $createData = [
+            'customId' => $customId,
+            'customName' => $customName,
+            'userId' => $userId,
+            'orderSn' => $orderSn,
+            'modPrice' => 1,
+            'payWay' => $payWay,
+            'style' => 1,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'hdId' => $hdId,
+            'hdName' => $hdName,
+            'onlinePay' => 1,
+            'amount' => $mayClearAmount,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'payStatus' => 0,
+            'payTime' => '0000-00-00 00:00:00',
+            'status' => 0,
+            'clearId' => $settleId,
+            'clearAmount' => $settleAmount,
+            'remark' => '',
+        ];
+        $respond = RechargeClass::addRecharge($createData);
+        util::success($respond);
+    }
+
+}

+ 46 - 0
biz-ghs/custom/classes/CustomClass.php

@@ -756,4 +756,50 @@ class CustomClass extends BaseClass
         util::success(['file' => $fileUrl, 'shortFile' => $file]);
     }
 
+    public static function showTotalBalance($pfShopId = 0, $lsShopId = 0)
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $arr['pf'] = ['debt' => 0, 'balance' => 0];
+        $arr['ls'] = ['debt' => 0, 'balance' => 0];
+        if (!empty($pfShopId)) {
+            $custom = CustomClass::getAllByCondition(['ownShopId' => $pfShopId], null, '*', null, true);
+            $pfDebt = 0;
+            $pfBalance = 0;
+            if (!empty($custom)) {
+                foreach ($custom as $c) {
+                    $balance = $c->balance ?? 0;
+                    if ($balance > 0) {
+                        $pfBalance = bcadd($pfBalance, $balance, 2);
+                    } else {
+                        $balance = abs($balance);
+                        $pfDebt = bcadd($pfDebt, $balance, 2);
+                    }
+                }
+            }
+            $arr['pf']['debt'] = floatval($pfDebt);
+            $arr['pf']['balance'] = floatval($pfBalance);
+        }
+        if (!empty($lsShop)) {
+            $lsCustom = \bizHd\custom\classes\CustomClass::getAllByCondition(['shopId' => $lsShopId], null, '*', null, true);
+            $lsDebt = 0;
+            $lsBalance = 0;
+            if (!empty($lsCustom)) {
+                foreach ($lsCustom as $lc) {
+                    $balance = $lc->balance ?? 0;
+                    if ($balance > 0) {
+                        $lsBalance = bcadd($lsBalance, $balance, 2);
+                    } else {
+                        $balance = abs($balance);
+                        $lsDebt = bcadd($lsDebt, $balance, 2);
+                    }
+                }
+                $arr['ls']['debt'] = floatval($lsDebt);
+                $arr['ls']['balance'] = floatval($lsBalance);
+            }
+        }
+        return $arr;
+    }
+
 }

+ 82 - 61
biz-hd/custom/classes/CustomClass.php

@@ -152,47 +152,55 @@ class CustomClass extends BaseClass
     public static function cgDebtAmountAdd($custom, $order)
     {
         $amount = $order->remainDebtPrice ?? 0;
-        $custom->isDebt = 1;
-        $lastDebt = bcadd($custom->debtAmount, $amount, 2);
-        $custom->debtAmount = $lastDebt;
+        $lastBalance = bcsub($custom->balance, $amount, 2);
+        $custom->balance = $lastBalance;
+        if ($custom->balance < 0) {
+            $custom->isDebt = 1;
+        }
         $custom->save();
 
+        $hdId = $custom->hdId ?? 0;
+        $hd = HdClass::getLockById($hdId);
+        if (empty($hd)) {
+            util::fail('花店信息缺失');
+        }
+        $remain = bcsub($hd->balance, $amount, 2);
+        $hd->balance = $remain;
+        if ($hd->balance < 0) {
+            $hd->debt = 2;
+        }
+        $hd->save();
+
+        $staffId = $order->shopAdminId ?? 0;
+        $staffName = $order->shopAdminName ?? '';
         $relateId = $order->id ?? 0;
         $customId = $custom->id ?? 0;
         $orderSn = $order->orderSn ?? '';
         $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
-        $event = '购买花材,订单号:' . $orderSn;
-
+        $event = '购买花材,单号:' . $orderSn;
+        $customName = $custom->name ?? '';
+        $onlinePay = 1;
+        $side = 0;
+        $payWay = 0;
         $change = [
-            'relateId' => $relateId,
             'customId' => $customId,
-            'ptStyle' => dict::getDict('ptStyle', 'hd'),
+            'customName' => $customName,
+            'relateId' => $relateId,
+            'onlinePay' => $onlinePay,
             'capitalType' => $capitalType,
             'amount' => $amount,
-            'balance' => $lastDebt,
-            'io' => 1,
-            'payWay' => $order->payWay,
+            'balance' => $lastBalance,
+            'io' => 0,
+            'side' => $side,
+            'payWay' => $payWay,
             'event' => $event,
-            'sjId' => $order->sjId,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
             'shopId' => $order->id,
             'mainId' => $order->mainId,
+            'remark' => '',
         ];
-        CustomDebtRecordClass::addChange($change);
-
-        $mainId = $order->mainId ?? 0;
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有main信息38');
-        }
-        $debt = $main->debt ?? 0;
-        $remain = bcadd($debt, $amount, 2);
-        $main->debt = $remain;
-        $main->save();
-
-        $event = $custom->name . ' 购买花材,订单号:' . $orderSn;
-        $change['balance'] = $remain;
-        $change['event'] = $event;
-        TotalDebtChangeClass::addChange($change);
+        BalanceChangeClass::add($change, true);
     }
 
     //散客申请退款,零售门店欠款金额减少
@@ -201,7 +209,7 @@ class CustomClass extends BaseClass
         $debtAmount = $custom->debtAmount ?? 0.00;
         $remain = bcsub($debtAmount, $amount, 2);
         if ($remain < 0) {
-            noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次退款金额:{$amount} 客户ID:{$custom->id} 超出了", '15280215347');
+            noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次退款金额:{$amount} 客户ID:{$custom->id} 超出了,编号66379", '15280215347');
             util::fail('操作失败,欠款金额会出现负数');
         }
         $custom->isDebt = $remain <= 0 ? 0 : 1;
@@ -244,53 +252,66 @@ class CustomClass extends BaseClass
         TotalDebtChangeClass::addChange($change);
     }
 
-    //客户结账欠款金额减少 ssh 20220908
+    //客户结账欠款金额减少 ssh 20250627
     public static function clearDebtAmountReduce($custom, $amount, $clear)
     {
-        $debtAmount = $custom->debtAmount ?? 0.00;
-        $remain = bcsub($debtAmount, $amount, 2);
-        if ($remain < 0) {
-            noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次结账金额:{$amount} 客户ID:{$custom->id} 超出了", '15280215347');
+        $balance = $custom->balance ?? 0.00;
+        $remainBalance = bcsub($balance, $amount, 2);
+        if ($remainBalance < 0) {
+            noticeUtil::push("零售客户欠款总金额:{$balance} 本次结账金额:{$amount} 客户ID:{$custom->id} 超出了,编号788965", '15280215347');
             util::fail('操作失败,结账后欠款金额会出现负数');
         }
-        $custom->isDebt = $remain <= 0 ? 0 : 1;
-        $custom->debtAmount = $remain;
+        $custom->balance = $remainBalance;
         $custom->save();
+
+        $hdId = $custom->hdId ?? 0;
+        $hd = HdClass::getLockById($hdId);
+        if (empty($hd)) {
+            util::fail('店铺信息异常');
+        }
+        $hdName = $hd->name ?? '';
+        $hdBalance = $hd->balance ?? 0;
+        $hdRemainBalance = bcsub($hdBalance, $amount, 2);
+        $hd->balance = $hdRemainBalance;
+        $hd->save();
+
+        if (floatval($hdRemainBalance) != floatval($remainBalance)) {
+            util::fail('余额有问题');
+        }
+
         $relateId = $clear->id ?? 0;
         $customId = $custom->id ?? 0;
         $capitalType = dict::getDict('capitalType', 'hdXsClear', 'id');
         $orderSn = $clear->orderSn ?? '';
-
+        $customName = $custom->name ?? '';
+        $event = "结账,单号:{$orderSn}";
+        $staffId = $clear->hdShopAdminId ?? 0;
+        $staffName = $clear->hdShopAdminName ?? '';
+        $shopId = $clear->hdShopId ?? 0;
+        $mainId = $clear->mainId ?? 0;
+        $remark = '';
+        $payWay = $clear->payWay ?? 0;
         $change = [
-            'relateId' => $relateId,
             'customId' => $customId,
-            'ptStyle' => dict::getDict('ptStyle', 'ghs'),
+            'customName' => $customName,
+            'hdId' => $hdId,
+            'hdName' => $hdName,
+            'relateId' => $relateId,
+            'onlinePay' => 1,
             'capitalType' => $capitalType,
             'amount' => $amount,
-            'balance' => $remain,
+            'balance' => $hdRemainBalance,
             'io' => 0,
-            'payWay' => 0,
-            'event' => "结账,单号:{$orderSn}",
-            'sjId' => $clear->sjId,
-            'shopId' => $clear->id,
-            'mainId' => $clear->mainId,
+            'side' => 0,
+            'payWay' => $payWay,
+            'event' => $event,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'remark' => $remark,
         ];
-        CustomDebtRecordClass::addChange($change);
-
-        $mainId = $clear->mainId ?? 0;
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有main信息40');
-        }
-        $debt = $main->debt ?? 0;
-        $totalRemain = bcsub($debt, $amount, 2);
-        $main->debt = $totalRemain;
-        $main->save();
-
-        $event = $custom->name . " 结账,单号:{$orderSn}";
-        $change['balance'] = $totalRemain;
-        $change['event'] = $event;
-        TotalDebtChangeClass::addChange($change);
+        BalanceChangeClass::add($change, true);
     }
 
     public static function getCustomCacheKey($sjId, $shopId, $userId)
@@ -313,7 +334,7 @@ class CustomClass extends BaseClass
         if (empty($shop)) {
             return false;
         }
-        if($shop->ptStyle == 2){
+        if ($shop->ptStyle == 2) {
             util::fail('有问题,批发店状态');
         }
         $salt = stringUtil::charsShuffleLowerCase(8);

+ 7 - 0
biz-hd/custom/classes/CustomDebtRecordClass.php

@@ -20,4 +20,11 @@ class CustomDebtRecordClass extends BaseClass
         return self::add($change, true);
     }
 
+    public static function getChangeList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC,id DESC');
+        return $data;
+    }
+
+
 }

+ 1 - 3
biz-hd/order/classes/OrderClass.php

@@ -137,9 +137,7 @@ class OrderClass extends BaseClass
         $riseNum = StatOrderCountClass::addOrder($shop, $main);
         $data['sendNum'] = date("d") . $riseNum;
         $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
-        $return = self::add($data, true);
-
-        return $return;
+        return self::add($data, true);
     }
 
     public static function getByOrderSn($orderSn)

+ 75 - 2
biz-hd/order/classes/SettleClass.php

@@ -17,6 +17,79 @@ class SettleClass extends BaseClass
 
     public static $baseFile = '\bizHd\order\models\Settle';
 
+    //$side 0 表示花店创建结账单,1客户创建结账单,二者区别有花店有带$staff信息,客户没有
+    //$params 预留参数
+    public static function addSettle($side, $orderList, $shop, $custom, $hd, $staff = [], $params = [])
+    {
+        $totalRemain = 0;
+        $string = '';
+        $shopId = $shop->id;
+        $mainId = $shop->mainId;
+        $sjId = $shop->sjId;
+
+        $customId = $custom->id ?? 0;
+        $customName = $custom->name ?? '';
+        $customAvatar = $custom->avatar;
+        $customMobile = $custom->mobile;
+        $customAddress = $custom->address;
+        $customUserId = $custom->userId;
+
+        $hdId = $hd->id;
+        $hdName = $hd->name;
+        $hdAvatar = $hd->avatar;
+        $hdMobile = $hd->mobile;
+        $hdAddress = $hd->address;
+        $staffId = 0;
+        $staffName = '';
+        if ($side == 1) {
+            $staffId = $staff->id;
+            $staffName = $staff->name ?? '';
+        }
+
+        $settleOrderSn = orderSn::getSettleSn();
+        foreach ($orderList as $order) {
+            $remainDebtPrice = $order->remainDebtPrice ?? 0;
+            $totalRemain = bcadd($totalRemain, $remainDebtPrice, 2);
+            $string = $string . ',' . $order->id;
+        }
+        $num = count($orderList);
+        $settleData = [
+            'prePrice' => $totalRemain,
+            'actPrice' => $totalRemain,
+            'realPrice' => $totalRemain,
+            'payWay' => 0,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'sjId' => $sjId,
+            'purchaseIds' => '',
+            'saleIds' => $string,
+            'num' => $num,
+            'status' => 1,
+            'customId' => $customId,
+            'customName' => $customName,
+            'customAvatar' => $customAvatar,
+            'customMobile' => $customMobile,
+            'customAddress' => $customAddress,
+            'customUserId' => $customUserId,
+            'hdId' => $hdId,
+            'hdShopId' => $shopId,
+            'hdName' => $hdName,
+            'hdAvatar' => $hdAvatar,
+            'hdMobile' => $hdMobile,
+            'hdAddress' => $hdAddress,
+            'hdStaffId' => $staffId,
+            'hdStaffName' => $staffName,
+            'orderSn' => $settleOrderSn,
+            'payTime' => '0000-00-00 00:00:00',
+        ];
+        return self::addData($settleData);
+    }
+
+    public static function clearSettle()
+    {
+
+    }
+
     //结清尾款 ssh 20220708
     public static function confirmSettle($order, $payWay, $staff)
     {
@@ -92,8 +165,8 @@ class SettleClass extends BaseClass
         }
 
         //客户欠款金额减少
-        $custom = CustomClass::getLockById($customId);
-        CustomClass::clearDebtAmountReduce($custom, $remainDebtPrice, $settleReturn);
+        //$custom = CustomClass::getLockById($customId);
+        //CustomClass::clearDebtAmountReduce($custom, $remainDebtPrice, $settleReturn);
 
         //制作单上的尾款也去掉
         WorkClass::updateByCondition(['orderId' => $orderId], ['orderDebtPrice' => 0]);

+ 2 - 0
biz-hd/order/services/OrderService.php

@@ -33,6 +33,7 @@ class OrderService extends BaseService
         $orderSn = orderSn::getOrderSn();
         $customId = $custom->id ?? 0;
         $hdId = $custom->hdId ?? 0;
+        $userId = $custom->userId ?? 0;
         $sjId = $data['sjId'] ?? 0;
         $shopId = $data['shopId'] ?? 0;
         $mainId = $data['mainId'] ?? 0;
@@ -315,6 +316,7 @@ class OrderService extends BaseService
         $data['customId'] = $customId;
         $data['hdId'] = $hdId;
         $data['sjId'] = $sjId;
+        $data['userId'] = $userId;
         $data['shopId'] = $shopId;
         $data['mainId'] = $mainId;
         $data['manyType'] = $manyType;

+ 36 - 32
biz-hd/recharge/classes/RechargeClass.php

@@ -92,38 +92,42 @@ class RechargeClass extends BaseClass
         $shop = ShopClass::getById($shopId, true);
         $rechargeWeal = $shop->rechargeWeal ?? 0;
         $addGiveAmount = 0;
-        if ($rechargeWeal == 1 || $rechargeWeal == 2) {
-            $weal = MemberWealClass::getAllByCondition(['shopId' => $shopId], null, '*');
-            if (!empty($weal)) {
-                $weal = arrayUtil::arraySort($weal, 'level', SORT_ASC);
-                if ($rechargeWeal == 1) {
-                    //充值升级会员
-                    $newLevel = 0;
-                    foreach ($weal as $k => $v) {
-                        $thisRecharge = $v['recharge'] ?? 0;
-                        $thisLevel = $v['level'] ?? 0;
-                        if ($amount >= $thisRecharge) {
-                            $newLevel = $thisLevel;
+
+        //如果客户有本身有欠款,充值不享受任何福利
+        if ($custom->balance > 0) {
+            if ($rechargeWeal == 1 || $rechargeWeal == 2) {
+                $weal = MemberWealClass::getAllByCondition(['shopId' => $shopId], null, '*');
+                if (!empty($weal)) {
+                    $weal = arrayUtil::arraySort($weal, 'level', SORT_ASC);
+                    if ($rechargeWeal == 1) {
+                        //优惠方式1:充值升级会员
+                        $newLevel = 0;
+                        foreach ($weal as $k => $v) {
+                            $thisRecharge = $v['recharge'] ?? 0;
+                            $thisLevel = $v['level'] ?? 0;
+                            if ($amount >= $thisRecharge) {
+                                $newLevel = $thisLevel;
+                            }
                         }
-                    }
-                    $params = [
-                        'style' => 0,
-                        'rechargeAmount' => floatval($amount),
-                        'onlinePay' => $onlinePay,
-                    ];
-                    if ($newLevel > $oldLevel) {
-                        CustomClass::levelChange($oldLevel, $newLevel, $shop, $custom, $hd, $params);
-                    }
-                } else {
-                    //充多少送多少
-                    foreach ($weal as $k => $v) {
-                        $thisRecharge = $v['recharge'] ?? 0;
-                        $thisGive = $v['give'] ?? 0;
-                        if ($amount >= $thisRecharge) {
-                            $recharge->giveAmount = $thisGive;
-                            $recharge->save();
-                            //增加赠送的金额
-                            $addGiveAmount = $thisGive;
+                        $params = [
+                            'style' => 0,
+                            'rechargeAmount' => floatval($amount),
+                            'onlinePay' => $onlinePay,
+                        ];
+                        if ($newLevel > $oldLevel) {
+                            CustomClass::levelChange($oldLevel, $newLevel, $shop, $custom, $hd, $params);
+                        }
+                    } else {
+                        //优惠方式2:充多少送多少
+                        foreach ($weal as $k => $v) {
+                            $thisRecharge = $v['recharge'] ?? 0;
+                            $thisGive = $v['give'] ?? 0;
+                            if ($amount >= $thisRecharge) {
+                                $recharge->giveAmount = $thisGive;
+                                $recharge->save();
+                                //增加赠送的金额
+                                $addGiveAmount = $thisGive;
+                            }
                         }
                     }
                 }
@@ -142,7 +146,7 @@ class RechargeClass extends BaseClass
         $hd->balance = bcadd($hd->balance, $totalAmount, 2);
         $hd->save();
         if ($hd->balance != $custom->balance) {
-            $msg = '充值回调失败,金额不一致';
+            $msg = '充值金额不一致。编号:' . floatval($hd->balance) . ' / ' . floatval($custom->balance);
             Yii::info($msg);
             util::fail($msg);
         }

+ 8 - 0
biz-mall/order/classes/OrderClass.php

@@ -58,6 +58,14 @@ class OrderClass extends BaseClass
         20000 => [90, 100],
     ];
 
+    //所有的欠款采购单 ssh 2021.1.26
+    public static function getDebtList($where)
+    {
+        $list = self::getAllList('*', $where, 'addTime DESC');
+        $count = self::getCount($where);
+        return ['list' => $list, 'debtNum' => $count];
+    }
+
     //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
     public static function getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight)
     {

+ 3 - 0
common/components/dict.php

@@ -408,6 +408,8 @@ class dict
             'customAskGhsRechargeReturn' => ['id' => 76, 'name' => 'customAskGhsRechargeReturn'],
             //减少散客的余额
             'deduct' => ['id' => 77, 'name' => 'deduct'],
+            //如果涉及是系统处理和操作,都可以用这个流水类型
+            'system' => ['id' => 78, 'name' => 'system'],
         ],
         "capitalTypeList" => [//流水类型的对应链接,后台收支明细查看时跳转的链接
             0 => ['link' => '/capital/order-detail', 'name' => '网店', 'orderLink' => '/order/detail', 'id' => 0,],
@@ -457,6 +459,7 @@ class dict
             75 => ['link' => '', 'name' => '售后返充', 'id' => 75,],
             76 => ['link' => '', 'name' => '售后返充', 'id' => 76,],
             77 => ['link' => '', 'name' => '手动减少', 'id' => 77,],
+            78 => ['link' => '', 'name' => '系统操作', 'id' => 78,],
         ],
 
         //用户来源

+ 127 - 0
console/controllers/LsCustomController.php

@@ -0,0 +1,127 @@
+<?php
+
+namespace console\controllers;
+
+use bizHd\balance\classes\BalanceChangeClass;
+use bizHd\custom\classes\CustomClass;
+use bizHd\custom\classes\HdClass;
+use bizHd\custom\models\Custom;
+use bizHd\shop\models\Shop;
+use common\components\dict;
+use common\components\util;
+use yii\console\Controller;
+use Yii;
+
+class LsCustomController extends Controller
+{
+
+
+    public function actionIndex()
+    {
+        //先确认所有客户的欠款总数跟账单总和能不能对应上 ssh 20250620
+        //批发不需要这一步
+        //零售要去数据库确认这一步
+    }
+
+    public function actionMigrate()
+    {
+
+        $query = new \yii\db\Query();
+        $query->from(Shop::tableName());
+        $query->where(['ptStyle' => 1]);
+        $query->orderBy('addTime ASC');
+        foreach ($query->batch(20) as $shopList) {
+            foreach ($shopList as $shop) {
+
+                $connection = Yii::$app->db;
+                $transaction = $connection->beginTransaction();
+
+                try {
+
+                    $shopId = $shop['id'] ?? 0;
+                    $query = new \yii\db\Query();
+                    $query->from(Custom::tableName());
+                    $query->where(['shopId' => $shopId]);
+                    $query->orderBy('addTime ASC');
+                    foreach ($query->batch(50) as $customList) {
+                        foreach ($customList as $custom) {
+                            $customId = $custom['id'] ?? 0;
+                            $debtAmount = $custom['debtAmount'] ?? 0;
+                            $hdId = $custom['hdId'] ?? 0;
+                            $customName = $custom['name'] ?? '';
+                            if (empty($hdId) || empty($customId)) {
+                                echo $customName . " customId:" . $customId . " hdId:" . $hdId . " 的ID是空的 \n";
+                                util::stop();
+                            }
+                            if ($debtAmount > 0) {
+
+                                echo "shopId:".$shopId." | ".$customName . " customId:" . $customId . " hdId:" . $hdId . " 有欠款 ==== \n\n";
+
+                                $custom = CustomClass::getById($customId, true);
+                                $hd = HdClass::getById($hdId, true);
+                                if (empty($custom) || empty($hd)) {
+                                    echo $customName . " customId:" . $customId . " hdId:" . $hdId . " 的对象是空的哦!! \n";
+                                    util::stop();
+                                }
+                                $balance = $custom->balance ?? 0;
+                                $hdBalance = $hd->balance ?? 0;
+                                if (floatval($balance) != $hdBalance) {
+                                    echo $customName . " customId:" . $customId . " hdId:" . $hdId . " 二边余额不一致 \n";
+                                    util::stop();
+                                }
+                                $newBalance = bcsub($balance, $debtAmount, 2);
+                                $custom->balance = $newBalance;
+                                $custom->debtAmount = 0;
+                                $custom->isDebt =0;
+                                $custom->debtNum = 0;
+                                $custom->save();
+
+                                $hd->balance = $newBalance;
+                                $hd->debtAmount = 0;
+                                $hd->debt =1;
+                                $hd->debtNum = 0;
+                                $hd->save();
+
+                                $hdName = $hd->name ?? '';
+                                $mainId = $shop['mainId'] ?? 0;
+                                $event = '系统操作:合并欠款';
+                                $capitalType = dict::getDict('capitalType', 'system', 'id');
+                                $change = [
+                                    'customId' => $customId,
+                                    'customName' => $customName,
+                                    'hdId' => $hdId,
+                                    'hdName' => $hdName,
+                                    'relateId' => 0,
+                                    'onlinePay' => 1,
+                                    'capitalType' => $capitalType,
+                                    'amount' => $debtAmount,
+                                    'balance' => $newBalance,
+                                    'io' => 0,
+                                    'side' => 0,
+                                    'payWay' => 0,
+                                    'event' => $event,
+                                    'staffId' => 0,
+                                    'staffName' => '',
+                                    'shopId' => $shopId,
+                                    'mainId' => $mainId,
+                                    'remark' => '',
+                                ];
+                                BalanceChangeClass::add($change, true);
+
+                            }else{
+                                //echo "shopId:".$shopId." | ".$customName . " customId:" . $customId . " hdId:" . $hdId . " 没有欠款 ok ok \n";
+                            }
+                        }
+                    }
+                    $transaction->commit();
+
+                } catch (\Exception $e) {
+                    $transaction->rollBack();
+                    $msg = $e->getMessage();
+                    echo "报错了:" . $msg . "\n";
+                }
+            }
+        }
+    }
+
+}