소스 검색

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

sunxbiao 11 달 전
부모
커밋
4afee58c37

+ 3 - 0
app/common/dao/user/UserSignScoreDao.php

@@ -11,6 +11,7 @@ use app\entity\data\user\UserSignScoreEntity;
11
 use think\db\exception\DataNotFoundException;
11
 use think\db\exception\DataNotFoundException;
12
 use think\db\exception\DbException;
12
 use think\db\exception\DbException;
13
 use think\db\exception\ModelNotFoundException;
13
 use think\db\exception\ModelNotFoundException;
14
+use think\facade\Log;
14
 
15
 
15
 class UserSignScoreDao extends BaseDao
16
 class UserSignScoreDao extends BaseDao
16
 {
17
 {
@@ -36,6 +37,8 @@ class UserSignScoreDao extends BaseDao
36
                 ->whereIn('id', $idList)
37
                 ->whereIn('id', $idList)
37
                 ->select()
38
                 ->select()
38
                 ->toArray();
39
                 ->toArray();
40
+            Log::info('$dataRes - getUserSignScoreEntityListByIdList');
41
+            Log::info($dataRes);
39
             if (!empty($dataRes)) {
42
             if (!empty($dataRes)) {
40
                 $entityList = array_map(function ($data) {
43
                 $entityList = array_map(function ($data) {
41
                     return UserSignScoreEntity::newInstance($data);
44
                     return UserSignScoreEntity::newInstance($data);

+ 23 - 14
app/common/repositories/store/order/StoreOrderRepository.php

@@ -11992,15 +11992,10 @@ class StoreOrderRepository extends BaseRepository
11992
             ->setPayType($storeOrderCreateRequestEntity->getPayType())
11992
             ->setPayType($storeOrderCreateRequestEntity->getPayType())
11993
             ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
11993
             ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
11994
 
11994
 
11995
-        // 5、验证是否 可以进行支付
11996
-        /** @var FzonePayTypeEntity $fzonePayTypeEntity */
11997
-        $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
11998
-        $paySuccess = $this->abatement($userEntity, $storeGroupOrderEntity, $fzonePayTypeEntity);
11999
-
12000
-        // 5、写入数据
11995
+        // 4、写入数据
12001
         Db::startTrans();
11996
         Db::startTrans();
12002
         try {
11997
         try {
12003
-            // 5.1 更细库存
11998
+            // 4.1 更细库存
12004
             foreach ($productStockList as $item) {
11999
             foreach ($productStockList as $item) {
12005
                 $productRepository->descStock($item['productId'], $item['cartNum']);
12000
                 $productRepository->descStock($item['productId'], $item['cartNum']);
12006
             }
12001
             }
@@ -12008,15 +12003,20 @@ class StoreOrderRepository extends BaseRepository
12008
                 $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
12003
                 $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
12009
             }
12004
             }
12010
 
12005
 
12011
-            // 5.2 修改 购物车状态
12006
+            // 4.2 修改 购物车状态
12012
             $storeCartRepository->updateIsPayByCartIdList($cartIdList);
12007
             $storeCartRepository->updateIsPayByCartIdList($cartIdList);
12013
 
12008
 
12014
-            // 5.3 写入 组合订单 (支付订单)
12009
+            // 4.3 写入 组合订单 (支付订单)
12015
             /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
12010
             /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
12016
             $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
12011
             $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
12017
             $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
12012
             $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
12018
 
12013
 
12019
-            // 5.4 写入订单数据
12014
+            // 4.4 验证是否 可以进行支付
12015
+            /** @var FzonePayTypeEntity $fzonePayTypeEntity */
12016
+            $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
12017
+            $paySuccess = $this->abatement($userEntity, $storeGroupOrderEntity, $fzonePayTypeEntity);
12018
+
12019
+            // 4.5 写入订单数据
12020
             $storeOrderStatusDataList = [];
12020
             $storeOrderStatusDataList = [];
12021
             $storeOrderProductDataList = [];
12021
             $storeOrderProductDataList = [];
12022
             $storeOrderIdList = [];
12022
             $storeOrderIdList = [];
@@ -12063,17 +12063,17 @@ class StoreOrderRepository extends BaseRepository
12063
                 ];
12063
                 ];
12064
             }
12064
             }
12065
 
12065
 
12066
-            // 5.5 订单操作记录表
12066
+            // 4.6 订单操作记录表
12067
             /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
12067
             /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
12068
             $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
12068
             $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
12069
             $storeOrderStatusRepository->insertAll($storeOrderStatusDataList);
12069
             $storeOrderStatusRepository->insertAll($storeOrderStatusDataList);
12070
 
12070
 
12071
-            // 5.6 订单购物详情表
12071
+            // 4.7 订单购物详情表
12072
             /** @var StoreOrderProductRepository $storeOrderProductRepository */
12072
             /** @var StoreOrderProductRepository $storeOrderProductRepository */
12073
             $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
12073
             $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
12074
             $storeOrderProductRepository->insertAll($storeOrderProductDataList);
12074
             $storeOrderProductRepository->insertAll($storeOrderProductDataList);
12075
 
12075
 
12076
-            // 5.7 支付成功后 发放奖励
12076
+            // 4.8 支付成功后 发放奖励
12077
             // 非现金 支付成功后 直接结算
12077
             // 非现金 支付成功后 直接结算
12078
             if ($paySuccess) {
12078
             if ($paySuccess) {
12079
                 // 修改订单的 支付状态
12079
                 // 修改订单的 支付状态
@@ -12152,7 +12152,7 @@ class StoreOrderRepository extends BaseRepository
12152
         $storeCartRepository = app()->make(StoreCartRepository::class);
12152
         $storeCartRepository = app()->make(StoreCartRepository::class);
12153
         $cartEntityList = $storeCartRepository->getCartEntityListByCartIdList($storeOrderCreateRequestEntity->getCartIdList());
12153
         $cartEntityList = $storeCartRepository->getCartEntityListByCartIdList($storeOrderCreateRequestEntity->getCartIdList());
12154
         if (empty($cartEntityList) || count($storeOrderCreateRequestEntity->getCartIdList()) != count($cartEntityList)) {
12154
         if (empty($cartEntityList) || count($storeOrderCreateRequestEntity->getCartIdList()) != count($cartEntityList)) {
12155
-            throw new ValidateException('获取购物车内容失败');
12155
+            throw new ValidateException('未查询到购物车信息');
12156
         }
12156
         }
12157
 
12157
 
12158
         $merchantIdList = [];
12158
         $merchantIdList = [];
@@ -12213,6 +12213,11 @@ class StoreOrderRepository extends BaseRepository
12213
 
12213
 
12214
         // 确认购物车内 微唯宝 的商品 是否满足发货
12214
         // 确认购物车内 微唯宝 的商品 是否满足发货
12215
         foreach ($cartEntityList as $cartEntity) {
12215
         foreach ($cartEntityList as $cartEntity) {
12216
+            // 验证用户
12217
+            if ($cartEntity->getUid() != $userEntity->getUid()) {
12218
+                throw new ValidateException('获取购物车内容失败');
12219
+            }
12220
+
12216
             // 验证商户
12221
             // 验证商户
12217
             if (empty($merchantEntityMap[$cartEntity->getMerId()])) {
12222
             if (empty($merchantEntityMap[$cartEntity->getMerId()])) {
12218
                 throw new ValidateException('未查询到商户信息');
12223
                 throw new ValidateException('未查询到商户信息');
@@ -12237,6 +12242,10 @@ class StoreOrderRepository extends BaseRepository
12237
             if ($cartEntity->getIsFail() == CartEnum::IS_FAIL['Yes']['code']) {
12242
             if ($cartEntity->getIsFail() == CartEnum::IS_FAIL['Yes']['code']) {
12238
                 throw new ValidateException($productEntity->getStoreName() . ' 已失效');
12243
                 throw new ValidateException($productEntity->getStoreName() . ' 已失效');
12239
             }
12244
             }
12245
+            // 判断订单是否已失效
12246
+            if ($cartEntity->getIsPay() == CartEnum::IS_PAY['Yes']['code']) {
12247
+                throw new ValidateException($productEntity->getStoreName() . ' 已下单');
12248
+            }
12240
 
12249
 
12241
             // 如果商品类型是 普通商品 ,则判断库存是否充足
12250
             // 如果商品类型是 普通商品 ,则判断库存是否充足
12242
             if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
12251
             if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {

+ 3 - 2
app/controller/api/store/order/StoreOrder.php

@@ -115,12 +115,13 @@ class StoreOrder
115
      */
115
      */
116
     public function createOrder(StoreCartRepository $cartRepository)
116
     public function createOrder(StoreCartRepository $cartRepository)
117
     {
117
     {
118
-        $uid = $this->request->uid();
118
+        $uid = 1592;
119
         if (in_array($uid, [1592, 766])) {
119
         if (in_array($uid, [1592, 766])) {
120
-            $request = request();
120
+            $request = new Request();
121
             $storeOrderCreateValidate = new StoreOrderCreateValidate($request);
121
             $storeOrderCreateValidate = new StoreOrderCreateValidate($request);
122
             return $this->createOrderNew($storeOrderCreateValidate);
122
             return $this->createOrderNew($storeOrderCreateValidate);
123
         }
123
         }
124
+        var_dump(123);
124
 
125
 
125
         $cartId = (array)$this->request->param('cart_id', []);
126
         $cartId = (array)$this->request->param('cart_id', []);
126
 
127
 

+ 40 - 40
app/entity/data/user/UserSignScoreEntity.php

@@ -8,19 +8,19 @@ class UserSignScoreEntity extends DataEntity
8
 {
8
 {
9
     public $id = null;  // 自增id
9
     public $id = null;  // 自增id
10
     public $uid = null;  // 会员id
10
     public $uid = null;  // 会员id
11
-    public $continuity_day = null;  // 连续签到几天
12
-    public $reward_score = null;  // 赠送积分数量
13
-    public $signin_time = null;  // 签到时间
14
-    public $source_uid = null;  // 赠送积分来源用户id
11
+    public $continuityDay = null;  // 连续签到几天
12
+    public $rewardScore = null;  // 赠送积分数量
13
+    public $signinTime = null;  // 签到时间
14
+    public $sourceUid = null;  // 赠送积分来源用户id
15
     public $status = null;  // 积分状态1-有效 0-失效 -1待确认
15
     public $status = null;  // 积分状态1-有效 0-失效 -1待确认
16
     public $mark = null;  // 备注
16
     public $mark = null;  // 备注
17
-    public $order_id = null;  // 订单id
17
+    public $orderId = null;  // 订单id
18
     public $pm = null;  // 1-收入。2-支出
18
     public $pm = null;  // 1-收入。2-支出
19
     public $surplus = null;  // 剩余
19
     public $surplus = null;  // 剩余
20
-    public $order_type = null;  // 订单类型。关联订单ID
20
+    public $orderType = null;  // 订单类型。关联订单ID
21
     public $addtime = null;  // 添加时间
21
     public $addtime = null;  // 添加时间
22
-    public $source_type = null;  // 积分类型:1签到,2分享好友注册赠送,3自己下单赠送,4,好友下单赠送,5.购买产品消耗
23
-    public $settlement_time = null;  // 结算时间
22
+    public $sourceType = null;  // 积分类型:1签到,2分享好友注册赠送,3自己下单赠送,4,好友下单赠送,5.购买产品消耗
23
+    public $settlementTime = null;  // 结算时间
24
 
24
 
25
     /**
25
     /**
26
      * @return mixed
26
      * @return mixed
@@ -63,16 +63,16 @@ class UserSignScoreEntity extends DataEntity
63
      */
63
      */
64
     public function getContinuityDay()
64
     public function getContinuityDay()
65
     {
65
     {
66
-        return $this->continuity_day;
66
+        return $this->continuityDay;
67
     }
67
     }
68
 
68
 
69
     /**
69
     /**
70
-     * @param mixed $continuity_day
70
+     * @param mixed $continuityDay
71
      * @return UserSignScoreEntity
71
      * @return UserSignScoreEntity
72
      */
72
      */
73
-    public function setContinuityDay($continuity_day): UserSignScoreEntity
73
+    public function setContinuityDay($continuityDay): UserSignScoreEntity
74
     {
74
     {
75
-        $this->continuity_day = $continuity_day;
75
+        $this->continuityDay = $continuityDay;
76
         return $this;
76
         return $this;
77
     }
77
     }
78
 
78
 
@@ -81,16 +81,16 @@ class UserSignScoreEntity extends DataEntity
81
      */
81
      */
82
     public function getRewardScore()
82
     public function getRewardScore()
83
     {
83
     {
84
-        return $this->reward_score;
84
+        return $this->rewardScore;
85
     }
85
     }
86
 
86
 
87
     /**
87
     /**
88
-     * @param mixed $reward_score
88
+     * @param mixed $rewardScore
89
      * @return UserSignScoreEntity
89
      * @return UserSignScoreEntity
90
      */
90
      */
91
-    public function setRewardScore($reward_score): UserSignScoreEntity
91
+    public function setRewardScore($rewardScore): UserSignScoreEntity
92
     {
92
     {
93
-        $this->reward_score = $reward_score;
93
+        $this->rewardScore = $rewardScore;
94
         return $this;
94
         return $this;
95
     }
95
     }
96
 
96
 
@@ -99,16 +99,16 @@ class UserSignScoreEntity extends DataEntity
99
      */
99
      */
100
     public function getSigninTime()
100
     public function getSigninTime()
101
     {
101
     {
102
-        return $this->signin_time;
102
+        return $this->signinTime;
103
     }
103
     }
104
 
104
 
105
     /**
105
     /**
106
-     * @param mixed $signin_time
106
+     * @param mixed $signinTime
107
      * @return UserSignScoreEntity
107
      * @return UserSignScoreEntity
108
      */
108
      */
109
-    public function setSigninTime($signin_time): UserSignScoreEntity
109
+    public function setSigninTime($signinTime): UserSignScoreEntity
110
     {
110
     {
111
-        $this->signin_time = $signin_time;
111
+        $this->signinTime = $signinTime;
112
         return $this;
112
         return $this;
113
     }
113
     }
114
 
114
 
@@ -117,16 +117,16 @@ class UserSignScoreEntity extends DataEntity
117
      */
117
      */
118
     public function getSourceUid()
118
     public function getSourceUid()
119
     {
119
     {
120
-        return $this->source_uid;
120
+        return $this->sourceUid;
121
     }
121
     }
122
 
122
 
123
     /**
123
     /**
124
-     * @param mixed $source_uid
124
+     * @param mixed $sourceUid
125
      * @return UserSignScoreEntity
125
      * @return UserSignScoreEntity
126
      */
126
      */
127
-    public function setSourceUid($source_uid): UserSignScoreEntity
127
+    public function setSourceUid($sourceUid): UserSignScoreEntity
128
     {
128
     {
129
-        $this->source_uid = $source_uid;
129
+        $this->sourceUid = $sourceUid;
130
         return $this;
130
         return $this;
131
     }
131
     }
132
 
132
 
@@ -171,16 +171,16 @@ class UserSignScoreEntity extends DataEntity
171
      */
171
      */
172
     public function getOrderId()
172
     public function getOrderId()
173
     {
173
     {
174
-        return $this->order_id;
174
+        return $this->orderId;
175
     }
175
     }
176
 
176
 
177
     /**
177
     /**
178
-     * @param mixed $order_id
178
+     * @param mixed $orderId
179
      * @return UserSignScoreEntity
179
      * @return UserSignScoreEntity
180
      */
180
      */
181
-    public function setOrderId($order_id): UserSignScoreEntity
181
+    public function setOrderId($orderId): UserSignScoreEntity
182
     {
182
     {
183
-        $this->order_id = $order_id;
183
+        $this->orderId = $orderId;
184
         return $this;
184
         return $this;
185
     }
185
     }
186
 
186
 
@@ -225,16 +225,16 @@ class UserSignScoreEntity extends DataEntity
225
      */
225
      */
226
     public function getOrderType()
226
     public function getOrderType()
227
     {
227
     {
228
-        return $this->order_type;
228
+        return $this->orderType;
229
     }
229
     }
230
 
230
 
231
     /**
231
     /**
232
-     * @param mixed $order_type
232
+     * @param mixed $orderType
233
      * @return UserSignScoreEntity
233
      * @return UserSignScoreEntity
234
      */
234
      */
235
-    public function setOrderType($order_type): UserSignScoreEntity
235
+    public function setOrderType($orderType): UserSignScoreEntity
236
     {
236
     {
237
-        $this->order_type = $order_type;
237
+        $this->orderType = $orderType;
238
         return $this;
238
         return $this;
239
     }
239
     }
240
 
240
 
@@ -261,16 +261,16 @@ class UserSignScoreEntity extends DataEntity
261
      */
261
      */
262
     public function getSourceType()
262
     public function getSourceType()
263
     {
263
     {
264
-        return $this->source_type;
264
+        return $this->sourceType;
265
     }
265
     }
266
 
266
 
267
     /**
267
     /**
268
-     * @param mixed $source_type
268
+     * @param mixed $sourceType
269
      * @return UserSignScoreEntity
269
      * @return UserSignScoreEntity
270
      */
270
      */
271
-    public function setSourceType($source_type): UserSignScoreEntity
271
+    public function setSourceType($sourceType): UserSignScoreEntity
272
     {
272
     {
273
-        $this->source_type = $source_type;
273
+        $this->sourceType = $sourceType;
274
         return $this;
274
         return $this;
275
     }
275
     }
276
 
276
 
@@ -279,16 +279,16 @@ class UserSignScoreEntity extends DataEntity
279
      */
279
      */
280
     public function getSettlementTime()
280
     public function getSettlementTime()
281
     {
281
     {
282
-        return $this->settlement_time;
282
+        return $this->settlementTime;
283
     }
283
     }
284
 
284
 
285
     /**
285
     /**
286
-     * @param mixed $settlement_time
286
+     * @param mixed $settlementTime
287
      * @return UserSignScoreEntity
287
      * @return UserSignScoreEntity
288
      */
288
      */
289
-    public function setSettlementTime($settlement_time): UserSignScoreEntity
289
+    public function setSettlementTime($settlementTime): UserSignScoreEntity
290
     {
290
     {
291
-        $this->settlement_time = $settlement_time;
291
+        $this->settlementTime = $settlementTime;
292
         return $this;
292
         return $this;
293
     }
293
     }
294
 }
294
 }