|
|
@@ -10,6 +10,7 @@ use app\common\enum\shared\SharedProsperityRewardRecordEnum;
|
|
10
|
10
|
use app\common\enum\shared\SharedProsperityUserEnum;
|
|
11
|
11
|
use app\common\repositories\BaseRepository;
|
|
12
|
12
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
|
13
|
+use app\entity\data\shared\SharedProsperityGroupUserEntity;
|
|
13
|
14
|
use app\entity\data\shared\SharedProsperityRecommendConfigEntity;
|
|
14
|
15
|
use app\entity\data\shared\SharedProsperityUserEntity;
|
|
15
|
16
|
use think\db\exception\DbException;
|
|
|
@@ -225,9 +226,9 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
225
|
226
|
$maxPv = 0;
|
|
226
|
227
|
$maxPvIndex = -1;
|
|
227
|
228
|
foreach ($list as $index => &$item) {
|
|
228
|
|
- $teamUserIds = $this->dao->getAllSubordinateUserIds($item['user_id'],false,4);
|
|
|
229
|
+ $teamUserIds = $this->dao->getAllSubordinateUserIds($item['user_id'], false, 4);
|
|
229
|
230
|
$teamTotalCount = count($teamUserIds);
|
|
230
|
|
- $teamPvSum = $this->dao->getTeamPvSum($item['user_id'],4);
|
|
|
231
|
+ $teamPvSum = $this->dao->getTeamPvSum($item['user_id'], 4);
|
|
231
|
232
|
$item['team_total_count'] = $teamTotalCount;
|
|
232
|
233
|
$item['team_pv_sum'] = $teamPvSum;
|
|
233
|
234
|
// 补充用户信息
|
|
|
@@ -364,7 +365,52 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
364
|
365
|
// );
|
|
365
|
366
|
// }
|
|
366
|
367
|
|
|
|
368
|
+
|
|
|
369
|
+ // 暂时新增加逻辑 用户购买 298 商品后,自动升级为1星合伙人,目前只有消费者 能够获得PV值,在奖励结算时,判断订单金额 是否大于 298 并且 用户身份为 用户,则升级为一星合伙人
|
|
|
370
|
+ // 逻辑修改,如果用户的身份 是普通用户,则统计他在共富区内 所有消费的金额,是否超 每天自增的 升级限制金额,如果超过则升级为1星合伙人
|
|
|
371
|
+ if ($sharedProsperityUserEntity->getPartnerLevel() == 0) {
|
|
|
372
|
+ /** @var StoreOrderRepository $storeOrderRepository */
|
|
|
373
|
+ $storeOrderRepository = app()->make(StoreOrderRepository::class);
|
|
|
374
|
+ $sumTotalPrice = $storeOrderRepository->getSumTotalPriceByUidAndMerId($sharedProsperityUserEntity->getUserId(), CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']);
|
|
|
375
|
+ if (!empty($sumTotalPrice)) {
|
|
|
376
|
+ $partnerLevel = $sharedProsperityUserEntity->getPartnerLevel();
|
|
|
377
|
+ /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
|
|
|
378
|
+ $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
|
|
|
379
|
+ $sharedProsperityRecommendConfigEntityList = $sharedProsperityRecommendConfigRepository->getList();
|
|
|
380
|
+ usort($sharedProsperityRecommendConfigEntityList, function (SharedProsperityRecommendConfigEntity $a, SharedProsperityRecommendConfigEntity $b) {
|
|
|
381
|
+ return $a->getLevel() <=> $b->getLevel(); // 从小到大排序
|
|
|
382
|
+ });
|
|
|
383
|
+ foreach ($sharedProsperityRecommendConfigEntityList as $sharedProsperityRecommendConfigEntity) {
|
|
|
384
|
+ if (is_null($sharedProsperityRecommendConfigEntity->getConsume())) {
|
|
|
385
|
+ continue;
|
|
|
386
|
+ }
|
|
|
387
|
+ if ($sumTotalPrice >= $sharedProsperityRecommendConfigEntity->getConsume() && $sharedProsperityUserEntity->getPartnerLevel() < $sharedProsperityRecommendConfigEntity->getLevel()) {
|
|
|
388
|
+ // 修改用户的等级
|
|
|
389
|
+ $sharedProsperityUserEntity->setPartnerLevel($sharedProsperityRecommendConfigEntity->getLevel());
|
|
|
390
|
+ }
|
|
|
391
|
+ }
|
|
|
392
|
+ // 也就是说 升级了 保存到数据库
|
|
|
393
|
+ if ($partnerLevel != $sharedProsperityUserEntity->getPartnerLevel()) {
|
|
|
394
|
+ $this->updateByEntity(
|
|
|
395
|
+ SharedProsperityUserEntity::newInstance()
|
|
|
396
|
+ ->setId($sharedProsperityUserEntity->getId())
|
|
|
397
|
+ ->setPartnerLevel($sharedProsperityUserEntity->getPartnerLevel())
|
|
|
398
|
+ );
|
|
|
399
|
+ }
|
|
|
400
|
+ }
|
|
|
401
|
+ }
|
|
|
402
|
+
|
|
|
403
|
+ // 根据原来的团队升级规则,去升级推荐人等级
|
|
367
|
404
|
$this->upgradeUpperLevels($sharedProsperityUserEntity->getUserId(), $sharedProsperityRecommendConfigEntityList);
|
|
|
405
|
+
|
|
|
406
|
+ // 新的升级规则
|
|
|
407
|
+ // 如果当前用户升级了 那要看一下他的上级 是否也需要升级
|
|
|
408
|
+ if (!empty($sharedProsperityUserEntity->getParentId())) {
|
|
|
409
|
+ $sharedProsperityUserEntityByParent = $this->getSharedProsperityUserEntityByUserId($sharedProsperityUserEntity->getParentId());
|
|
|
410
|
+ if (!empty($sharedProsperityUserEntityByParent->getId()) && $sharedProsperityUserEntityByParent->getPartnerLevel() < 2) {
|
|
|
411
|
+ $this->upgradeUpperLevelsByPromotionOne($sharedProsperityUserEntityByParent);
|
|
|
412
|
+ }
|
|
|
413
|
+ }
|
|
368
|
414
|
}
|
|
369
|
415
|
}
|
|
370
|
416
|
|
|
|
@@ -422,30 +468,6 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
422
|
468
|
// 计算新等级
|
|
423
|
469
|
$newLevel = $this->calculateLevelByTeamPv($teamPvBySmallSum, $sharedProsperityRecommendConfigEntityList);
|
|
424
|
470
|
|
|
425
|
|
- // 暂时新增加逻辑 用户购买 298 商品后,自动升级为1星合伙人,目前只有消费者 能够获得PV值,在奖励结算时,判断订单金额 是否大于 298 并且 用户身份为 用户,则升级为一星合伙人
|
|
426
|
|
- // 逻辑修改,如果用户的身份 是普通用户,则统计他在共富区内 所有消费的金额,是否超 每天自增的 升级限制金额,如果超过则升级为1星合伙人
|
|
427
|
|
- if ($sharedProsperityUserEntity->getPartnerLevel() == 0) {
|
|
428
|
|
- /** @var StoreOrderRepository $storeOrderRepository */
|
|
429
|
|
- $storeOrderRepository = app()->make(StoreOrderRepository::class);
|
|
430
|
|
- $sumTotalPrice = $storeOrderRepository->getSumTotalPriceByUidAndMerId($sharedProsperityUserEntity->getUserId(), CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']);
|
|
431
|
|
- if (!empty($sumTotalPrice)) {
|
|
432
|
|
- /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
|
|
433
|
|
- $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
|
|
434
|
|
- $sharedProsperityRecommendConfigEntityList = $sharedProsperityRecommendConfigRepository->getList();
|
|
435
|
|
- usort($sharedProsperityRecommendConfigEntityList, function (SharedProsperityRecommendConfigEntity $a, SharedProsperityRecommendConfigEntity $b) {
|
|
436
|
|
- return $a->getLevel() <=> $b->getLevel(); // 从小到大排序
|
|
437
|
|
- });
|
|
438
|
|
- foreach ($sharedProsperityRecommendConfigEntityList as $sharedProsperityRecommendConfigEntity) {
|
|
439
|
|
- if (is_null($sharedProsperityRecommendConfigEntity->getConsume())) {
|
|
440
|
|
- continue;
|
|
441
|
|
- }
|
|
442
|
|
- if ($sumTotalPrice >= $sharedProsperityRecommendConfigEntity->getConsume() && $newLevel < $sharedProsperityRecommendConfigEntity->getLevel()) {
|
|
443
|
|
- $newLevel = $sharedProsperityRecommendConfigEntity->getLevel();
|
|
444
|
|
- }
|
|
445
|
|
- }
|
|
446
|
|
- }
|
|
447
|
|
- }
|
|
448
|
|
-
|
|
449
|
471
|
// 如果新等级大于当前等级,则更新
|
|
450
|
472
|
if ($newLevel > $sharedProsperityUserEntity->getPartnerLevel()) {
|
|
451
|
473
|
$this->updateByEntity(
|
|
|
@@ -557,13 +579,13 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
557
|
579
|
{
|
|
558
|
580
|
/** @var SharedProsperityUserDao $shareUserDao */
|
|
559
|
581
|
$shareUserDao = app()->make(SharedProsperityUserDao::class);
|
|
560
|
|
-
|
|
|
582
|
+
|
|
561
|
583
|
// 获取所有下级用户ID(包括自己)
|
|
562
|
584
|
$subordinateIds = $shareUserDao->getAllSubordinateUserIds($userId, true);
|
|
563
|
585
|
if (empty($subordinateIds)) {
|
|
564
|
586
|
return [];
|
|
565
|
587
|
}
|
|
566
|
|
-
|
|
|
588
|
+
|
|
567
|
589
|
// 获取这些共富用户的基本信息(包含parent_id)
|
|
568
|
590
|
$sharedUsers = $shareUserDao->getSharedProsperityUserEntityListByUserIdList($subordinateIds);
|
|
569
|
591
|
|
|
|
@@ -592,9 +614,9 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
592
|
614
|
$idToName = [];
|
|
593
|
615
|
foreach ($userInfos as $userInfo) {
|
|
594
|
616
|
$sharedUserInfo = $shareUserDao->getSharedProsperityUserEntityListByUserIdList([$userInfo->getUid()]);
|
|
595
|
|
- $idToName[$userInfo->getUid()] = $userInfo->getNickname() . '(' . $userInfo->account .')(身份:' . $partnerLevel[$sharedUserInfo[0]->getPartnerLevel()] . ')' ?? ('用户' . $userInfo->getUid());
|
|
|
617
|
+ $idToName[$userInfo->getUid()] = $userInfo->getNickname() . '(' . $userInfo->account . ')(身份:' . $partnerLevel[$sharedUserInfo[0]->getPartnerLevel()] . ')' ?? ('用户' . $userInfo->getUid());
|
|
596
|
618
|
}
|
|
597
|
|
-
|
|
|
619
|
+
|
|
598
|
620
|
// 构建节点数组
|
|
599
|
621
|
$nodes = [];
|
|
600
|
622
|
foreach ($sharedUsers as $sharedUser) {
|
|
|
@@ -604,7 +626,7 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
604
|
626
|
'name' => $idToName[$sharedUser->getUserId()] ?? ('用户' . $sharedUser->getUserId()),
|
|
605
|
627
|
];
|
|
606
|
628
|
}
|
|
607
|
|
-
|
|
|
629
|
+
|
|
608
|
630
|
// 构建树,以传入的用户为根节点
|
|
609
|
631
|
$rootNode = $this->findNode($nodes, $userId);
|
|
610
|
632
|
if (!$rootNode) {
|
|
|
@@ -617,7 +639,7 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
617
|
639
|
];
|
|
618
|
640
|
return [$tree];
|
|
619
|
641
|
}
|
|
620
|
|
-
|
|
|
642
|
+
|
|
621
|
643
|
/**
|
|
622
|
644
|
* 递归构建共富用户树
|
|
623
|
645
|
* @param array $nodes 节点数组,每个节点包含 user_id, parent_id, name
|
|
|
@@ -639,7 +661,7 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
639
|
661
|
}
|
|
640
|
662
|
return $branch;
|
|
641
|
663
|
}
|
|
642
|
|
-
|
|
|
664
|
+
|
|
643
|
665
|
/**
|
|
644
|
666
|
* 根据user_id查找节点名称
|
|
645
|
667
|
* @param array $nodes
|
|
|
@@ -655,7 +677,7 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
655
|
677
|
}
|
|
656
|
678
|
return null;
|
|
657
|
679
|
}
|
|
658
|
|
-
|
|
|
680
|
+
|
|
659
|
681
|
/**
|
|
660
|
682
|
* 根据user_id查找节点
|
|
661
|
683
|
* @param array $nodes
|
|
|
@@ -685,7 +707,7 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
685
|
707
|
$userData = $userDao->accountLikeByUser($params['account']);
|
|
686
|
708
|
$uids = [];
|
|
687
|
709
|
if ($userData) {
|
|
688
|
|
- $uids = array_column($userData,'uid');
|
|
|
710
|
+ $uids = array_column($userData, 'uid');
|
|
689
|
711
|
}
|
|
690
|
712
|
|
|
691
|
713
|
$where[] = ['a.user_id', 'in', $uids];
|
|
|
@@ -697,7 +719,7 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
697
|
719
|
$userData = $userDao->nicknameLikeByUser($params['nickname']);
|
|
698
|
720
|
$uids = [];
|
|
699
|
721
|
if ($userData) {
|
|
700
|
|
- $uids = array_column($userData,'uid');
|
|
|
722
|
+ $uids = array_column($userData, 'uid');
|
|
701
|
723
|
}
|
|
702
|
724
|
$where[] = ['a.user_id', 'in', $uids];
|
|
703
|
725
|
}
|
|
|
@@ -824,4 +846,66 @@ class SharedProsperityUserRepository extends BaseRepository
|
|
824
|
846
|
return false;
|
|
825
|
847
|
}
|
|
826
|
848
|
}
|
|
|
849
|
+
|
|
|
850
|
+ /**
|
|
|
851
|
+ * 第一次促销的 身份 升级方法
|
|
|
852
|
+ * @param SharedProsperityUserEntity $sharedProsperityUserEntity
|
|
|
853
|
+ * @return void
|
|
|
854
|
+ */
|
|
|
855
|
+ public function upgradeUpperLevelsByPromotionOne(SharedProsperityUserEntity $sharedProsperityUserEntity)
|
|
|
856
|
+ {
|
|
|
857
|
+ // 判断当前用户 是否在共富区的消费值 > 298,如果不满足则不能升级
|
|
|
858
|
+ /** @var StoreOrderRepository $storeOrderRepository */
|
|
|
859
|
+ $storeOrderRepository = app()->make(StoreOrderRepository::class);
|
|
|
860
|
+ $sumTotalPrice = $storeOrderRepository->getSumTotalPriceByUidAndMerId($sharedProsperityUserEntity->getUserId(), CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']);
|
|
|
861
|
+ if ($sumTotalPrice < 298) {
|
|
|
862
|
+ return;
|
|
|
863
|
+ }
|
|
|
864
|
+
|
|
|
865
|
+ // 查询当前用户的直属下级
|
|
|
866
|
+ $sharedProsperityUserEntityListByChild = $this->getSharedProsperityUserEntityListByParentId($sharedProsperityUserEntity->getUserId());
|
|
|
867
|
+ // 一星合伙人数量
|
|
|
868
|
+ $oneStarPartner = 0;
|
|
|
869
|
+ // 二星合伙人数量
|
|
|
870
|
+ $twoStarPartner = 0;
|
|
|
871
|
+ foreach ($sharedProsperityUserEntityListByChild as $sharedProsperityUserEntityByChild) {
|
|
|
872
|
+ if ($sharedProsperityUserEntityByChild->getPartnerLevel() >= 1) {
|
|
|
873
|
+ $oneStarPartner++;
|
|
|
874
|
+ if ($sharedProsperityUserEntityByChild->getPartnerLevel() >= 2) {
|
|
|
875
|
+ $twoStarPartner++;
|
|
|
876
|
+ }
|
|
|
877
|
+ }
|
|
|
878
|
+ }
|
|
|
879
|
+
|
|
|
880
|
+ // 推荐 6 个 2星以上的合伙人 增加万人团身份
|
|
|
881
|
+ if ($twoStarPartner >= 6) {
|
|
|
882
|
+ /** @var SharedProsperityGroupUserRepository $sharedProsperityGroupUserRepository */
|
|
|
883
|
+ $sharedProsperityGroupUserRepository = app()->make(SharedProsperityGroupUserRepository::class);
|
|
|
884
|
+ $sharedProsperityGroupUserEntity = $sharedProsperityGroupUserRepository->getSharedProsperityGroupUserEntityByUserId($sharedProsperityUserEntity->getUserId());
|
|
|
885
|
+ if (empty($sharedProsperityGroupUserEntity->getId())) {
|
|
|
886
|
+ // 如果没有共富团身份 则增加共富团 万人团身份
|
|
|
887
|
+ $sharedProsperityGroupUserRepository->createByEntity(
|
|
|
888
|
+ SharedProsperityGroupUserEntity::newInstance()
|
|
|
889
|
+ ->setUserId($sharedProsperityUserEntity->getUserId())
|
|
|
890
|
+ ->setGroupId(1)
|
|
|
891
|
+ ->setStatus(1)
|
|
|
892
|
+ );
|
|
|
893
|
+ }
|
|
|
894
|
+ }
|
|
|
895
|
+ // 推荐 6 个 1星以上的合伙人 则升级为 2 星合伙人
|
|
|
896
|
+ if ($sharedProsperityUserEntity->getPartnerLevel() < 2 && $oneStarPartner >= 6) {
|
|
|
897
|
+ $this->updateByEntity(
|
|
|
898
|
+ SharedProsperityUserEntity::newInstance()
|
|
|
899
|
+ ->setId($sharedProsperityUserEntity->getId())
|
|
|
900
|
+ ->setPartnerLevel(2)
|
|
|
901
|
+ );
|
|
|
902
|
+ // 如果当前用户升级了 那要看一下他的上级 是否也需要升级
|
|
|
903
|
+ if (!empty($sharedProsperityUserEntity->getParentId())) {
|
|
|
904
|
+ $sharedProsperityUserEntityByParent = $this->getSharedProsperityUserEntityByUserId($sharedProsperityUserEntity->getParentId());
|
|
|
905
|
+ if (!empty($sharedProsperityUserEntityByParent->getId()) && $sharedProsperityUserEntityByParent->getPartnerLevel() < 2) {
|
|
|
906
|
+ $this->upgradeUpperLevelsByPromotionOne($sharedProsperityUserEntityByParent);
|
|
|
907
|
+ }
|
|
|
908
|
+ }
|
|
|
909
|
+ }
|
|
|
910
|
+ }
|
|
827
|
911
|
}
|