|
|
@@ -804,93 +804,115 @@ class StoreGroupOrderRepository extends BaseRepository
|
|
804
|
804
|
->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
|
|
805
|
805
|
|
|
806
|
806
|
// 4、写入数据
|
|
807
|
|
- Db::startTrans();
|
|
808
|
807
|
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;
|
|
|
808
|
+ Db::transaction(function () use (
|
|
|
809
|
+ $productRepository,
|
|
|
810
|
+ $productAttrValueRepository,
|
|
|
811
|
+ $storeCartRepository,
|
|
|
812
|
+ $storeGroupOrderRepository,
|
|
|
813
|
+ $storeOrderRepository,
|
|
|
814
|
+ $productStockList,
|
|
|
815
|
+ $productAttrValueStockList,
|
|
|
816
|
+ $cartIdList,
|
|
|
817
|
+ $storeGroupOrderEntity,
|
|
|
818
|
+ $storeOrderEntityList,
|
|
|
819
|
+ $storeOrderCreateRequestEntity,
|
|
|
820
|
+ $userEntity,
|
|
|
821
|
+ $cartEntityMap,
|
|
|
822
|
+ $storeProductEntityMap,
|
|
|
823
|
+ $storeProductAttrValueEntityMap
|
|
|
824
|
+ ) {
|
|
|
825
|
+ // 4.1 更细库存
|
|
|
826
|
+ foreach ($productStockList as $item) {
|
|
|
827
|
+ $productRepository->descStock($item['productId'], $item['cartNum']);
|
|
|
828
|
+ }
|
|
|
829
|
+ foreach ($productAttrValueStockList as $item) {
|
|
|
830
|
+ $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
|
|
838
|
831
|
}
|
|
839
|
832
|
|
|
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
|
|
- }
|
|
|
833
|
+ // 4.2 修改 购物车状态
|
|
|
834
|
+ $storeCartRepository->updateIsPayByCartIdList($cartIdList);
|
|
|
835
|
+
|
|
|
836
|
+ // 4.3 写入 组合订单 (支付订单)
|
|
|
837
|
+ $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
|
|
|
838
|
+
|
|
|
839
|
+ // 4.5 写入订单数据
|
|
|
840
|
+ $storeOrderStatusEntityList = [];
|
|
|
841
|
+ $storeOrderProductEntityList = [];
|
|
|
842
|
+ $paySuccess = true; // 是否已完成支付 并支付成功
|
|
|
843
|
+ foreach ($storeOrderEntityList as $key => $storeOrderEntity) {
|
|
|
844
|
+ // 将订单数据 写入数据库 并完善实体
|
|
|
845
|
+ $storeOrderEntity->setGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
|
|
|
846
|
+ $storeOrderEntity = $storeOrderRepository->createByEntity($storeOrderEntity);
|
|
|
847
|
+
|
|
|
848
|
+ // 4.4 验证是否 可以进行支付 因为历史的 用户资金(佣金、养老金、积分、VR等)扣减所绑定的orderId都是订单ID
|
|
|
849
|
+ /** @var FzonePayTypeEntity $fzonePayTypeEntity */
|
|
|
850
|
+ $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
|
|
|
851
|
+ // 当有一笔支付失败时,默认整个 订单组 没有 "完全" 支付成功
|
|
|
852
|
+ if (!$storeOrderRepository->abatement($userEntity, $storeOrderEntity, $fzonePayTypeEntity)) {
|
|
|
853
|
+ $paySuccess = false;
|
|
|
854
|
+ }
|
|
|
855
|
+
|
|
|
856
|
+ // 将每件商品设计到的优惠券要取消掉
|
|
|
857
|
+
|
|
|
858
|
+ // 准备订单的 状态数据
|
|
|
859
|
+ $storeOrderStatusEntityList[] = StoreOrderStatusEntity::newInstance()
|
|
|
860
|
+ ->setOrderId($storeOrderEntity->getOrderId())
|
|
|
861
|
+ ->setChangeType(StoreOrderStatusEnum::CHANGE_TYPE['Create']['code'])
|
|
|
862
|
+ ->setChangeMessage(StoreOrderStatusEnum::CHANGE_TYPE['Create']['name']);
|
|
|
863
|
+
|
|
|
864
|
+ // 获取当前 订单绑定的购物车
|
|
|
865
|
+ $cartEntity = $cartEntityMap[$storeOrderEntity->getCartId()];
|
|
|
866
|
+ // 准备订单的 订单购物详情表
|
|
|
867
|
+ $storeOrderProductEntityList[] = StoreOrderProductEntity::newInstance()
|
|
|
868
|
+ ->setOrderId($storeOrderEntity->getOrderId())
|
|
|
869
|
+ ->setCartId($storeOrderEntity->getCartId())
|
|
|
870
|
+ ->setUid($storeOrderEntity->getUid())
|
|
|
871
|
+ ->setProductId($cartEntity->getProductId())
|
|
|
872
|
+ ->setProductPrice($storeOrderEntity->getTotalPrice())
|
|
|
873
|
+ ->setExtensionOne(0.00)
|
|
|
874
|
+ ->setExtensionTwo(0.00)
|
|
|
875
|
+ ->setProductSku($cartEntity->getProductAttrUnique())
|
|
|
876
|
+ ->setProductNum($cartEntity->getCartNum())
|
|
|
877
|
+ ->setRefundNum($cartEntity->getCartNum())
|
|
|
878
|
+ ->setType($storeProductEntityMap[$cartEntity->getProductId()]->getType())
|
|
|
879
|
+ ->setCartInfo(json_encode([
|
|
|
880
|
+ 'product' => $storeProductEntityMap[$cartEntity->getProductId()]->toUnderlineArray(),
|
|
|
881
|
+ 'productAttr' => $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()]->toUnderlineArray(),
|
|
|
882
|
+ 'product_type' => $cartEntity->getProductType()
|
|
|
883
|
+ ]));
|
|
870
|
884
|
|
|
871
|
|
- // 4.6 订单操作记录表
|
|
872
|
|
- /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
|
|
873
|
|
- $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
|
874
|
|
- $storeOrderStatusRepository->createByEntityList($storeOrderStatusEntityList);
|
|
|
885
|
+ }
|
|
875
|
886
|
|
|
876
|
|
- // 4.7 订单购物详情表
|
|
877
|
|
- /** @var StoreOrderProductRepository $storeOrderProductRepository */
|
|
878
|
|
- $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
|
|
879
|
|
- $storeOrderProductRepository->createByEntityList($storeOrderProductEntityList);
|
|
|
887
|
+ // 4.6 订单操作记录表
|
|
|
888
|
+ /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
|
|
|
889
|
+ $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
|
|
890
|
+ $storeOrderStatusRepository->createByEntityList($storeOrderStatusEntityList);
|
|
880
|
891
|
|
|
881
|
|
- // 4.8 支付成功后 发放奖励
|
|
882
|
|
- // 非现金 支付成功后 直接结算
|
|
883
|
|
- if ($paySuccess) {
|
|
884
|
|
- $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
|
|
885
|
|
- }
|
|
|
892
|
+ // 4.7 订单购物详情表
|
|
|
893
|
+ /** @var StoreOrderProductRepository $storeOrderProductRepository */
|
|
|
894
|
+ $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
|
|
|
895
|
+ $storeOrderProductRepository->createByEntityList($storeOrderProductEntityList);
|
|
886
|
896
|
|
|
887
|
|
- Db::commit();
|
|
888
|
|
- } catch (DbException $e) {
|
|
889
|
|
- Db::rollback();
|
|
|
897
|
+ // 4.8 支付成功后 发放奖励
|
|
|
898
|
+ // 非现金 支付成功后 直接结算
|
|
|
899
|
+ if ($paySuccess) {
|
|
|
900
|
+ $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
|
|
|
901
|
+ }
|
|
|
902
|
+ });
|
|
|
903
|
+ } catch (\Throwable $e) {
|
|
890
|
904
|
Log::error('StoreGroupOrderRepository-createStoreGroupOrder:' . $e->getMessage());
|
|
|
905
|
+ return [
|
|
|
906
|
+ 'code' => 10001,
|
|
|
907
|
+ 'message' => $e->getMessage(),
|
|
|
908
|
+ 'data' => []
|
|
|
909
|
+ ];
|
|
891
|
910
|
}
|
|
892
|
|
- return ['order_id' => $storeGroupOrderEntity->getGroupOrderId(), 'groupOrder' => $storeGroupOrderEntity->toArray()];
|
|
893
|
|
-
|
|
|
911
|
+ return [
|
|
|
912
|
+ 'code' => 0,
|
|
|
913
|
+ 'message' => '订单创建成功',
|
|
|
914
|
+ 'data' => ['order_id' => $storeGroupOrderEntity->getGroupOrderId(), 'groupOrder' => $storeGroupOrderEntity->toArray()]
|
|
|
915
|
+ ];
|
|
894
|
916
|
}
|
|
895
|
917
|
|
|
896
|
918
|
/**
|