WIN-2308041133\Administrator 1 dag geleden
bovenliggende
commit
46cf23869b

+ 7 - 7
app/api/controller/v1/store/StoreCartController.php

@@ -102,13 +102,13 @@ class StoreCartController
             @file_put_contents("quanju.txt", "礼包检查: uid=$uid, is_gift=$is_gift\r\n", 8);
 
             // 先查看符合条件的订单详情
-            $hasOrder = $orderServices->count([
-                ['uid'=> $uid],
-                ['order_type'=> 1],
-                ['paid'=> 1]
-            ]);
-            @file_put_contents("quanju.txt", "礼包检查: hasOrder=$hasOrder\r\n", 8);
-            if ($hasOrder > 0) {
+//            $hasOrder = $orderServices->count([
+//                ['uid'=> $uid],
+//                ['order_type'=> 1],
+//                ['paid'=> 1]
+//            ]);
+
+            if ($orderServices->checkGift($uid)) {
                 return app('json')->fail('礼包商品只能购买一次');
             }
         }

+ 13 - 0
app/dao/order/StoreOrderDao.php

@@ -1068,4 +1068,17 @@ class StoreOrderDao extends BaseDao
     {
         return $this->getModel()->where('pid', $pid)->where('status', 1)->where('id', '<>', $order_id)->count();
     }
+    /**
+     * 判断用户是否购买过礼包商品
+     * @param int $pid
+     * @param int $order_id
+     * @return int
+     * @author: 吴汐
+     * @email: 442384644@qq.com
+     * @date: 2023/8/31
+     */
+    public function getGiftOrder(int $uid)
+    {
+        return $this->getModel()->where('uid', $uid)->where('pid', 1)->where('order_type',1 )->count();
+    }
 }

+ 13 - 0
app/services/order/StoreOrderServices.php

@@ -2817,4 +2817,17 @@ HTML;
             return true;
         }
     }
+    /**
+     * 判断用户是否购买过礼包订单
+     * @param int $uid
+     */
+    public function checkGift(int $uid)
+    {
+        $order_count = $this->dao->getGiftOrder($uid);
+        if ($order_count > 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
 }