Browse Source

共富区用户升级,增加升级条件,购买58635商品的普通用户升级为1星合伙人

sunxbiao 4 months ago
parent
commit
00f48bd88b

+ 28 - 0
app/common/dao/store/order/StoreCartDao.php

@@ -218,4 +218,32 @@ class StoreCartDao extends BaseDao
218 218
             ->whereIn('cart_id', $cartIdList)
219 219
             ->update(['is_pay' => $isPay]);
220 220
     }
221
+
222
+    /**
223
+     * 获取 购物车实体 根基用户ID 商品ID列表 查询 已下单的(这里并非表示已支付) 购物车实体
224
+     * @param int $uid
225
+     * @param array $productIdList
226
+     * @return CartEntity[]
227
+     */
228
+    public function getCartEntityListByUidAndProductIdListAndIsPay(int $uid, array $productIdList): array
229
+    {
230
+        $entityList = [];
231
+        try {
232
+            /** @var StoreCart $model */
233
+            $model = $this->getModel();
234
+            $dataListRes = $model::getDB()
235
+                ->where('uid', '=', $uid)
236
+                ->whereIn('product_id', $productIdList)
237
+                ->where('is_pay', '=', CartEnum::IS_PAY['Yes']['code'])
238
+                ->select()
239
+                ->toArray();
240
+            if (!empty($dataListRes)) {
241
+                foreach ($dataListRes as $data) {
242
+                    $entityList[] = CartEntity::newInstance($data);
243
+                }
244
+            }
245
+        } catch (\Exception $e) {
246
+        }
247
+        return $entityList;
248
+    }
221 249
 }

+ 26 - 0
app/common/dao/store/order/StoreOrderDao.php

@@ -723,6 +723,32 @@ class StoreOrderDao extends BaseDao
723 723
     }
724 724
 
725 725
     /**
726
+     * @param array $cartIdList
727
+     * @return StoreOrderEntity[]
728
+     */
729
+    public function getStoreOrderEntityListByCartIdListAndIsPay(array $cartIdList): array
730
+    {
731
+        $entityList = [];
732
+        try {
733
+            /** @var StoreOrder $model */
734
+            $model = $this->getModel();
735
+            $dataRes = $model::getDB()
736
+                ->whereIn('card_id', $cartIdList)
737
+                ->where('paid', '=', StoreOrderEnum::PAID['YES']['code'])
738
+                ->select()
739
+                ->toArray();
740
+            if (!empty($dataRes)) {
741
+                $entityList = array_map(function ($data) {
742
+                    return StoreOrderEntity::newInstance($data);
743
+                }, $dataRes);
744
+            }
745
+        } catch (\Exception $e) {
746
+
747
+        }
748
+        return $entityList;
749
+    }
750
+
751
+    /**
726 752
      * 订单支付成功 更新订单状态
727 753
      * @param StoreOrderEntity[] $storeOrderEntityList
728 754
      * @return StoreOrderEntity[]

+ 32 - 11
app/common/repositories/shared/SharedProsperityUserRepository.php

@@ -9,6 +9,7 @@ use app\common\enum\CommonEnum;
9 9
 use app\common\enum\shared\SharedProsperityRewardRecordEnum;
10 10
 use app\common\enum\shared\SharedProsperityUserEnum;
11 11
 use app\common\repositories\BaseRepository;
12
+use app\common\repositories\store\order\StoreCartRepository;
12 13
 use app\common\repositories\store\order\StoreOrderRepository;
13 14
 use app\entity\data\shared\SharedProsperityGroupUserEntity;
14 15
 use app\entity\data\shared\SharedProsperityRecommendConfigEntity;
@@ -366,14 +367,33 @@ class SharedProsperityUserRepository extends BaseRepository
366 367
             // }
367 368
 
368 369
 
369
-            // 暂时新增加逻辑 用户购买 298 商品后,自动升级为1星合伙人,目前只有消费者 能够获得PV值,在奖励结算时,判断订单金额 是否大于 298 并且 用户身份为 用户,则升级为一星合伙人
370
-            // 逻辑修改,如果用户的身份 是普通用户,则统计他在共富区内 所有消费的金额,是否超 每天自增的 升级限制金额,如果超过则升级为1星合伙人
371 370
             if ($sharedProsperityUserEntity->getPartnerLevel() == 0) {
371
+                // 记录用户当前的 用户等级
372
+                $partnerLevel = $sharedProsperityUserEntity->getPartnerLevel();
373
+
374
+                // 新增需求 凡是 共富区,购买过商品ID 58635 的 ‘普通用户’ 升级为 ‘1星合伙人’
375
+                /** @var StoreCartRepository $storeCartRepository */
376
+                $storeCartRepository = app()->make(StoreCartRepository::class);
377
+                $storeCartEntityList = $storeCartRepository->getCartEntityListByUidAndProductIdListAndIsPay($sharedProsperityUserEntity->getUserId(), [58635]);
378
+                if (!empty($storeCartEntityList)) {
379
+                    $cartIdList = array_column($storeCartEntityList, 'cartId');
380
+                    if (!empty($cartIdList)) {
381
+                        /** @var StoreOrderRepository $storeOrderRepository */
382
+                        $storeOrderRepository = app()->make(StoreOrderRepository::class);
383
+                        $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByCartIdListAndIsPay($cartIdList);
384
+                        if (!empty($storeOrderEntityList)) {
385
+                            // 修改用户的等级
386
+                            $sharedProsperityUserEntity->setPartnerLevel(1);
387
+                        }
388
+                    }
389
+                }
390
+
391
+                // 暂时新增加逻辑 用户购买 298 商品后,自动升级为1星合伙人,目前只有消费者 能够获得PV值,在奖励结算时,判断订单金额 是否大于 298 并且 用户身份为 用户,则升级为一星合伙人
392
+                // 逻辑修改,如果用户的身份 是普通用户,则统计他在共富区内 所有消费的金额,是否超 每天自增的 升级限制金额,如果超过则升级为1星合伙人
372 393
                 /** @var StoreOrderRepository $storeOrderRepository */
373 394
                 $storeOrderRepository = app()->make(StoreOrderRepository::class);
374 395
                 $sumTotalPrice = $storeOrderRepository->getSumTotalPriceByUidAndMerId($sharedProsperityUserEntity->getUserId(), CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']);
375 396
                 if (!empty($sumTotalPrice)) {
376
-                    $partnerLevel = $sharedProsperityUserEntity->getPartnerLevel();
377 397
                     /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
378 398
                     $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
379 399
                     $sharedProsperityRecommendConfigEntityList = $sharedProsperityRecommendConfigRepository->getList();
@@ -389,14 +409,15 @@ class SharedProsperityUserRepository extends BaseRepository
389 409
                             $sharedProsperityUserEntity->setPartnerLevel($sharedProsperityRecommendConfigEntity->getLevel());
390 410
                         }
391 411
                     }
392
-                    // 也就是说 升级了 保存到数据库
393
-                    if ($partnerLevel != $sharedProsperityUserEntity->getPartnerLevel()) {
394
-                        $this->updateByEntity(
395
-                            SharedProsperityUserEntity::newInstance()
396
-                                ->setId($sharedProsperityUserEntity->getId())
397
-                                ->setPartnerLevel($sharedProsperityUserEntity->getPartnerLevel())
398
-                        );
399
-                    }
412
+                }
413
+
414
+                // 也就是说 升级了 保存到数据库
415
+                if ($partnerLevel != $sharedProsperityUserEntity->getPartnerLevel()) {
416
+                    $this->updateByEntity(
417
+                        SharedProsperityUserEntity::newInstance()
418
+                            ->setId($sharedProsperityUserEntity->getId())
419
+                            ->setPartnerLevel($sharedProsperityUserEntity->getPartnerLevel())
420
+                    );
400 421
                 }
401 422
             }
402 423
 

+ 10 - 0
app/common/repositories/store/order/StoreCartRepository.php

@@ -156,4 +156,14 @@ class StoreCartRepository extends BaseRepository
156 156
     {
157 157
         return $this->dao->updateIsPayByCartIdList($cartIdList, $isPay);
158 158
     }
159
+
160
+    /**
161
+     * @param int $uid
162
+     * @param array $productIdList
163
+     * @return CartEntity[]
164
+     */
165
+    public function getCartEntityListByUidAndProductIdListAndIsPay(int $uid, array $productIdList): array
166
+    {
167
+        return $this->dao->getCartEntityListByUidAndProductIdListAndIsPay($uid, $productIdList);
168
+    }
159 169
 }

+ 10 - 0
app/common/repositories/store/order/StoreOrderRepository.php

@@ -10863,6 +10863,16 @@ class StoreOrderRepository extends BaseRepository
10863 10863
         return $this->dao->getStoreOrderEntityListByGroupOrderIdList($groupOrderIdList);
10864 10864
     }
10865 10865
 
10866
+    /**
10867
+     * 根据 购物车ID 获取 已下单的 并且 支付的 订单
10868
+     * @param array $cartIdList
10869
+     * @return StoreOrderEntity[]
10870
+     */
10871
+    public function getStoreOrderEntityListByCartIdListAndIsPay(array $cartIdList): array
10872
+    {
10873
+        return $this->dao->getStoreOrderEntityListByCartIdListAndIsPay($cartIdList);
10874
+    }
10875
+
10866 10876
     public function create($data)
10867 10877
     {
10868 10878
         return $this->dao->create($data);