WIN-2308041133\Administrator 3 месяцев назад
Родитель
Сommit
9d2ff8a8a8
1 измененных файлов с 30 добавлено и 29 удалено
  1. 30 29
      app/services/order/StoreOrderComputedServices.php

+ 30 - 29
app/services/order/StoreOrderComputedServices.php

@@ -334,6 +334,35 @@ class StoreOrderComputedServices extends BaseServices
         @file_put_contents("quanju.txt", $repeatDiscount."使用复购折扣\r\n", 8);
         @file_put_contents("quanju.txt", $hasRepeat."使用复购折扣了吗\r\n", 8);
 
+        // 先判断永久复购折扣(分销等级level_discount=1)
+        if ($hasRepeat && $userInfo && isset($userInfo['agent_level']) && $userInfo['agent_level'] > 0) {
+            $agentLevel = app()->make(AgentLevelServices::class);
+            $level_discount = $agentLevel->value(['id' => $userInfo['agent_level'], 'is_del' => 0], 'level_discount');
+
+            if ($level_discount == 1) {
+                // 计算有多少个50元
+                $units = intval(bcdiv((string)$payPrice, '50', 0));
+                @file_put_contents("quanju.txt", json_encode(['永久复购折扣','payPrice'=>$payPrice,'units'=>$units])."-永久复购折扣计算\r\n", 8);
+
+                if ($units > 0) {
+                    // 每满50元减免20元(永久折扣不消耗次数)
+                    $discountAmount = bcmul((string)$units, '20', 2);
+                    $payPrice = bcsub((string)$payPrice, $discountAmount, 2);
+                    // 确保价格不低于0.01
+                    $payPrice = $payPrice < 0.01 ? '0.01' : $payPrice;
+
+                    // 将复购折扣金额累加到deductionPrice
+                    $deductionPrice = bcadd((string)$deductionPrice, $discountAmount, 2);
+
+                    @file_put_contents("quanju.txt", json_encode(['units'=>$units,'discountAmount'=>$discountAmount,'payPrice'=>$payPrice,'deductionPrice'=>$deductionPrice])."-永久复购折扣计算结果\r\n", 8);
+
+                    // 永久复购折扣不消耗次数
+                    return [$payPrice, $deductionPrice, 0, isset($userInfo['repeat_discount_num']) ? (int)$userInfo['repeat_discount_num'] : 0];
+                }
+            }
+        }
+
+        // 如果没有永久复购折扣,则使用复购折扣次数
         if ($repeatDiscount > 0 && $hasRepeat) {
 //            @file_put_contents("quanju.txt", "使用复购折扣\r\n", 8);
             // 计算有多少个50元
@@ -366,35 +395,7 @@ class StoreOrderComputedServices extends BaseServices
                 }
             }
         }
-//        else {
-//            // 检查永久复购折扣(分销等级level_discount=1)
-//            if ($hasRepeat && $userInfo && isset($userInfo['agent_level']) && $userInfo['agent_level'] > 0) {
-//                $agentLevel = app()->make(AgentLevelServices::class);
-//                $level_discount = $agentLevel->value(['id' => $userInfo['agent_level'], 'is_del' => 0], 'level_discount');
-//
-//                if ($level_discount == 1) {
-//                    // 计算有多少个50元
-//                    $units = intval(bcdiv((string)$payPrice, '50', 0));
-//                    @file_put_contents("quanju.txt", json_encode(['永久复购折扣','payPrice'=>$payPrice,'units'=>$units])."-永久复购折扣计算\r\n", 8);
-//
-//                    if ($units > 0) {
-//                        // 每满50元减免20元(永久折扣不消耗次数)
-//                        $discountAmount = bcmul((string)$units, '20', 2);
-//                        $payPrice = bcsub((string)$payPrice, $discountAmount, 2);
-//                        // 确保价格不低于0.01
-//                        $payPrice = $payPrice < 0.01 ? '0.01' : $payPrice;
-//
-//                        // 将复购折扣金额累加到deductionPrice
-//                        $deductionPrice = bcadd((string)$deductionPrice, $discountAmount, 2);
-//
-//                        @file_put_contents("quanju.txt", json_encode(['units'=>$units,'discountAmount'=>$discountAmount,'payPrice'=>$payPrice,'deductionPrice'=>$deductionPrice])."-永久复购折扣计算结果\r\n", 8);
-//
-//                        // 永久复购折扣不消耗次数
-//                        return [$payPrice, $deductionPrice, 0, isset($userInfo['repeat_discount_num']) ? (int)$userInfo['repeat_discount_num'] : 0];
-//                    }
-//                }
-//            }
-//        }
+
         // 不使用复购折扣或不符合条件
         return [$payPrice, $deductionPrice, 0, 0];
     }