Browse Source

feat(shared-prosperity): 添加团队业绩统计层级参数支持

- 为 getTeamPvSum 方法增加层级参数,默认使用共享繁荣配置的层级代码
- 为 getTeamPvSumWithSelf 方法增加 self 参数控制是否包含自身数据
- 更新仓库中的团队用户ID获取逻辑,移除部分场景下的自包含选项
- 调整部门业绩统计功能,支持指定层级深度的团队数据查询
- 修改直属用户业绩计算方式,统一使用新的层级参数化方法
shichen 5 months ago
parent
commit
3b188f4098

+ 4 - 4
app/common/dao/shared/SharedProsperityUserDao.php

@@ -161,9 +161,9 @@ class SharedProsperityUserDao extends BaseDao
161 161
      * @param int $userId
162 162
      * @return float
163 163
      */
164
-    public function getTeamPvSum(int $userId): float
164
+    public function getTeamPvSum(int $userId, int $hierarchy = CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Hierarchy']['code']): float
165 165
     {
166
-        $userIds = $this->getAllSubordinateUserIds($userId, false);
166
+        $userIds = $this->getAllSubordinateUserIds($userId, false, $hierarchy);
167 167
         if (empty($userIds)) {
168 168
             return 0.0;
169 169
         }
@@ -184,9 +184,9 @@ class SharedProsperityUserDao extends BaseDao
184 184
      * @param int $userId
185 185
      * @return float
186 186
      */
187
-    public function getTeamPvSumWithSelf(int $userId): float
187
+    public function getTeamPvSumWithSelf(int $userId, $self = false): float
188 188
     {
189
-        $userIds = $this->getAllSubordinateUserIds($userId, true);
189
+        $userIds = $this->getAllSubordinateUserIds($userId, $self);
190 190
         if (empty($userIds)) {
191 191
             return 0.0;
192 192
         }

+ 5 - 5
app/common/repositories/shared/SharedProsperityUserRepository.php

@@ -194,7 +194,7 @@ class SharedProsperityUserRepository extends BaseRepository
194 194
         $list = $this->dao->getDirectByUserId($userId);
195 195
         if (empty($list)) {
196 196
             // 没有直推用户,仍然返回统计数据(我的部门总人数和总业绩)
197
-            $myTeamUserIds = $this->dao->getAllSubordinateUserIds($userId, true);
197
+            $myTeamUserIds = $this->dao->getAllSubordinateUserIds($userId);
198 198
             $myTeamTotalCount = count($myTeamUserIds);
199 199
             $myTeamPvSum = $this->dao->getTeamPvSumWithSelf($userId);
200 200
             return [
@@ -227,9 +227,9 @@ class SharedProsperityUserRepository extends BaseRepository
227 227
         $maxPv = 0;
228 228
         $maxPvIndex = -1;
229 229
         foreach ($list as $index => &$item) {
230
-            $teamUserIds = $this->dao->getAllSubordinateUserIds($item['user_id'], true);
230
+            $teamUserIds = $this->dao->getAllSubordinateUserIds($item['user_id'],false,4);
231 231
             $teamTotalCount = count($teamUserIds);
232
-            $teamPvSum = $this->dao->getTeamPvSumWithSelf($item['user_id']);
232
+            $teamPvSum = $this->dao->getTeamPvSum($item['user_id'],4);
233 233
             $item['team_total_count'] = $teamTotalCount;
234 234
             $item['team_pv_sum'] = $teamPvSum;
235 235
             // 补充用户信息
@@ -264,9 +264,9 @@ class SharedProsperityUserRepository extends BaseRepository
264 264
             $smallDepartment = $list;
265 265
         }
266 266
         // 计算统计数据
267
-        $myTeamUserIds = $this->dao->getAllSubordinateUserIds($userId, true);
267
+        $myTeamUserIds = $this->dao->getAllSubordinateUserIds($userId);
268 268
         $myTeamTotalCount = count($myTeamUserIds);
269
-        $myTeamPvSum = $this->dao->getTeamPvSumWithSelf($userId);
269
+        $myTeamPvSum = $this->dao->getTeamPvSum($userId);
270 270
         $smallDepartmentPvSum = 0;
271 271
         foreach ($smallDepartment as $item) {
272 272
             $smallDepartmentPvSum += $item['team_pv_sum'];