Ver código fonte

```
feat(profits): 添加执行分红功能- 在 `route/admin.php` 中添加了执行分红的路由。- 新增 `ExecuteProfitRequestEntity` 请求实体类,用于处理执行分红请求的数据。- 新增 `ExecuteProfitValidate` 验证器,用于验证执行分红请求的数据。
- 新增 `OldUserLog` 模型类,用于记录用户余额日志。
- 新增 `OldUserLogDao` 数据访问对象,用于操作 `OldUserLog` 模型。
- 新增 `OldUserLogEnum` 枚举类,定义了金额类型。
- 在 `ProfitsRepository` 中新增 `executeProfit` 方法,用于执行分红逻辑,并记录用户余额日志。
- 在 `ShareProfits` 控制器中新增 `executeProfit` 方法,用于处理执行分红的请求。
-修复了 `Pv` 类中的代码格式问题。- 修改了队列配置,默认使用 Redis作为队列驱动。
```

shichen 10 meses atrás
pai
commit
24a390a6bb

+ 14 - 0
app/common/dao/log/OldUserLogDao.php

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace app\common\dao\log;
4
+
5
+use app\common\dao\BaseDao;
6
+use app\common\model\log\OldUserLog;
7
+
8
+class OldUserLogDao extends BaseDao
9
+{
10
+    protected function getModel(): string
11
+    {
12
+        return OldUserLog::class;
13
+    }
14
+}

+ 20 - 0
app/common/enum/log/OldUserLogEnum.php

@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+namespace app\common\enum\log;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class OldUserLogEnum extends CommonEnum
8
+{
9
+    // 金额类型:1=PV,2=GB(钢镚),3=冻积分(DF),4代金券(VR),5补贴金(BT),6=提现额度,7=养老金,8,佣金
10
+    const TYPE = [
11
+        'PV' => ['code' => 1, 'name' => 'PV'],
12
+        'GB' => ['code' => 2, 'name' => 'GB(钢镚)'],
13
+        'DF' => ['code' => 3, 'name' => '冻积分(DF)'],
14
+        'VR' => ['code' => 4, 'name' => '代金券(VR)'],
15
+        'BT' => ['code' => 5, 'name' => '补贴金(BT)'],
16
+        'TX' => ['code' => 6, 'name' => '提现额度'],
17
+        'YL' => ['code' => 7, 'name' => '养老金'],
18
+        'YJ' => ['code' => 8, 'name' => '佣金']
19
+    ];
20
+}

+ 21 - 0
app/common/model/log/OldUserLog.php

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace app\common\model\log;
4
+
5
+use app\common\model\BaseModel;
6
+
7
+/**
8
+ * 用户余额记录表
9
+ */
10
+class OldUserLog extends BaseModel
11
+{
12
+    public static function tablePk(): ?string
13
+    {
14
+        return 'id';
15
+    }
16
+
17
+    public static function tableName(): string
18
+    {
19
+        return 'old_user_log';
20
+    }
21
+}

+ 140 - 1
app/common/repositories/profits/ProfitsRepository.php

@@ -7,7 +7,9 @@ use app\common\dao\profit\ZeroUserProfitDao;
7 7
 use app\common\dao\user\UserDao;
8 8
 use app\common\dao\user\ZeroUserLineDao;
9 9
 use app\common\enum\user\ZeroUserEnum;
10
+use app\common\model\log\OldUserLog;
10 11
 use app\common\model\profit\ZeroUserProfitsDetail;
12
+use app\common\model\user\User;
11 13
 use app\common\utils\QueueLogger;
12 14
 use app\jobs\ZeroUserProfits;
13 15
 use think\db\exception\DataNotFoundException;
@@ -142,7 +144,7 @@ class ProfitsRepository
142 144
                 unset($groupData);
143 145
                 $groupData = $this->getUserByGroup($userIds, $key);
144 146
                 if (empty($groupData)) {
145
-                    QueueLogger::info('0号线合伙人分红:0号线用户:'.$param['zeroUserId'].',暂无'.$key.'级别用户' );
147
+                    QueueLogger::info('0号线合伙人分红:0号线用户:' . $param['zeroUserId'] . ',暂无' . $key . '级别用户');
146 148
                     continue;
147 149
                 }
148 150
                 // 获取初中高用户直推和团队业绩
@@ -363,4 +365,141 @@ class ProfitsRepository
363 365
         }
364 366
         return true;
365 367
     }
368
+
369
+    // 执行分红
370
+    public function executeProfit($param)
371
+    {
372
+        $detailDao = new ZeroUserProfitsDetail();
373
+        // 获取分红信息
374
+        $list = $detailDao->where('zero_user_profit_id', $param['zeroUserProfitId'])->select()->toArray();
375
+        if (empty($list)) {
376
+            return [];
377
+        }
378
+
379
+
380
+        // $userIds = array_column($list, 'user_id');
381
+        //
382
+        // $userList = User::select($userIds);
383
+
384
+
385
+        // dd($list);
386
+
387
+        foreach ($list as $key => $value) {
388
+
389
+            $allAward = bcadd($value['min_count'], $value['max_count']);
390
+            //90%给佣金,10给复购金
391
+            $yj_90 = floor($allAward * 0.9 * 100) / 100;
392
+            $fg_10 = floor($allAward * 0.1 * 100) / 100;
393
+
394
+            $userModel = $this->userDao->get($value['user_id']);
395
+            $userModel->total_amount_old = $userModel->total_amount_old + $yj_90;
396
+            $userModel->amount_old = $userModel->amount_old + $yj_90;
397
+            $userModel->brokerage_price = $userModel->brokerage_price + $yj_90;
398
+            $userModel->fugou = $userModel->fugou + $fg_10;
399
+            $userModel->save();
400
+        }
401
+
402
+
403
+        die;
404
+
405
+        // 插入执行分红队列
406
+        // foreach ($userList as $value) {
407
+        //     $value->amount_old = Db::raw('amount_old + 1');
408
+        //     $value->save();
409
+        // }
410
+
411
+        $update = [];
412
+        foreach ($userList as $value) {
413
+            $amountOld = $value->amount_old + 1;
414
+            $update[] = [
415
+                'uid' => $value->uid,
416
+                'amount_old' => $amountOld
417
+            ];
418
+        }
419
+        $this->userDao->saveAll($update);
420
+        die;
421
+    }
422
+
423
+    /**
424
+     * @param $userId
425
+     * @param $type
426
+     * @param $changeStatus
427
+     * @param $money
428
+     * @param $routineLogOfKeyId
429
+     * @param $remark
430
+     * @param $isAdmin
431
+     * @param $createTime
432
+     * @param $alterMoney
433
+     * @return int|string
434
+     * @author 史晨
435
+     * @date 2025/9/18 14:16
436
+     * 记录用户余额日志
437
+     */
438
+    private function recordOldUserLog($userId, $type, $changeStatus, $money, $routineLogOfKeyId, $remark = "", $isAdmin = 1, $alterMoney = 0)
439
+    {
440
+        $insertData = [
441
+            'user_id' => $userId,
442
+            'type' => $type,
443
+            'change_status' => $changeStatus,
444
+            'money' => $money,
445
+            'routine_log_of_key_id' => $routineLogOfKeyId,
446
+            'remark' => $remark,
447
+            'is_admin' => $isAdmin,
448
+            'create_time' => time(),
449
+            'alter_money' => $alterMoney
450
+        ];
451
+        $dao = new OldUserLog();
452
+        return $dao->insert($insertData);
453
+    }
454
+
455
+    private function recordUserBillLog()
456
+    {
457
+        $bill = [
458
+            'uid' => $uid,
459
+            'link_id' => 0,//关联订单id
460
+            'pm' => 1,//0:支出,1:获得
461
+            'title' => $name,//账单标题
462
+            'category' => 'now_money',//明细种类
463
+            'type' => 'commission',//明细类型
464
+            'number' => $num,//明细数字
465
+            'balance' => 0,//剩余
466
+            'mark' => $mark,//备注
467
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
468
+            'status' => 1,//0待确定,1有效,-1无效
469
+            'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
470
+            //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
471
+            //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
472
+            'order_sn' => 0,//订单号
473
+            'tripartite' => 0,//
474
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
475
+            'mer_id' => 0,//商户id
476
+            'source' => 0,//1线下 0线上
477
+            'order_type' => 1,//1自营  2 第三方  订单类型
478
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
479
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
480
+            'take_time' => time(),//结算时间
481
+            'district_id' => '',//
482
+            'street_id' => '',//
483
+            'month' => '',//月份
484
+
485
+
486
+        ];
487
+    }
488
+
489
+    private function fugouUserLog()
490
+    {
491
+        $bill = [
492
+            'uid' => $uid,
493
+            'number' => $num,//数量
494
+            'status' => $status,//复购金状态1-有效 0-失效 -1待确认
495
+            'mark' => "复购金",//备注
496
+            'desc' => "10%复购金",//描述
497
+            'order_id' => $order_id,//订单id
498
+            'surplus' => 0,//剩余
499
+            'order_type' => 11,//关联订单ID
500
+            'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
501
+            'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
502
+            'addtime' => time(),
503
+        ];
504
+    }
366 505
 }

+ 2 - 2
app/common/utils/Pv.php

@@ -32,7 +32,7 @@ class Pv
32 32
         StoreOrderEnum::STATUS['WAITING_RECEIVE']['code'],
33 33
         StoreOrderEnum::STATUS['WAITING_EVALUATION']['code'],
34 34
         StoreOrderEnum::STATUS['COMPLETED']['code']
35
-        ];
35
+    ];
36 36
 
37 37
     /**
38 38
      * 需要排除的测试用户ID列表
@@ -84,7 +84,7 @@ class Pv
84 84
      */
85 85
     public function getPvConfig(): array
86 86
     {
87
-        return  $this->pvDao->getData();
87
+        return $this->pvDao->getData();
88 88
     }
89 89
 
90 90
     /**

+ 11 - 8
app/controller/admin/profits/ShareProfits.php

@@ -5,8 +5,10 @@ namespace app\controller\admin\profits;
5 5
 use app\common\repositories\profits\ProfitsRepository;
6 6
 use app\common\utils\Pv;
7 7
 use app\controller\admin\BaseController;
8
+use app\entity\admin\request\profits\ExecuteProfitRequestEntity;
8 9
 use app\entity\admin\request\profits\PartnerProfitsRequestEntity;
9 10
 use app\entity\admin\response\profits\ZeroUserProfitResponseEntity;
11
+use app\validate\admin\profits\ExecuteProfitValidate;
10 12
 use app\validate\admin\profits\PartnerProfitsValidate;
11 13
 
12 14
 class ShareProfits extends BaseController
@@ -33,15 +35,9 @@ class ShareProfits extends BaseController
33 35
      */
34 36
     public function partnerProfits(PartnerProfitsValidate $validate)
35 37
     {
36
-
37
-        $a = new Pv();
38
-        $a->countPv();
39
-        die;
40
-
41
-
42 38
         $validationResult = $this->validateRequest($validate, PartnerProfitsRequestEntity::class);
43
-        $res = $this->repository->getZeroUser($validationResult->toArray());
44
-        // $res = $this->repository->profits($validationResult->toArray());
39
+        // $res = $this->repository->getZeroUser($validationResult->toArray());
40
+        $res = $this->repository->profits($validationResult->toArray());
45 41
         if (is_string($res)) {
46 42
             $response = ZeroUserProfitResponseEntity::error($res);
47 43
             return app('json')->fail($response->toResponseArray());
@@ -49,4 +45,11 @@ class ShareProfits extends BaseController
49 45
         $response = ZeroUserProfitResponseEntity::success();
50 46
         return app('json')->success($response->toResponseArray());
51 47
     }
48
+
49
+    // 执行分红
50
+    public function executeProfit(ExecuteProfitValidate $validate)
51
+    {
52
+        $validationResult = $this->validateRequest($validate, ExecuteProfitRequestEntity::class);
53
+        $this->repository->executeProfit($validationResult->toArray());
54
+    }
52 55
 }

+ 25 - 0
app/entity/admin/request/profits/ExecuteProfitRequestEntity.php

@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+namespace app\entity\admin\request\profits;
4
+
5
+use app\entity\CommonEntity;
6
+
7
+class ExecuteProfitRequestEntity extends CommonEntity
8
+{
9
+    // 0号线分红日志id
10
+    public $zeroUserProfitId;
11
+
12
+
13
+    public function getZeroUserProfitId()
14
+    {
15
+        return $this->zeroUserProfitId;
16
+    }
17
+
18
+
19
+    public function setZeroUserProfitId($zeroUserProfitId): ExecuteProfitRequestEntity
20
+    {
21
+
22
+        $this->zeroUserProfitId = $zeroUserProfitId;
23
+        return $this;
24
+    }
25
+}

+ 18 - 0
app/validate/admin/profits/ExecuteProfitValidate.php

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace app\validate\admin\profits;
4
+
5
+use app\validate\CommonValidate;
6
+
7
+class ExecuteProfitValidate extends CommonValidate
8
+{
9
+    protected $failException = true;
10
+
11
+    protected $rule = [
12
+        'zero_user_profit_id|日志id' => 'require',
13
+    ];
14
+
15
+    protected $message = [
16
+        'zero_user_profit_id.int' => '日志id类型错误',
17
+    ];
18
+}

+ 1 - 1
config/queue.php

@@ -10,7 +10,7 @@
10 10
 // +----------------------------------------------------------------------
11 11
 
12 12
 return [
13
-    'default'     => 'database',
13
+    'default'     => 'redis',
14 14
     'connections' => [
15 15
         'sync'     => [
16 16
             'type' => 'sync',

+ 2 - 0
route/admin.php

@@ -481,6 +481,8 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
481 481
         Route::group('shareProfits', function () {
482 482
             // 合伙人分红
483 483
             Route::post('partnerProfits', '/partnerProfits')->name('partnerProfits');
484
+            // 执行分红
485
+            Route::post('executeProfit', '/executeProfit')->name('executeProfit');
484 486
         })->prefix('admin.profits.ShareProfits');
485 487
 
486 488