Просмотр исходного кода

Merge branch 'zhongqi-optimize' into dev

shizhongqi 3 месяцев назад
Родитель
Сommit
f958fdcc91
1 измененных файлов с 41 добавлено и 34 удалено
  1. 41 34
      biz-hd/recharge/classes/RechargeClass.php

+ 41 - 34
biz-hd/recharge/classes/RechargeClass.php

@@ -266,15 +266,20 @@ class RechargeClass extends BaseClass
             $hd->balanceGive = bcadd($hd->balanceGive, $balanceGive, 2);
         }
         //充值的余额
+        $beforeBalancePay = $custom->balancePay;
         $custom->balancePay = bcadd($custom->balancePay, $balancePay, 2);
         $hd->balancePay = bcadd($hd->balancePay, $balancePay, 2);
         //总余额
         $totalBalance = bcadd($balancePay, $balanceGive, 2);
         $custom->balance = bcadd($custom->balance, $totalBalance, 2);
         $hd->balance = bcadd($hd->balance, $totalBalance, 2);
-        //积分与成长值
-        $custom->integral = bcadd($custom->integral, $balancePay);
-        $custom->growth = bcadd($custom->growth, $balancePay);
+        $changeAmount = bccomp($beforeBalancePay, 0, 2) === -1 ? $custom->balancePay : $balancePay;  // 根据余额欠款,计算变化金额,用于计算积分与成长值
+        $addIntegralAndGrowth = bccomp($changeAmount, 0, 2) === 1; // 如果变化金额大于0,则计算积分与成长值
+        if ($addIntegralAndGrowth) {
+            //积分与成长值
+            $custom->integral = bcadd($custom->integral, $changeAmount);
+            $custom->growth = bcadd($custom->growth, $changeAmount);
+        }
         $custom->save();
         $hd->save();
 
@@ -470,38 +475,40 @@ class RechargeClass extends BaseClass
             }
         }
 
-        $createTime = date('Y-m-d H:i:s');
-        //成长值变动记录
-        $growthData = [
-            'shopId' => $shopId,
-            'userId' => $custom->userId,
-            'userName' => $custom->name,
-            'event' => $event,
-            'relateId' => $relateId,
-            'relateType' => 0,
-            'num' => $balancePay,
-            'growth' => $custom->growth,
-            'staffId' => $staffId, //操作人(员工id)
-            'staffName' => $staffName, //员工名称
-            'createTime' => $createTime,
-        ];
-        UserGrowthClass::add($growthData);
+        if ($addIntegralAndGrowth) {
+            $createTime = date('Y-m-d H:i:s');
+            //成长值变动记录
+            $growthData = [
+                'shopId' => $shopId,
+                'userId' => $custom->userId,
+                'userName' => $custom->name,
+                'event' => $event,
+                'relateId' => $relateId,
+                'relateType' => 0,
+                'num' => $changeAmount,
+                'growth' => $custom->growth,
+                'staffId' => $staffId, //操作人(员工id)
+                'staffName' => $staffName, //员工名称
+                'createTime' => $createTime,
+            ];
+            UserGrowthClass::add($growthData);
 
-        //积分变动记录
-        $integralData = [
-            'shopId' => $shopId,
-            'userId' => $custom->userId,
-            'userName' => $custom->name,
-            'event' => $event,
-            'relateId' => $relateId,
-            'relateType' => 0,
-            'num' => $balancePay,
-            'integral' => $custom->integral,
-            'staffId' => $staffId, //操作人(员工id)
-            'staffName' => $staffName, //员工名称
-            'createTime' => $createTime,
-        ];
-        UserIntegralClass::add($integralData);
+            //积分变动记录
+            $integralData = [
+                'shopId' => $shopId,
+                'userId' => $custom->userId,
+                'userName' => $custom->name,
+                'event' => $event,
+                'relateId' => $relateId,
+                'relateType' => 0,
+                'num' => $changeAmount,
+                'integral' => $custom->integral,
+                'staffId' => $staffId, //操作人(员工id)
+                'staffName' => $staffName, //员工名称
+                'createTime' => $createTime,
+            ];
+            UserIntegralClass::add($integralData);
+        }
 
         return $returnChange;
     }