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

feat(admin): 添加分红积分基准价格设置并进行有效性验证

- 在系统配置中添加"award_integral_price"字段,用于设置分红积分基准价格
- 添加对分红积分基准价格的验证,确保其值大于 0
- 优化了代码格式,调整了数组元素的缩进
kirin 5 месяцев назад
Родитель
Сommit
31f9b5d813

+ 1 - 0
app/common/repositories/user/UserBillRepository.php

@@ -39,6 +39,7 @@ class UserBillRepository extends BaseRepository
     const TYPE_INFO = [
         'brokerage' => [
             'brokerage/now_money' => '佣金转入余额',
+            'brokerage/extract_award' => '提取分红积分',
             'brokerage/order_one' => '获得一级推广佣金',
             'brokerage/order_two' => '获得二级推广佣金',
             'brokerage/refund_one' => '退还一级佣金',

+ 59 - 2
app/common/repositories/user/UserRepository.php

@@ -2693,8 +2693,65 @@ class UserRepository extends BaseRepository
         }
     }
 
-    public function extractIntegral($uid)
+    /**
+     * 提取分红积分
+     * @param $uid
+     * @param $num
+     * @return true
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function extractIntegral($uid, $num = 0)
     {
-        
+        $info = $this->dao->get($uid);
+        if ($num == 0) $num = $info['award_integral'];
+        if ($num > 0) {
+            // 实例化用户账单仓库,用于处理用户账单相关操作。
+            $userBillRepository = app()->make(UserBillRepository::class);
+            $price = $this->awardIntegralPrice();
+            $all_price = bcmul($num, $price['price']);
+            if ($all_price > $info['award_range']) $all_price = $info['award_range'];
+
+            if ($all_price > 0) {
+                //用户获得$all_price的佣金
+                $userBillRepository->incBill($uid, 'brokerage', 'extract_award', [
+                    'link_id' => 0,
+                    'status' => 1,
+                    'title' => '提取分红积分',
+                    'number' => $all_price,
+                    'mark' => $info['nickname'] . '提取' . floatval($num) . '分红积分为' . floatval($all_price) . '佣金(分红积分价格:' . $price['price'] . ')',
+                    'balance' => bcadd($info['brokerage_price'], $all_price, 2)
+                ]);
+                $userRepository = app()->make(UserRepository::class);
+                $userRepository->incBrokerage($uid, $all_price);
+                $userRepository->incField($uid, 'brokerage_price', $all_price);
+                //用户失去$all_price的收益额度
+                $userBillRepository->decBill($uid, 'award_range', 'extract_award', [
+                    'link_id' => 0,
+                    'status' => 1,
+                    'title' => '提取分红积分',
+                    'number' => $all_price,
+                    'mark' => $info['nickname'] . '提取分红积分为佣金,减少分红额度',
+                    'balance' => bcsub($info['award_range'], $all_price, 2)
+                ]);
+                $userRepository->decField($uid, 'award_range', $all_price);
+                if ($info['award_range'] == $all_price) {
+                    $num = $info['award_integral'];
+                }
+                //若用户失去所有收益额度,清空用户的分红积分
+                $userBillRepository->decBill($uid, 'award_integral', 'extract_award', [
+                    'link_id' => 0,
+                    'status' => 1,
+                    'title' => '提取分红积分',
+                    'number' => $num,
+                    'mark' => $info['nickname'] . '提取' . floatval($num) . '分红积分',
+                    'balance' => bcsub($info['award_integral'], $num, 2)
+                ]);
+                $userRepository->decField($uid, 'award_integral', $num);
+            }
+
+        }
+        return true;
     }
 }