Przeglądaj źródła

feat(store): 添加购物车商品ID列表查询功能并优化订单幸福币发放逻辑

shichen 3 miesięcy temu
rodzic
commit
1d4b245f71

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

@@ -246,4 +246,26 @@ class StoreCartDao extends BaseDao
246 246
         }
247 247
         return $entityList;
248 248
     }
249
+
250
+    public function getCartEntityListByUidAndProductIdList(int $uid, array $productIdList): array
251
+    {
252
+        $entityList = [];
253
+        try {
254
+            /** @var StoreCart $model */
255
+            $model = $this->getModel();
256
+            $dataListRes = $model::getDB()
257
+                ->where('uid', '=', $uid)
258
+                ->whereIn('product_id', $productIdList)
259
+                ->select()
260
+                ->toArray();
261
+            if (!empty($dataListRes)) {
262
+                foreach ($dataListRes as $data) {
263
+                    $entityList[] = CartEntity::newInstance($data);
264
+                }
265
+            }
266
+        } catch (\Exception $e) {
267
+        }
268
+        return $entityList;
269
+    }
270
+
249 271
 }

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

@@ -166,4 +166,9 @@ class StoreCartRepository extends BaseRepository
166 166
     {
167 167
         return $this->dao->getCartEntityListByUidAndProductIdListAndIsPay($uid, $productIdList);
168 168
     }
169
+
170
+    public function getCartEntityListByUidAndProductIdList(int $uid, array $productIdList): array
171
+    {
172
+        return $this->dao->getCartEntityListByUidAndProductIdList($uid, $productIdList);
173
+    }
169 174
 }

+ 18 - 13
app/common/repositories/store/order/StoreOrderRepository.php

@@ -11736,19 +11736,24 @@ class StoreOrderRepository extends BaseRepository
11736 11736
                 '购买共富区商品获得PV'
11737 11737
             );
11738 11738
 
11739
-            // 发放幸福币
11740
-            $xfbData = [
11741
-                'uid' => $sharedProsperityUserEntity->getUserId(),
11742
-                'before' => 0,
11743
-                'number' => $storeOrderEntity->getPayPrice(),
11744
-                'after' => 0,
11745
-                'mark' => '购买共富区商品获得幸福币:' . $storeOrderEntity->getPayPrice(),
11746
-                'desc' => '购买共富区商品获得幸福币',
11747
-                'order_sn' => $storeOrderEntity->getOrderSn(),
11748
-                'order_type' => $storeOrderEntity->getOrderType(),
11749
-                'type' => 1,
11750
-                'addtime' => time()
11751
-            ];
11739
+            // 特定商品发放幸福币
11740
+            /** @var StoreCartRepository $storeCartRepository */
11741
+            $storeCartRepository = app()->make(StoreCartRepository::class);
11742
+            $storeCartEntity = $storeCartRepository->getCartEntityListByUidAndProductIdList($storeOrderEntity->getUid(), [90619]);
11743
+            if (!empty($storeCartEntityList)) {
11744
+                $xfbData = [
11745
+                    'uid' => $sharedProsperityUserEntity->getUserId(),
11746
+                    'before' => 0,
11747
+                    'number' => $storeOrderEntity->getPayPrice(),
11748
+                    'after' => 0,
11749
+                    'mark' => '购买共富区商品获得幸福币:' . $storeOrderEntity->getPayPrice(),
11750
+                    'desc' => '购买共富区商品获得幸福币',
11751
+                    'order_sn' => $storeOrderEntity->getOrderSn(),
11752
+                    'order_type' => $storeOrderEntity->getOrderType(),
11753
+                    'type' => 1,
11754
+                    'addtime' => time()
11755
+                ];
11756
+            }
11752 11757
             /** @var UserSignXfbRepository $xfbRepository */
11753 11758
             $xfbRepository = app()->make(UserSignXfbRepository::class);
11754 11759
             $xfbRepository->create($xfbData);