Przeglądaj źródła

Merge branch 'refs/heads/master' into dev

sunxbiao 5 miesięcy temu
rodzic
commit
d9181ed33b

+ 127 - 92
app/common/repositories/store/order/StoreGroupOrderRepository.php

@@ -178,20 +178,33 @@ class StoreGroupOrderRepository extends BaseRepository
178 178
         }
179 179
 
180 180
         // 3、逻辑处理
181
-        Db::startTrans();
182 181
         try {
183
-            // 软 删除订单组
184
-            $storeGroupOrderEntity->setIsDel(StoreGroupOrderEnum::IS_DEL['Yes']['code']);
185
-            $this->update($storeGroupOrderEntity->getGroupOrderId(), $storeGroupOrderEntity->toUnderlineArray());
186
-
187
-            // 循环关闭订单组内的数据
188
-            foreach ($storeOrderEntityList as $storeOrderEntity) {
189
-                $storeOrderRepository->closeStoreOrder($storeOrderEntity, $uid, $changeMessage, $remark);
190
-            }
191
-
192
-            Db::commit();
193
-        } catch (DbException $e) {
194
-            Db::rollback();
182
+            Db::transaction(function () use (
183
+                $storeOrderRepository,
184
+                $storeGroupOrderEntity,
185
+                $storeOrderEntityList,
186
+                $uid,
187
+                $changeMessage,
188
+                $remark
189
+            ) {
190
+                // 软 删除订单组
191
+                $storeGroupOrderEntity->setIsDel(StoreGroupOrderEnum::IS_DEL['Yes']['code']);
192
+                $this->update($storeGroupOrderEntity->getGroupOrderId(), $storeGroupOrderEntity->toUnderlineArray());
193
+
194
+                // 循环关闭订单组内的数据
195
+                foreach ($storeOrderEntityList as $storeOrderEntity) {
196
+                    $storeOrderRepository->closeStoreOrder($storeOrderEntity, $uid, $changeMessage, $remark);
197
+                }
198
+            });
199
+        } catch (\Throwable $e) {
200
+            throw new ValidateException('关闭订单失败:' . json_encode([
201
+                    'error_message' => $e->getMessage(),
202
+                    'error_file' => $e->getFile(),
203
+                    'error_line' => $e->getLine(),
204
+                    'error_code' => $e->getCode(),
205
+                    'exception_class' => get_class($e),
206
+                    'trace' => $e->getTraceAsString()
207
+                ], JSON_UNESCAPED_UNICODE));
195 208
         }
196 209
 
197 210
         // $groupOrder = $this->search(['paid' => 0, 'uid' => $uid ?: ''])->where('group_order_id', $id)->with(['orderList'])->find();
@@ -770,7 +783,7 @@ class StoreGroupOrderRepository extends BaseRepository
770 783
                 ->setCost($cost)
771 784
                 ->setMerMoney($merMoney)
772 785
                 ->setPayType($storeOrderCreateRequestEntity->getPayType())
773
-                ->setShareId($storeOrderCreateRequestEntity->getShareId())
786
+                ->setShareId($shareEntity->getId())
774 787
                 ->setShareUid($shareEntity->getUid())
775 788
                 ->setServiceMoney($serviceMoney)
776 789
                 ->setTestOrder($userEntity->getTestUser())
@@ -804,93 +817,115 @@ class StoreGroupOrderRepository extends BaseRepository
804 817
             ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
805 818
 
806 819
         // 4、写入数据
807
-        Db::startTrans();
808 820
         try {
809
-            // 4.1 更细库存
810
-            foreach ($productStockList as $item) {
811
-                $productRepository->descStock($item['productId'], $item['cartNum']);
812
-            }
813
-            foreach ($productAttrValueStockList as $item) {
814
-                $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
815
-            }
816
-
817
-            // 4.2 修改 购物车状态
818
-            $storeCartRepository->updateIsPayByCartIdList($cartIdList);
819
-
820
-            // 4.3 写入 组合订单 (支付订单)
821
-            $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
822
-
823
-            // 4.5 写入订单数据
824
-            $storeOrderStatusEntityList = [];
825
-            $storeOrderProductEntityList = [];
826
-            $paySuccess = true; // 是否已完成支付 并支付成功
827
-            foreach ($storeOrderEntityList as $key => $storeOrderEntity) {
828
-                // 将订单数据 写入数据库 并完善实体
829
-                $storeOrderEntity->setGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
830
-                $storeOrderEntity = $storeOrderRepository->createByEntity($storeOrderEntity);
831
-
832
-                // 4.4 验证是否 可以进行支付 因为历史的 用户资金(佣金、养老金、积分、VR等)扣减所绑定的orderId都是订单ID
833
-                /** @var FzonePayTypeEntity $fzonePayTypeEntity */
834
-                $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
835
-                // 当有一笔支付失败时,默认整个 订单组 没有 "完全" 支付成功
836
-                if (!$storeOrderRepository->abatement($userEntity, $storeOrderEntity, $fzonePayTypeEntity)) {
837
-                    $paySuccess = false;
821
+            Db::transaction(function () use (
822
+                $productRepository,
823
+                $productAttrValueRepository,
824
+                $storeCartRepository,
825
+                $storeGroupOrderRepository,
826
+                $storeOrderRepository,
827
+                $productStockList,
828
+                $productAttrValueStockList,
829
+                $cartIdList,
830
+                &$storeGroupOrderEntity,
831
+                $storeOrderEntityList,
832
+                $storeOrderCreateRequestEntity,
833
+                $userEntity,
834
+                $cartEntityMap,
835
+                $storeProductEntityMap,
836
+                $storeProductAttrValueEntityMap
837
+            ) {
838
+                // 4.1 更细库存
839
+                foreach ($productStockList as $item) {
840
+                    $productRepository->descStock($item['productId'], $item['cartNum']);
841
+                }
842
+                foreach ($productAttrValueStockList as $item) {
843
+                    $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
838 844
                 }
839 845
 
840
-                // 将每件商品设计到的优惠券要取消掉
841
-
842
-                // 准备订单的 状态数据
843
-                $storeOrderStatusEntityList[] = StoreOrderStatusEntity::newInstance()
844
-                    ->setOrderId($storeOrderEntity->getOrderId())
845
-                    ->setChangeType(StoreOrderStatusEnum::CHANGE_TYPE['Create']['code'])
846
-                    ->setChangeMessage(StoreOrderStatusEnum::CHANGE_TYPE['Create']['name']);
847
-
848
-                // 获取当前 订单绑定的购物车
849
-                $cartEntity = $cartEntityMap[$storeOrderEntity->getCartId()];
850
-                // 准备订单的 订单购物详情表
851
-                $storeOrderProductEntityList[] = StoreOrderProductEntity::newInstance()
852
-                    ->setOrderId($storeOrderEntity->getOrderId())
853
-                    ->setCartId($storeOrderEntity->getCartId())
854
-                    ->setUid($storeOrderEntity->getUid())
855
-                    ->setProductId($cartEntity->getProductId())
856
-                    ->setProductPrice($storeOrderEntity->getTotalPrice())
857
-                    ->setExtensionOne(0.00)
858
-                    ->setExtensionTwo(0.00)
859
-                    ->setProductSku($cartEntity->getProductAttrUnique())
860
-                    ->setProductNum($cartEntity->getCartNum())
861
-                    ->setRefundNum($cartEntity->getCartNum())
862
-                    ->setType($storeProductEntityMap[$cartEntity->getProductId()]->getType())
863
-                    ->setCartInfo(json_encode([
864
-                        'product' => $storeProductEntityMap[$cartEntity->getProductId()]->toUnderlineArray(),
865
-                        'productAttr' => $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()]->toUnderlineArray(),
866
-                        'product_type' => $cartEntity->getProductType()
867
-                    ]));
868
-
869
-            }
846
+                // 4.2 修改 购物车状态
847
+                $storeCartRepository->updateIsPayByCartIdList($cartIdList);
848
+
849
+                // 4.3 写入 组合订单 (支付订单)
850
+                $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
851
+
852
+                // 4.5 写入订单数据
853
+                $storeOrderStatusEntityList = [];
854
+                $storeOrderProductEntityList = [];
855
+                $paySuccess = true; // 是否已完成支付 并支付成功
856
+                foreach ($storeOrderEntityList as $key => $storeOrderEntity) {
857
+                    // 将订单数据 写入数据库 并完善实体
858
+                    $storeOrderEntity->setGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
859
+                    $storeOrderEntity = $storeOrderRepository->createByEntity($storeOrderEntity);
860
+
861
+                    // 4.4 验证是否 可以进行支付 因为历史的 用户资金(佣金、养老金、积分、VR等)扣减所绑定的orderId都是订单ID
862
+                    /** @var FzonePayTypeEntity $fzonePayTypeEntity */
863
+                    $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
864
+                    // 当有一笔支付失败时,默认整个 订单组 没有 "完全" 支付成功
865
+                    if (!$storeOrderRepository->abatement($userEntity, $storeOrderEntity, $fzonePayTypeEntity)) {
866
+                        $paySuccess = false;
867
+                    }
868
+
869
+                    // 将每件商品设计到的优惠券要取消掉
870
+
871
+                    // 准备订单的 状态数据
872
+                    $storeOrderStatusEntityList[] = StoreOrderStatusEntity::newInstance()
873
+                        ->setOrderId($storeOrderEntity->getOrderId())
874
+                        ->setChangeType(StoreOrderStatusEnum::CHANGE_TYPE['Create']['code'])
875
+                        ->setChangeMessage(StoreOrderStatusEnum::CHANGE_TYPE['Create']['name']);
876
+
877
+                    // 获取当前 订单绑定的购物车
878
+                    $cartEntity = $cartEntityMap[$storeOrderEntity->getCartId()];
879
+                    // 准备订单的 订单购物详情表
880
+                    $storeOrderProductEntityList[] = StoreOrderProductEntity::newInstance()
881
+                        ->setOrderId($storeOrderEntity->getOrderId())
882
+                        ->setCartId($storeOrderEntity->getCartId())
883
+                        ->setUid($storeOrderEntity->getUid())
884
+                        ->setProductId($cartEntity->getProductId())
885
+                        ->setProductPrice($storeOrderEntity->getTotalPrice())
886
+                        ->setExtensionOne(0.00)
887
+                        ->setExtensionTwo(0.00)
888
+                        ->setProductSku($cartEntity->getProductAttrUnique())
889
+                        ->setProductNum($cartEntity->getCartNum())
890
+                        ->setRefundNum($cartEntity->getCartNum())
891
+                        ->setType($storeProductEntityMap[$cartEntity->getProductId()]->getType())
892
+                        ->setCartInfo(json_encode([
893
+                            'product' => $storeProductEntityMap[$cartEntity->getProductId()]->toUnderlineArray(),
894
+                            'productAttr' => $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()]->toUnderlineArray(),
895
+                            'product_type' => $cartEntity->getProductType()
896
+                        ]));
870 897
 
871
-            // 4.6 订单操作记录表
872
-            /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
873
-            $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
874
-            $storeOrderStatusRepository->createByEntityList($storeOrderStatusEntityList);
898
+                }
875 899
 
876
-            // 4.7 订单购物详情表
877
-            /** @var StoreOrderProductRepository $storeOrderProductRepository */
878
-            $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
879
-            $storeOrderProductRepository->createByEntityList($storeOrderProductEntityList);
900
+                // 4.6 订单操作记录表
901
+                /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
902
+                $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
903
+                $storeOrderStatusRepository->createByEntityList($storeOrderStatusEntityList);
880 904
 
881
-            // 4.8 支付成功后 发放奖励
882
-            // 非现金 支付成功后 直接结算
883
-            if ($paySuccess) {
884
-                $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
885
-            }
905
+                // 4.7 订单购物详情表
906
+                /** @var StoreOrderProductRepository $storeOrderProductRepository */
907
+                $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
908
+                $storeOrderProductRepository->createByEntityList($storeOrderProductEntityList);
886 909
 
887
-            Db::commit();
888
-        } catch (DbException $e) {
889
-            Db::rollback();
910
+                // 4.8 支付成功后 发放奖励
911
+                // 非现金 支付成功后 直接结算
912
+                if ($paySuccess) {
913
+                    $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
914
+                }
915
+            });
916
+        } catch (\Throwable  $e) {
890 917
             Log::error('StoreGroupOrderRepository-createStoreGroupOrder:' . $e->getMessage());
918
+            return [
919
+                'code' => 10001,
920
+                'message' => $e->getMessage(),
921
+                'data' => []
922
+            ];
891 923
         }
892
-        return ['order_id' => $storeGroupOrderEntity->getGroupOrderId(), 'groupOrder' => $storeGroupOrderEntity->toArray()];
893
-
924
+        return [
925
+            'code' => 0,
926
+            'message' => '订单创建成功',
927
+            'data' => ['order_id' => $storeGroupOrderEntity->getGroupOrderId(), 'groupOrder' => $storeGroupOrderEntity->toArray()]
928
+        ];
894 929
     }
895 930
 
896 931
     /**

+ 9 - 2
app/common/repositories/store/order/StoreOrderRepository.php

@@ -12313,8 +12313,15 @@ class StoreOrderRepository extends BaseRepository
12313 12313
 
12314 12314
             // 5、撤回订单扣除的数据项
12315 12315
             $this->cancellation($userEntity, $storeOrderEntity, $fzonePayTypeEntity);
12316
-        } catch (DbException $e) {
12317
-            throw new ValidateException('支付失败,支付方式错误!');
12316
+        } catch (\Throwable $e) {
12317
+            throw new ValidateException('关闭订单失败:' . json_encode([
12318
+                    'error_message' => $e->getMessage(),
12319
+                    'error_file' => $e->getFile(),
12320
+                    'error_line' => $e->getLine(),
12321
+                    'error_code' => $e->getCode(),
12322
+                    'exception_class' => get_class($e),
12323
+                    'trace' => $e->getTraceAsString()
12324
+                ], JSON_UNESCAPED_UNICODE));
12318 12325
         }
12319 12326
     }
12320 12327
 

+ 7 - 1
app/common/repositories/store/product/ProductRepository.php

@@ -7,6 +7,7 @@
7 7
 
8 8
 namespace app\common\repositories\store\product;
9 9
 
10
+use app\common\enum\CommonEnum;
10 11
 use app\common\model\store\order\StoreOrder;
11 12
 use app\common\model\store\product\Product;
12 13
 use app\common\model\store\product\ProductContent;
@@ -1052,7 +1053,12 @@ class ProductRepository extends BaseRepository
1052 1053
         }
1053 1054
 
1054 1055
 
1055
-
1056
+        // 共富商品处理
1057
+        if ($res['mer_id'] == 3447) {
1058
+            $res['yanglao'] = bcmul($res['price'], CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['YangLaoJin']['Ratio']['code'], 2);
1059
+            $k['jifen'] = 0;
1060
+            $k['gongxian'] = 0;
1061
+        }
1056 1062
 
1057 1063
         $res['pv']=($k['pv']);
1058 1064
         $res['jifen']=($k['jifen']);

+ 4 - 0
app/common/repositories/system/merchant/MerchantRepository.php

@@ -12,6 +12,7 @@ namespace app\common\repositories\system\merchant;
12 12
 
13 13
 
14 14
 use app\common\dao\system\merchant\MerchantDao;
15
+use app\common\enum\CommonEnum;
15 16
 use app\common\model\store\product\ProductReply;
16 17
 use app\common\repositories\BaseRepository;
17 18
 use app\common\repositories\store\product\ProductCopyRepository;
@@ -501,6 +502,9 @@ class MerchantRepository extends BaseRepository
501 502
                         3=>$v['price']//复购金
502 503
                     ]
503 504
                 ];
505
+            }else if ($productMerId == 3447) {
506
+                $yanglao = bcmul($v['price'], CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['YangLaoJin']['Ratio']['code'], 2);
507
+                $v['yanglao'] = $yanglao;
504 508
             }
505 509
 
506 510
 //            $v=($v,$k);

+ 77 - 74
app/controller/api/Notify.php

@@ -127,85 +127,87 @@ class Notify
127 127
                             }
128 128
                             break;
129 129
                         case 'pay':
130
-                            $group_order = Db::name('store_group_order')->where('group_order_sn', $requestId[0])->find();
131
-                            $uid = $group_order['uid'];
132
-                            if (in_array($uid, [1592, 766, 6, 783, 7, 1166, 4604, 4782])) {
133
-                                /** ************** 定义参数 ************** */
134
-                                // 订单编号
135
-                                $groupOrderSn_Rand = $post_data_str['order_no'];
136
-                                // 订单号
137
-                                $groupOrderSn = $requestId[0];
138
-                                // 随机值
139
-                                $rand = $requestId[1];
140
-                                // 支付人ID
141
-                                $payOpenId = $post_data_str['expend']['open_id'];
142
-                                // 支付撤销方法
143
-                                $paymentReverseFunc = function ($payWX, $payType, $groupOrderSn_Rand, $paymentId, $appId, $orderNo, $reverseAmt, $notifyUrl = '') {
144
-                                    if ($payWX == StoreGroupOrderEnum::PAY_WX['TDYL']['code']) {
145
-                                        $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
146
-                                    } else {
147
-                                        $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
148
-                                    }
149
-                                    $refundTraits = [
150
-                                        'payment_id' => $paymentId,
151
-                                        'app_id' => $appId,
152
-                                        'order_no' => $orderNo,
153
-                                        'reverse_amt' => $reverseAmt,
154
-                                        'notify_url' => $notifyUrl ?: env('APP_URL') . "/api/hf_notify/reverse_order",
155
-                                    ];
156
-                                    $hfRefundRes = app()->make(StoreRefundOrderRepository::class)->payment_Reverse($refundTraits, $payType == '1' ? 2 : 1, $payWX, $key);
157
-                                    Db::name("log")
158
-                                        ->insert([
159
-                                            'data' => '【订单支付回调】【03】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';汇付支付撤销请求参数:' . json_encode($refundTraits) . ';汇付支付撤销返回结果:' . json_encode($hfRefundRes)
160
-                                        ]);
161
-                                };
162
-                                /** *************** 定义结束 *************** */
163
-
164
-                                /** 逻辑开始 */
165
-                                // 1、获取订单数据
166
-                                /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
167
-                                $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
168
-                                // 获取订单组数据
169
-                                $storeGroupOrderEntity = $storeGroupOrderRepository->getStoreGroupOrderEntityByGroupOrderSn($groupOrderSn);
170
-                                if (empty($storeGroupOrderEntity->getGroupOrderId())) {
171
-                                    Db::name("log")
172
-                                        ->insert([
173
-                                            'data' => '【订单支付回调】【01】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';订单组查询失败'
174
-                                        ]);
175
-                                    break;
176
-                                }
177
-                                /** @var StoreOrderRepository $storeOrderRepository */
178
-                                $storeOrderRepository = app()->make(StoreOrderRepository::class);
179
-                                // 获取订单集合
180
-                                $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
181
-                                if (empty($storeOrderEntityList)) {
182
-                                    Db::name("log")
183
-                                        ->insert([
184
-                                            'data' => '【订单支付回调】【02】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';订单集合查询失败'
185
-                                        ]);
186
-                                    break;
130
+                            /** ************** 定义参数 ************** */
131
+                            // 订单编号
132
+                            $groupOrderSn_Rand = $post_data_str['order_no'];
133
+                            // 订单号
134
+                            $groupOrderSn = $requestId[0];
135
+                            // 随机值
136
+                            $rand = $requestId[1];
137
+                            // 支付人ID
138
+                            $payOpenId = $post_data_str['expend']['open_id'];
139
+                            // 支付撤销方法
140
+                            $paymentReverseFunc = function ($payWX, $payType, $groupOrderSn_Rand, $paymentId, $appId, $orderNo, $reverseAmt, $notifyUrl = '') {
141
+                                if ($payWX == StoreGroupOrderEnum::PAY_WX['TDYL']['code']) {
142
+                                    $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
143
+                                } else {
144
+                                    $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
187 145
                                 }
146
+                                $refundTraits = [
147
+                                    'payment_id' => $paymentId,
148
+                                    'app_id' => $appId,
149
+                                    'order_no' => $orderNo,
150
+                                    'reverse_amt' => $reverseAmt,
151
+                                    'notify_url' => $notifyUrl ?: env('APP_URL') . "/api/hf_notify/reverse_order",
152
+                                ];
153
+                                $hfRefundRes = app()->make(StoreRefundOrderRepository::class)->payment_Reverse($refundTraits, $payType == '1' ? 2 : 1, $payWX, $key);
154
+                                Db::name("log")
155
+                                    ->insert([
156
+                                        'data' => '【订单支付回调】【03】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';汇付支付撤销请求参数:' . json_encode($refundTraits) . ';汇付支付撤销返回结果:' . json_encode($hfRefundRes)
157
+                                    ]);
158
+                            };
159
+                            /** *************** 定义结束 *************** */
160
+
161
+                            /** 逻辑开始 */
162
+                            // 1、获取订单数据
163
+                            /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
164
+                            $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
165
+                            // 获取订单组数据
166
+                            $storeGroupOrderEntity = $storeGroupOrderRepository->getStoreGroupOrderEntityByGroupOrderSn($groupOrderSn);
167
+                            if (empty($storeGroupOrderEntity->getGroupOrderId())) {
168
+                                Db::name("log")
169
+                                    ->insert([
170
+                                        'data' => '【订单支付回调】【01】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';订单组查询失败'
171
+                                    ]);
172
+                                break;
173
+                            }
174
+                            /** @var StoreOrderRepository $storeOrderRepository */
175
+                            $storeOrderRepository = app()->make(StoreOrderRepository::class);
176
+                            // 获取订单集合
177
+                            $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
178
+                            if (empty($storeOrderEntityList)) {
179
+                                Db::name("log")
180
+                                    ->insert([
181
+                                        'data' => '【订单支付回调】【02】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';订单集合查询失败'
182
+                                    ]);
183
+                                break;
184
+                            }
188 185
 
189
-                                // 2、判断订单是否已经被代付 如果已记录支付人 并且不是自己,则可能有人代付,则将本次的支付撤回
190
-                                foreach ($storeOrderEntityList as $storeOrderEntity) {
191
-                                    if (!empty($storeOrderEntity->getPayOpenId())) {
192
-                                        if ($storeOrderEntity->getPayOpenId() != $payOpenId) {
193
-                                            // 如果已经被用户支付 撤回支付
194
-                                            $orderNo = app()->make(StoreRefundOrderRepository::class)->getNewOrderId();
195
-                                            $paymentReverseFunc($storeGroupOrderEntity->getPayWx(), $pay_type, $groupOrderSn_Rand, $post_data_str['id'], $post['app_id'], $orderNo, $post_data_str['pay_amt']);
196
-                                            break 2;
197
-                                        }
198
-                                    } else {
199
-                                        $storeOrderEntity->setPayOpenId($payOpenId);
186
+                            // 2、判断订单是否已经被代付 如果已记录支付人 并且不是自己,则可能有人代付,则将本次的支付撤回
187
+                            foreach ($storeOrderEntityList as $storeOrderEntity) {
188
+                                if (!empty($storeOrderEntity->getPayOpenId())) {
189
+                                    if ($storeOrderEntity->getPayOpenId() != $payOpenId) {
190
+                                        // 如果已经被用户支付 撤回支付
191
+                                        $orderNo = app()->make(StoreRefundOrderRepository::class)->getNewOrderId();
192
+                                        $paymentReverseFunc($storeGroupOrderEntity->getPayWx(), $pay_type, $groupOrderSn_Rand, $post_data_str['id'], $post['app_id'], $orderNo, $post_data_str['pay_amt']);
193
+                                        break 2;
200 194
                                     }
195
+                                } else {
196
+                                    $storeOrderEntity->setPayOpenId($payOpenId);
201 197
                                 }
202
-                                // 如果已支付 不做后续处理
203
-                                if ($storeGroupOrderEntity->getPaid() == StoreGroupOrderEnum::PAID['YES']['code']) {
204
-                                    break;
205
-                                }
198
+                            }
199
+                            // 如果已支付 不做后续处理
200
+                            if ($storeGroupOrderEntity->getPaid() == StoreGroupOrderEnum::PAID['YES']['code']) {
201
+                                break;
202
+                            }
203
+
204
+                            // 3、支付成功 处理逻辑
205
+                            $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
206
+                            /*
207
+                            $group_order = Db::name('store_group_order')->where('group_order_sn', $requestId[0])->find();
208
+                            $uid = $group_order['uid'];
209
+                            if (in_array($uid, [1592, 766, 6, 783, 7, 1166, 4604, 4782])) {
206 210
 
207
-                                // 3、支付成功 处理逻辑
208
-                                $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
209 211
                             } else {
210 212
                             // 判断代付是否支付过
211 213
                             $group_order = Db::name('store_group_order')->where('group_order_sn', $requestId[0])->find();
@@ -965,6 +967,7 @@ class Notify
965 967
                             event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
966 968
 
967 969
                             }
970
+                            */
968 971
                             break;
969 972
                         case 'pay_channel':
970 973
                             //渠道商

+ 13 - 2
app/controller/api/store/order/StoreGroupOrder.php

@@ -64,7 +64,18 @@ class StoreGroupOrder extends BaseController
64 64
         }
65 65
 
66 66
         // 3、创建订单
67
-        $result = $this->repository->createStoreGroupOrder($storeOrderCreateRequestEntity);
68
-        return app('json')->success('订单创建成功', $result);
67
+        makeLock()->lock();
68
+        try {
69
+            $result = $this->repository->createStoreGroupOrder($storeOrderCreateRequestEntity);
70
+        } catch (\Throwable $e) {
71
+            makeLock()->unlock();
72
+            throw $e;
73
+        }
74
+        makeLock()->unlock();
75
+
76
+        if (!empty($result['code'])) {
77
+            return app('json')->fail($result['message']);
78
+        }
79
+        return app('json')->success($result['message'], $result['data']);
69 80
     }
70 81
 }

+ 19 - 2
app/controller/merchant/store/order/Order.php

@@ -20,6 +20,7 @@ use think\App;
20 20
 use crmeb\basic\BaseController;
21 21
 use app\common\repositories\store\order\StoreOrderRepository as repository;
22 22
 use think\facade\Db;
23
+use think\facade\Log;
23 24
 
24 25
 class Order extends BaseController
25 26
 {
@@ -439,18 +440,34 @@ class Order extends BaseController
439 440
     /**
440 441
      * @param $id
441 442
      * @param StoreGroupOrderRepository $groupOrderRepository
443
+     * @param repository $orderRepository
442 444
      * @return mixed
445
+     * @throws \think\db\exception\DataNotFoundException
446
+     * @throws \think\db\exception\DbException
447
+     * @throws \think\db\exception\ModelNotFoundException
443 448
      * @author xaboy
444 449
      * @day 2020/6/10
445 450
      */
446 451
     public function cancelGroupOrder($id, StoreGroupOrderRepository $groupOrderRepository, StoreOrderRepository $orderRepository)
447 452
     {
448
-        $data = $this->request->params(['change_message','remark']);
453
+        $data = $this->request->params(['change_message', 'remark']);
449 454
         $merId = $this->request->merId();
450 455
         $order = $orderRepository->getWhere(['group_order_id' => $id]);
451 456
         if ($order['mer_id'] != $merId)
452 457
             return app('json')->fail('数据不存在');
453
-        $groupOrderRepository->cancel((int)$id, 0, $data['change_message'], $data['remark']);
458
+        try {
459
+            $groupOrderRepository->cancel((int)$id, 0, $data['change_message'], $data['remark']);
460
+        } catch (\Throwable $e) {
461
+            Log::error('关闭订单失败:' . json_encode([
462
+                    'error_message' => $e->getMessage(),
463
+                    'error_file' => $e->getFile(),
464
+                    'error_line' => $e->getLine(),
465
+                    'error_code' => $e->getCode(),
466
+                    'exception_class' => get_class($e),
467
+                    'trace' => $e->getTraceAsString()
468
+                ], JSON_UNESCAPED_UNICODE));
469
+            return app('json')->fail('关闭订单失败');
470
+        }
454 471
         return app('json')->success('取消成功');
455 472
     }
456 473
 

+ 1 - 0
crmeb/listens/AutoCancelGroupOrderListen.php

@@ -22,6 +22,7 @@ class AutoCancelGroupOrderListen implements ListenerInterface
22 22
 
23 23
     public function handle($event): void
24 24
     {
25
+        /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
25 26
         $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
26 27
         Timer::tick(60000, function () use ($storeGroupOrderRepository) {
27 28
             $timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;