Преглед на файлове

Merge branch 'minus' into dev

shish преди 1 година
родител
ревизия
6c8259a093

+ 16 - 1
app-hd/controllers/RechargeController.php

@@ -27,11 +27,26 @@ class RechargeController extends BaseController
     //获取商城端充值页小程序短链接和说明内容
     public function actionGetMallRechargeShortLink()
     {
+        $get = Yii::$app->request->get();
+        if (getenv('YII_ENV') == 'dev') {
+            util::success(['rechargeAccountLink' => 'www.google.com', 'orderLink' => 'www.google.com']);
+        }
+        $orderId = $get['orderId'] ?? 0;
         $account = $this->shopId;
         $page = 'pages/member/recharge?account=' . $account;
         $ret = WxMiniClass::getShortLink($page);
         $link = $ret['link'] ?? '';
-        util::success(['link' => $link]);
+        $orderLink = '';
+        if (!empty($orderId)) {
+            $order = OrderClass::getById($orderId, true);
+            if ($order->mainId != $this->mainId) {
+                util::fail('访问错误');
+            }
+            $orderPage = 'pages/member/recharge?account=' . $account . '&id=' . $orderId;
+            $res = WxMiniClass::getShortLink($orderPage);
+            $orderLink = $res['link'] ?? '';
+        }
+        util::success(['rechargeAccountLink' => $link, 'orderLink' => $orderLink]);
     }
 
     //获取扫码充值的小程序码 ssh 20250307

+ 0 - 4
app-hd/controllers/RefundController.php

@@ -110,10 +110,6 @@ class RefundController extends BaseController
                 util::fail('2023年10月17日前订单无法申请退款');
             }
 
-            if ($order->payWay == 2) {
-                util::fail('余额支付订单暂不支持售后');
-            }
-
             $addTime = $order->addTime ?? '';
             $current = time();
             if ($order->debt != 1 && (strtotime($addTime) + 3 * 30 * 24 * 60 * 60) < $current) {

+ 46 - 109
biz-hd/custom/classes/CustomClass.php

@@ -188,20 +188,24 @@ class CustomClass extends BaseClass
             $settleId = $set->id;
         }
 
-        $lastBalance = bcsub($custom->balance, $amount, 2);
-        $custom->balance = $lastBalance;
+        $customBalance = bcsub($custom->balance, $amount, 2);
+        $custom->balance = $customBalance;
         if ($custom->balance < 0) {
             $custom->isDebt = 1;
         }
         $custom->save();
 
-        $remain = bcsub($hd->balance, $amount, 2);
-        $hd->balance = $remain;
+        $hdBalance = bcsub($hd->balance, $amount, 2);
+        $hd->balance = $hdBalance;
         if ($hd->balance < 0) {
             $hd->debt = 2;
         }
         $hd->save();
 
+        if (floatval($customBalance) != floatval($hdBalance)) {
+            util::fail('余额有错,请联系管理员,编号' . $hdId);
+        }
+
         $relateId = $order->id ?? 0;
         $customId = $custom->id ?? 0;
         $orderSn = $order->orderSn ?? '';
@@ -218,14 +222,14 @@ class CustomClass extends BaseClass
             'onlinePay' => $onlinePay,
             'capitalType' => $capitalType,
             'amount' => $amount,
-            'balance' => $lastBalance,
+            'balance' => $customBalance,
             'io' => 0,
             'side' => $side,
             'payWay' => $payWay,
             'event' => $event,
             'staffId' => $staffId,
             'staffName' => $staffName,
-            'shopId' => $order->id,
+            'shopId' => $shopId,
             'mainId' => $order->mainId,
             'settleId' => $settleId,
             'settleNo' => $settleNo,
@@ -235,122 +239,70 @@ class CustomClass extends BaseClass
         BalanceChangeClass::add($change, true);
     }
 
-    //散客申请退款,零售门店欠款金额减少
+    //欠款和余额支付的售后 ssh 20250803
     public static function refundDebtAmountReduce($custom, $amount, $refund)
     {
-        $debtAmount = $custom->debtAmount ?? 0.00;
-        $remain = bcsub($debtAmount, $amount, 2);
-        if ($remain < 0) {
-            noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次退款金额:{$amount} 客户ID:{$custom->id} 超出了,编号66379", '15280215347');
-            util::fail('操作失败,欠款金额会出现负数');
-        }
-        $custom->isDebt = $remain <= 0 ? 0 : 1;
-        $custom->debtAmount = $remain;
-        $custom->save();
-        $relateId = $refund->id ?? 0;
-        $customId = $custom->id ?? 0;
-        $capitalType = dict::getDict('capitalType', 'hdRefund', 'id');
-        $refundSn = $refund->refundSn ?? '';
-
-        $change = [
-            'relateId' => $relateId,
-            'customId' => $customId,
-            'ptStyle' => dict::getDict('ptStyle', 'hd'),
-            'capitalType' => $capitalType,
-            'amount' => $amount,
-            'balance' => $remain,
-            'io' => 0,
-            'payWay' => 0,
-            'event' => "客户申请退款,退款单号:{$refundSn}",
-            'sjId' => $refund->sjId ?? 0,
-            'shopId' => $refund->shopId ?? 0,
-            'mainId' => $refund->mainId ?? 0,
-        ];
-        CustomDebtRecordClass::addChange($change);
-
-        $mainId = $refund->mainId ?? 0;
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有main信息39');
+        $hdId = $custom->hdId ?? 0;
+        $hd = HdClass::getLockById($hdId);
+        if (empty($hd)) {
+            util::fail('花店信息缺失,编号520');
         }
-        $debt = $main->debt ?? 0;
-        $totalRemain = bcsub($debt, $amount, 2);
-        $main->debt = $totalRemain;
-        $main->save();
-
-        $event = $custom->name . "申请退款,退款单号:{$refundSn}";
-        $change['balance'] = $totalRemain;
-        $change['event'] = $event;
-        TotalDebtChangeClass::addChange($change);
-    }
 
-    //客户结账欠款金额减少 ssh 20250627
-    public static function clearDebtAmountReduce($custom, $amount, $clear)
-    {
-        $balance = $custom->balance ?? 0.00;
-        $remainBalance = bcsub($balance, $amount, 2);
-        if ($remainBalance < 0) {
-            noticeUtil::push("零售客户欠款总金额:{$balance} 本次结账金额:{$amount} 客户ID:{$custom->id} 超出了,编号788965", '15280215347');
-            util::fail('操作失败,结账后欠款金额会出现负数');
+        $customBalance = bcadd($custom->balance, $amount, 2);
+        $custom->balance = $customBalance;
+        if ($custom->balance < 0) {
+            $custom->isDebt = 1;
         }
-        $custom->balance = $remainBalance;
         $custom->save();
 
-        $hdId = $custom->hdId ?? 0;
-        $hd = HdClass::getLockById($hdId);
-        if (empty($hd)) {
-            util::fail('店铺信息异常');
+        $hdBalance = bcadd($hd->balance, $amount, 2);
+        $hd->balance = $hdBalance;
+        if ($hd->balance < 0) {
+            $hd->debt = 2;
         }
-        $hdName = $hd->name ?? '';
-        $hdBalance = $hd->balance ?? 0;
-        $hdRemainBalance = bcsub($hdBalance, $amount, 2);
-        $hd->balance = $hdRemainBalance;
         $hd->save();
 
-        if (floatval($hdRemainBalance) != floatval($remainBalance)) {
-            util::fail('余额有问题');
+        if (floatval($customBalance) !== floatval($hdBalance)) {
+            util::fail('余额错误,请联系管理员,编号' . $hdId);
         }
 
-        $relateId = $clear->id ?? 0;
+        $relateId = $refund->id ?? 0;
         $customId = $custom->id ?? 0;
-        $capitalType = dict::getDict('capitalType', 'hdXsClear', 'id');
-        $orderSn = $clear->orderSn ?? '';
+        $refundSn = $refund->refundSn ?? '';
+        $orderSn = $refund->orderSn ?? '';
+        $orderId = $refund->orderId ?? 0;
+        $staffId = $refund->shopAdminId ?? 0;
+        $staffName = $refund->shopAdminName ?? '';
+        $capitalType = dict::getDict('capitalType', 'hdRefund', 'id');
+        $event = "订单售后 " . $refundSn;
         $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;
+        $onlinePay = 1;
+        $side = 0;
+        $payWay = 2;//余额支付
         $change = [
             'customId' => $customId,
             'customName' => $customName,
-            'hdId' => $hdId,
-            'hdName' => $hdName,
             'relateId' => $relateId,
-            'onlinePay' => 1,
+            'relateSn' => $refundSn,
+            'onlinePay' => $onlinePay,
             'capitalType' => $capitalType,
             'amount' => $amount,
-            'balance' => $hdRemainBalance,
-            'io' => 0,
-            'side' => 0,
+            'balance' => $customBalance,
+            'io' => 1,
+            'side' => $side,
             'payWay' => $payWay,
             'event' => $event,
             'staffId' => $staffId,
             'staffName' => $staffName,
-            'shopId' => $shopId,
-            'mainId' => $mainId,
-            'remark' => $remark,
+            'shopId' => $refund->shopId,
+            'mainId' => $refund->mainId,
+            'refundOrderId' => $orderId,
+            'refundOrderSn' => $orderSn,
+            'remark' => '',
         ];
         BalanceChangeClass::add($change, true);
     }
 
-    public static function getCustomCacheKey($sjId, $shopId, $userId)
-    {
-        return 'hd_custom_key_' . $sjId . '_' . $shopId . '_' . $userId;
-    }
-
     //添加客户 ssh 2021.2.28
     public static function addCustom($data)
     {
@@ -486,19 +438,4 @@ class CustomClass extends BaseClass
         return $list;
     }
 
-    //更新客户信息 ssh 2021.3.23
-    public static function updateCustomInfo($custom, $data)
-    {
-        $userId = $custom['userId'];
-        $userData = [];
-        if (!empty($data['mobile'])) {
-            $userData['mobile'] = $data['mobile'];
-        }
-        if (!empty($userData)) {
-            UserClass::updateById($userId, $userData);
-        }
-        $id = $custom['id'];
-        self::updateById($id, $data);
-    }
-
 }

+ 10 - 8
biz-hd/refund/services/HdRefundService.php

@@ -268,7 +268,7 @@ class HdRefundService extends BaseService
                     'refundReason' => $refundReason,
                 ];
                 $response = $laResource->refund($aliParams);
-                if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
+                if (!isset($response['code']) || $response['code'] != 'BBS00000') {
                     $errMsg = $response['msg'] ?? '';
                     noticeUtil::push('退款失败' . $errMsg, '15280215347');
                     util::fail('退款失败');
@@ -278,28 +278,26 @@ class HdRefundService extends BaseService
                 $refund->save();
             }
         } else {
-
-            //客户欠款金额减少
             $customId = $order->customId ?? 0;
             $custom = CustomClass::getLockById($customId);
             if (empty($custom)) {
                 util::fail('没有找到客户');
             }
-
             if ($payWay == dict::getDict('payWay', 'debtPay')) {
-
+                //如果欠款支付,减掉欠款,其实就是增加余额
                 $currentRemain = bcsub($order->remainDebtPrice, $refundPrice, 2);
+                if ($currentRemain < 0) {
+                    util::fail('剩余欠款不足售后金额');
+                }
                 $order->remainDebtPrice = $currentRemain;
                 if ($currentRemain <= 0) {
                     $order->debt = 0;
                 }
                 $order->save();
-
                 CustomClass::refundDebtAmountReduce($custom, $refundPrice, $refund);
-
             }
-
             if ($payWay == dict::getDict('payWay', 'cash')) {
+                //如果现金支付
                 $moneyData = [
                     'shopId' => $shopId,
                     'amount' => $refundPrice,
@@ -308,6 +306,10 @@ class HdRefundService extends BaseService
                 ];
                 ShopMoneyClass::hdRefundSkOutAmount($moneyData, $main);
             }
+            if ($payWay == dict::getDict('payWay', 'balancePay')) {
+                //如果是余额支付,客户的余额要增加
+                CustomClass::refundDebtAmountReduce($custom, $refundPrice, $refund);
+            }
         }
         return $refund;
     }

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

@@ -62,6 +62,19 @@ class OrderClass extends BaseClass
     public static function getDebtList($where)
     {
         $list = self::getAllList('*', $where, 'addTime DESC');
+
+        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);
+            }
+        }
+
         $count = self::getCount($where);
         return ['list' => $list, 'debtNum' => $count];
     }