|
|
@@ -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
|
/**
|