Browse Source

优化用户下单方法-进行中

sunxbiao 1 year ago
parent
commit
3cbe5ba319

+ 6 - 0
app/common/enum/store/CartEnum.php

@@ -14,4 +14,10 @@ class CartEnum extends CommonEnum
14 14
         'No' => ['code' => 0, 'name' => '未失效'],
15 15
         'Yes' => ['code' => 1, 'name' => '失效']
16 16
     ];
17
+
18
+    // 是否已购买 '0 = 未购买 1 = 已购买'
19
+    const IS_PAY = [
20
+        'No' => ['code' => 0, 'name' => '未购买'],
21
+        'Yes' => ['code' => 1, 'name' => '已购买']
22
+    ];
17 23
 }

+ 22 - 5
app/common/repositories/store/order/StoreOrderRepository.php

@@ -10645,7 +10645,9 @@ class StoreOrderRepository extends BaseRepository
10645 10645
      */
10646 10646
     public function createOrderNew(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity, UserEntity $userEntity, array $cartEntityList, AddressEntity $addressEntity, ShareEntity $shareEntity)
10647 10647
     {
10648
-
10648
+        // 购物车
10649
+        /** @var StoreCartRepository $storeCartRepository */
10650
+        $storeCartRepository = app()->make(StoreCartRepository::class);
10649 10651
         // 商户
10650 10652
         /** @var MerchantRepository $merchantRepository */
10651 10653
         $merchantRepository = app()->make(MerchantRepository::class);
@@ -10905,11 +10907,27 @@ class StoreOrderRepository extends BaseRepository
10905 10907
 
10906 10908
 
10907 10909
 
10908
-            // 会员专区
10909
-            if ($productEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']) {
10910
+            // // 会员专区
10911
+            // if ($productEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']) {
10912
+            //
10913
+            // }
10910 10914
 
10915
+            // 更新库存
10916
+            if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
10917
+                $productAttrValueRepository->descStock($productAttrValueEntity->getProductId(), $productAttrValueEntity->getUnique(), $cartEntity->getCartNum());
10918
+                $productRepository->descStock($productEntity->getProductId(), $cartEntity->getCartNum());
10919
+            } else {
10920
+                $productAttrValueRepository->descSkuStock($productEntity->getOldProductId(), $productAttrValueEntity->getSku(), $cartEntity->getCartNum());
10921
+                $productRepository->descStock($productEntity->getOldProductId(), $cartEntity->getCartNum());
10911 10922
             }
10912 10923
 
10924
+            // 修改 购物车状态
10925
+            $storeCartRepository->update($cartEntity->getCartId(), ['is_pay' => CartEnum::IS_PAY['Yes']['code']]);
10926
+
10927
+            // 修改优惠券状态
10928
+            // $storeCouponUserRepository->updates([], []);
10929
+
10930
+            // StoreGroupOrderEntity
10913 10931
 
10914 10932
             // 组装数据
10915 10933
             $_order = [
@@ -10976,12 +10994,11 @@ class StoreOrderRepository extends BaseRepository
10976 10994
                 'fzone_pay_note' => $array_fzone_paytype_all['fzone_pay_note'],
10977 10995
                 'fzone_pay_type' => $array_fzone_paytype_all['fzone_pay_type'],
10978 10996
             ];
10979
-        }
10980 10997
 
10981
-        foreach ($orderList as $orderInfo) {
10982 10998
 
10983 10999
         }
10984 11000
 
11001
+
10985 11002
         return [];
10986 11003
     }
10987 11004
 

+ 33 - 0
app/entity/CommonEntity.php

@@ -48,4 +48,37 @@ class CommonEntity
48 48
         }
49 49
         return $data;
50 50
     }
51
+
52
+    /**
53
+     * 将实体属性(驼峰命名)转换为下划线命名的数组
54
+     * 用于数据库写入
55
+     * @return array
56
+     */
57
+    public function toUnderlineArray(): array
58
+    {
59
+        $result = [];
60
+        $camelArray = $this->toArray(); // 先获取驼峰格式的数组
61
+
62
+        foreach ($camelArray as $key => $value) {
63
+            // 将驼峰键名转为下划线格式
64
+            $underlineKey = $this->camelToUnderline($key);
65
+            $result[$underlineKey] = $value;
66
+        }
67
+
68
+        return $result;
69
+    }
70
+
71
+    /**
72
+     * 驼峰命名转下划线命名
73
+     * @param string $camel
74
+     * @return string
75
+     */
76
+    private function camelToUnderline(string $camel): string
77
+    {
78
+        // 处理连续大写字母(如 "userID" 转 "user_id")
79
+        $camel = preg_replace('/([A-Z]+)([A-Z][a-z])/', '$1_$2', $camel);
80
+
81
+        // 将大写字母前添加下划线并转为小写
82
+        return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $camel));
83
+    }
51 84
 }