Procházet zdrojové kódy

共富体系-增加用户升级功能

sunxbiao před 5 měsíci
rodič
revize
ce93b0b4ac

+ 1 - 1
app/common/dao/shared/SharedProsperityRecommendConfigDao.php

@@ -15,7 +15,7 @@ class SharedProsperityRecommendConfigDao extends BaseDao
15 15
     }
16 16
 
17 17
     /**
18
-     * @return array
18
+     * @return SharedProsperityRecommendConfigEntity[]
19 19
      * @author 史晨
20 20
      * @date 2026/2/5 14:43
21 21
      * 获取推荐配置

+ 1 - 1
app/common/repositories/shared/SharedProsperityRecommendConfigRepository.php

@@ -38,7 +38,7 @@ class SharedProsperityRecommendConfigRepository extends BaseRepository
38 38
     }
39 39
 
40 40
     /**
41
-     * @return array
41
+     * @return SharedProsperityRecommendConfigEntity[]
42 42
      * @author 史晨
43 43
      * @date 2026/2/5 14:12
44 44
      */

+ 36 - 0
app/common/repositories/shared/SharedProsperityUserRepository.php

@@ -5,6 +5,7 @@ namespace app\common\repositories\shared;
5 5
 use app\common\dao\shared\SharedProsperityUserDao;
6 6
 use app\common\dao\user\UserDao;
7 7
 use app\common\repositories\BaseRepository;
8
+use app\entity\data\shared\SharedProsperityRecommendConfigEntity;
8 9
 use app\entity\data\shared\SharedProsperityUserEntity;
9 10
 use think\db\exception\DbException;
10 11
 
@@ -245,4 +246,39 @@ class SharedProsperityUserRepository extends BaseRepository
245 246
     {
246 247
         return $this->dao->saveAll($dataList);
247 248
     }
249
+
250
+    /**
251
+     * 用户身份升级
252
+     * @param array $userIdList
253
+     * @return void
254
+     */
255
+    public function identityUpgrade(array $userIdList)
256
+    {
257
+        $sharedProsperityUserEntityList = $this->getSharedProsperityUserEntityListByUserIdList($userIdList);
258
+
259
+        /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
260
+        $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
261
+        $sharedProsperityRecommendConfigEntityList = $sharedProsperityRecommendConfigRepository->getList();
262
+        usort($sharedProsperityRecommendConfigEntityList, function (SharedProsperityRecommendConfigEntity $a, SharedProsperityRecommendConfigEntity $b) {
263
+            return $a->getPv() <=> $b->getPv();  // 从小到大排序
264
+        });
265
+        foreach ($sharedProsperityUserEntityList as $sharedProsperityUserEntity) {
266
+            $partnerLevel = 0;
267
+            foreach ($sharedProsperityRecommendConfigEntityList as $sharedProsperityRecommendConfigEntity) {
268
+                if ($sharedProsperityUserEntity->getPv() >= $sharedProsperityRecommendConfigEntity->getPv()) {
269
+                    $partnerLevel = $sharedProsperityRecommendConfigEntity->getLevel();
270
+                } else {
271
+                    // 如果本次验证的等级结果大于 之前的等级,说明用户升级了 需要更新等级
272
+                    if ($partnerLevel > $sharedProsperityUserEntity->getPartnerLevel()) {
273
+                        $this->updateByEntity(
274
+                            SharedProsperityUserEntity::newInstance()
275
+                                ->setId($sharedProsperityUserEntity->getId())
276
+                                ->setPartnerLevel($partnerLevel)
277
+                        );
278
+                    }
279
+                    break;
280
+                }
281
+            }
282
+        }
283
+    }
248 284
 }

+ 0 - 5
app/common/repositories/store/order/StoreGroupOrderRepository.php

@@ -948,11 +948,6 @@ class StoreGroupOrderRepository extends BaseRepository
948 948
         if (!empty($settlementOrderIdList)) {
949 949
             // 将订单 生成的奖励数据 立即结算(发放) 并更新这些订单的 结算字段以及结算时间
950 950
             $storeOrderRepository->settlementOrderByOrderIdList($settlementOrderIdList);
951
-
952
-            // 结算完成后更新用户的身份信息 设置用户 身份
953
-            /** @var UserRepository $userRepository */
954
-            $userRepository = app()->make(UserRepository::class);
955
-            $userRepository->setUserIdentity($storeGroupOrderEntity->getUid());
956 951
         }
957 952
 
958 953
         // 9、订单 分账 将收入的现金 商户部分 发放给 商户

+ 25 - 2
app/common/repositories/store/order/StoreOrderRepository.php

@@ -11999,10 +11999,22 @@ class StoreOrderRepository extends BaseRepository
11999 11999
                 $userSignGongxianRepository = app()->make(UserSignGongxianRepository::class);
12000 12000
                 $userSignGongxianEntityList = $userSignGongxianRepository->getUserSignGongxianEntityListByOrderIdListAndPending(UserSignGongxianEnum::ORDER_TYPE['Platform']['code'], $unsettledOrderIdList);
12001 12001
                 if (!empty($userSignGongxianEntityList)) {
12002
-                    $userSignGongxianIdList = array_map(function ($userSignGongxianEntity) {
12002
+                    $affectedUserIdListByMember = [];
12003
+                    $userSignGongxianIdList = array_map(function ($userSignGongxianEntity) use (&$affectedUserIdListByMember) {
12004
+                        $affectedUserIdListByMember[] = $userSignGongxianEntity->getUid();
12003 12005
                         return $userSignGongxianEntity->getId();
12004 12006
                     }, $userSignGongxianEntityList);
12005 12007
                     $userSignGongxianRepository->executeByIdList($userSignGongxianIdList);
12008
+                    // 会员体系结构 依靠贡献值变化而升级,所以当贡献值产生变化时 需记录用户ID 进行升级
12009
+                    if (!empty($affectedUserIdListByMember)) {
12010
+                        $affectedUserIdListByMember = array_unique($affectedUserIdListByMember);
12011
+                        // 结算完成后更新用户的身份信息 设置用户 身份
12012
+                        /** @var UserRepository $userRepository */
12013
+                        $userRepository = app()->make(UserRepository::class);
12014
+                        foreach ($affectedUserIdListByMember as $userId) {
12015
+                            $userRepository->setUserIdentity($userId);
12016
+                        }
12017
+                    }
12006 12018
                 }
12007 12019
 
12008 12020
                 /** 结算 PV */
@@ -12032,10 +12044,21 @@ class StoreOrderRepository extends BaseRepository
12032 12044
                 $sharedProsperityRewardRecordRepository = app()->make(SharedProsperityRewardRecordRepository::class);
12033 12045
                 $sharedProsperityRewardRecordEntityList = $sharedProsperityRewardRecordRepository->getSharedProsperityRewardRecordEntityListByOrderSnListAndPending(SharedProsperityRewardRecordEnum::TYPE_SHOP['Platform']['code'], $unsettledOrderSnList);
12034 12046
                 if (!empty($sharedProsperityRewardRecordEntityList)) {
12035
-                    $sharedProsperityRewardRecordIdList = array_map(function ($sharedProsperityRewardRecordEntity) {
12047
+                    $affectedUserIdListBySharedProsperity = [];
12048
+                    $sharedProsperityRewardRecordIdList = array_map(function ($sharedProsperityRewardRecordEntity) use (&$affectedUserIdListBySharedProsperity) {
12049
+                        if ($sharedProsperityRewardRecordEntity->getType() == SharedProsperityRewardRecordEnum::TYPE['PV']['code']) {
12050
+                            $affectedUserIdListBySharedProsperity[] = $sharedProsperityRewardRecordEntity->getUserId();
12051
+                        }
12036 12052
                         return $sharedProsperityRewardRecordEntity->getId();
12037 12053
                     }, $sharedProsperityRewardRecordEntityList);
12038 12054
                     $sharedProsperityRewardRecordRepository->executeByIdList($sharedProsperityRewardRecordIdList);
12055
+                    // 当用户PV产生变化时,需要更新产生变化用户的 共富体系等级
12056
+                    if (!empty($affectedUserIdListBySharedProsperity)) {
12057
+                        $affectedUserIdListBySharedProsperity = array_unique($affectedUserIdListBySharedProsperity);
12058
+                        /** @var SharedProsperityUserRepository $sharedProsperityUserRepository */
12059
+                        $sharedProsperityUserRepository = app()->make(SharedProsperityUserRepository::class);
12060
+                        $sharedProsperityUserRepository->identityUpgrade($affectedUserIdListBySharedProsperity);
12061
+                    }
12039 12062
                 }
12040 12063
 
12041 12064
                 // 订单奖励结算时 更新订单自身 结算字段

+ 19 - 0
app/entity/data/shared/SharedProsperityUserEntity.php

@@ -11,6 +11,7 @@ class SharedProsperityUserEntity extends DataEntity
11 11
     public $parentId = null;  // 推荐人用户id
12 12
     public $pv = null;  // pv
13 13
     public $consumerStocks = null; // 消费股
14
+    public $balance = null; // 余额
14 15
     public $withdrawalLimit = null;  // 提现额度
15 16
     public $partnerLevel = null;  // 合伙人等级
16 17
     public $createTime = null;  // 创建时间
@@ -109,6 +110,24 @@ class SharedProsperityUserEntity extends DataEntity
109 110
     /**
110 111
      * @return mixed
111 112
      */
113
+    public function getBalance()
114
+    {
115
+        return $this->balance;
116
+    }
117
+
118
+    /**
119
+     * @param mixed $balance
120
+     * @return SharedProsperityUserEntity
121
+     */
122
+    public function setBalance($balance): SharedProsperityUserEntity
123
+    {
124
+        $this->balance = $balance;
125
+        return $this;
126
+    }
127
+
128
+    /**
129
+     * @return mixed
130
+     */
112 131
     public function getWithdrawalLimit()
113 132
     {
114 133
         return $this->withdrawalLimit;