|
|
@@ -3,6 +3,7 @@
|
|
3
|
3
|
namespace app\common\repositories\shared;
|
|
4
|
4
|
|
|
5
|
5
|
use app\common\dao\shared\SharedProsperityRewardRecordDao;
|
|
|
6
|
+use app\common\dao\shared\SharedProsperityUserDao;
|
|
6
|
7
|
use app\common\enum\shared\SharedProsperityRewardRecordEnum;
|
|
7
|
8
|
use app\common\repositories\BaseRepository;
|
|
8
|
9
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
|
@@ -263,4 +264,79 @@ class SharedProsperityRewardRecordRepository extends BaseRepository
|
|
263
|
264
|
|
|
264
|
265
|
return $idList;
|
|
265
|
266
|
}
|
|
|
267
|
+
|
|
|
268
|
+
|
|
|
269
|
+ /**
|
|
|
270
|
+ * 获取奖励记录分页列表,并返回统计数据
|
|
|
271
|
+ * @param int $userId 用户ID
|
|
|
272
|
+ * @param int $status 前端传入的状态:1=有效,0=待确定
|
|
|
273
|
+ * @param int $page 页码
|
|
|
274
|
+ * @param int $pageSize 每页数量,默认10
|
|
|
275
|
+ * @return array
|
|
|
276
|
+ */
|
|
|
277
|
+ public function getRewardList($userId, $status, $page, $pageSize = 10)
|
|
|
278
|
+ {
|
|
|
279
|
+ $type = SharedProsperityRewardRecordEnum::TYPE['PV']['code'];
|
|
|
280
|
+ if ($status == 1) {
|
|
|
281
|
+ $statusCode = SharedProsperityRewardRecordEnum::STATUS['VALID']['code'];
|
|
|
282
|
+ } else {
|
|
|
283
|
+ $statusCode = SharedProsperityRewardRecordEnum::STATUS['PENDING']['code'];
|
|
|
284
|
+ }
|
|
|
285
|
+ $pm = 1; // 只查询获得(收入)
|
|
|
286
|
+ // 获取分页列表
|
|
|
287
|
+ $list = $this->dao->getRewardList($userId, $type, $statusCode, null, $pm, $page, $pageSize);
|
|
|
288
|
+
|
|
|
289
|
+ // 计算统计数据
|
|
|
290
|
+ $stats = $this->calculateRewardStats($userId);
|
|
|
291
|
+
|
|
|
292
|
+ return [
|
|
|
293
|
+ 'list' => $list,
|
|
|
294
|
+ 'stats' => $stats,
|
|
|
295
|
+ ];
|
|
|
296
|
+ }
|
|
|
297
|
+
|
|
|
298
|
+ /**
|
|
|
299
|
+ * 计算奖励统计数据
|
|
|
300
|
+ * @param int $userId
|
|
|
301
|
+ * @return array
|
|
|
302
|
+ */
|
|
|
303
|
+ private function calculateRewardStats(int $userId): array
|
|
|
304
|
+ {
|
|
|
305
|
+ $type = SharedProsperityRewardRecordEnum::TYPE['PV']['code'];
|
|
|
306
|
+ $pm = 1; // 获得
|
|
|
307
|
+
|
|
|
308
|
+ // 1. 我的贡献值(有效)
|
|
|
309
|
+ $myContribution = $this->dao->getRewardSum($userId, $type, SharedProsperityRewardRecordEnum::STATUS['VALID']['code'], null, $pm);
|
|
|
310
|
+ // 2. 未生效贡献值(待确定)
|
|
|
311
|
+ $pendingContribution = $this->dao->getRewardSum($userId, $type, SharedProsperityRewardRecordEnum::STATUS['PENDING']['code'], null, $pm);
|
|
|
312
|
+
|
|
|
313
|
+ // 获取直推用户ID列表
|
|
|
314
|
+ /** @var SharedProsperityUserDao $sharedProsperityUserDao */
|
|
|
315
|
+ $sharedProsperityUserDao = app()->make(SharedProsperityUserDao::class);
|
|
|
316
|
+ $directUserIds = array_column($sharedProsperityUserDao->getDirectByUserId($userId), 'user_id');
|
|
|
317
|
+
|
|
|
318
|
+ // 3. 直推贡献值(直推用户的有效贡献总和)
|
|
|
319
|
+ $directContribution = 0;
|
|
|
320
|
+ if (!empty($directUserIds)) {
|
|
|
321
|
+ $directContribution = $this->dao->getRewardSum($directUserIds, $type, SharedProsperityRewardRecordEnum::STATUS['VALID']['code'], null, $pm);
|
|
|
322
|
+ }
|
|
|
323
|
+
|
|
|
324
|
+ // 4. 小部门贡献值(需要区分大部门和小部门)
|
|
|
325
|
+ // 获取团队划分
|
|
|
326
|
+ /** @var SharedProsperityUserRepository $sharedProsperityUserRepository */
|
|
|
327
|
+ $sharedProsperityUserRepository = app()->make(SharedProsperityUserRepository::class);
|
|
|
328
|
+ $teamData = $sharedProsperityUserRepository->getTeam($userId);
|
|
|
329
|
+ $smallDepartmentUserIds = array_column($teamData['small_department'] ?? [], 'user_id');
|
|
|
330
|
+ $smallDepartmentContribution = 0;
|
|
|
331
|
+ if (!empty($smallDepartmentUserIds)) {
|
|
|
332
|
+ $smallDepartmentContribution = $this->dao->getRewardSum($smallDepartmentUserIds, $type, SharedProsperityRewardRecordEnum::STATUS['VALID']['code'], null, $pm);
|
|
|
333
|
+ }
|
|
|
334
|
+
|
|
|
335
|
+ return [
|
|
|
336
|
+ 'my_contribution' => (float) $myContribution,
|
|
|
337
|
+ 'pending_contribution' => (float) $pendingContribution,
|
|
|
338
|
+ 'direct_contribution' => (float) $directContribution,
|
|
|
339
|
+ 'small_department_contribution' => (float) $smallDepartmentContribution,
|
|
|
340
|
+ ];
|
|
|
341
|
+ }
|
|
266
|
342
|
}
|