Просмотр исходного кода

优化用户下单方法-进行中-注释优惠券相关逻辑(未完成),目前阶段不需要

sunxbiao 1 год назад
Родитель
Сommit
bf4a362f63
1 измененных файлов с 44 добавлено и 82 удалено
  1. 44 82
      app/common/repositories/store/order/StoreOrderRepository.php

+ 44 - 82
app/common/repositories/store/order/StoreOrderRepository.php

@@ -11674,55 +11674,53 @@ class StoreOrderRepository extends BaseRepository
11674 11674
                 }
11675 11675
             }
11676 11676
 
11677
-            // 计算优惠券 ******************
11678
-            // 商品券 优先于 店铺券
11679
-            // 商品券(平台优惠券)
11680
-            if (!isset($storeCouponUserEntityListByMerIdMap[0])) {
11681
-                $storeCouponUserEntityListByMerIdMap[0] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid(0, $cartEntity->getUid());
11682
-            }
11683
-            // 店铺券(满减券)
11684
-            if (!isset($storeCouponUserEntityListByMerIdMap[$merchantEntity->getMerId()])) {
11685
-                // 查询 当前用户 在当前 店铺的 优惠券
11686
-                $storeCouponUserEntityListByMerIdMap[$merchantEntity->getMerId()] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid($merchantEntity->getMerId(), $cartEntity->getUid());
11687
-            }
11688
-
11689
-            if (!empty($storeCouponUserEntityListByMerIdMap[0]) || !empty($storeCouponUserEntityListByMerIdMap[$merchantEntity->getMerId()])) {
11690
-                foreach ([0, $merchantEntity->getMerId()] as $merId) {
11691
-                    foreach ($storeCouponUserEntityListByMerIdMap[$merId] as $storeCouponUserEntity) {
11692
-                        // 如果不能明确当前优惠券的 获取方式 ,则忽略当前的优惠券的有效性
11693
-                        if (empty($storeCouponUserEntity->getType())) {
11694
-                            continue;
11695
-                        }
11696
-                        // 优惠卷关联商品 辅助表
11697
-                        $storeCouponProductEntityList = $storeCouponProductRepository->getStoreCouponProductEntityListByCouponId($storeCouponUserEntity->getCouponId());
11698
-                        if (!empty($storeCouponProductEntityList)) {
11699
-                            // 商品券
11700
-                            foreach ($storeCouponProductEntityList as $storeCouponProductEntity) {
11701
-                                // 如果当前 优惠券 所关联的 商品 是否在当前购买的 该商家的 商品列表中,(没有则说明此条关联记录 无用) 并且当前 该商家内 该商品没有已使用的优惠券
11702
-                                if (in_array($storeCouponProductEntity->getProductId(), array_keys($productPriceByMerIdMap[$merchantEntity->getMerId()])) && !isset($useCouponProduct[$storeCouponProductEntity->getProductId()][$merchantEntity->getMerId()])) {
11703
-                                    // 如果 当前该商家 该商品 的价格 超过了 “最低消费多少金额可用优惠券” 的金额 则记录该优惠金额,并记录该优惠券ID 后续设置为已使用
11704
-                                    if ($productPriceByMerIdMap[$merchantEntity->getMerId()][$storeCouponProductEntity->getProductId()] >= $storeCouponUserEntity->getUseMinPrice()) {
11705
-                                        $couponPrice = bcadd($couponPrice, $storeCouponUserEntity->getCouponPrice(), 2);
11706
-                                        // 一个商家的 一种商品 只能使用一次优惠券
11707
-                                        $useCouponProduct[$storeCouponProductEntity->getProductId()][$merchantEntity->getMerId()] = $storeCouponUserEntity->getCouponUserId();
11708
-                                        break;
11709
-                                    }
11710
-                                }
11711
-                            }
11712
-                        } else {
11713
-                            // 店铺券(平台券-满减券)
11714
-                        }
11715
-
11716
-                    }
11717
-                }
11718
-
11719
-            }
11720
-
11721
-            // 计算养老金 TODO
11722
-            $yanglaojin = bcadd($yanglaojin, $productRepository->yanglaojin($cartEntity->getProductId()), 2);
11677
+            // // 计算优惠券 ******************  优惠券是此步骤(第一步需要考虑的问题,但是目前阶段暂不需要该功能 所以未完成 先注释)
11678
+            // // 商品券 优先于 店铺券
11679
+            // // 商品券(平台优惠券)
11680
+            // if (!isset($storeCouponUserEntityListByMerIdMap[0])) {
11681
+            //     $storeCouponUserEntityListByMerIdMap[0] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid(0, $cartEntity->getUid());
11682
+            // }
11683
+            // // 店铺券(满减券)
11684
+            // if (!isset($storeCouponUserEntityListByMerIdMap[$merchantEntity->getMerId()])) {
11685
+            //     // 查询 当前用户 在当前 店铺的 优惠券
11686
+            //     $storeCouponUserEntityListByMerIdMap[$merchantEntity->getMerId()] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid($merchantEntity->getMerId(), $cartEntity->getUid());
11687
+            // }
11688
+            //
11689
+            // if (!empty($storeCouponUserEntityListByMerIdMap[0]) || !empty($storeCouponUserEntityListByMerIdMap[$merchantEntity->getMerId()])) {
11690
+            //     foreach ([0, $merchantEntity->getMerId()] as $merId) {
11691
+            //         foreach ($storeCouponUserEntityListByMerIdMap[$merId] as $storeCouponUserEntity) {
11692
+            //             // 如果不能明确当前优惠券的 获取方式 ,则忽略当前的优惠券的有效性
11693
+            //             if (empty($storeCouponUserEntity->getType())) {
11694
+            //                 continue;
11695
+            //             }
11696
+            //             // 优惠卷关联商品 辅助表
11697
+            //             $storeCouponProductEntityList = $storeCouponProductRepository->getStoreCouponProductEntityListByCouponId($storeCouponUserEntity->getCouponId());
11698
+            //             if (!empty($storeCouponProductEntityList)) {
11699
+            //                 // 商品券
11700
+            //                 foreach ($storeCouponProductEntityList as $storeCouponProductEntity) {
11701
+            //                     // 如果当前 优惠券 所关联的 商品 是否在当前购买的 该商家的 商品列表中,(没有则说明此条关联记录 无用) 并且当前 该商家内 该商品没有已使用的优惠券
11702
+            //                     if (in_array($storeCouponProductEntity->getProductId(), array_keys($productPriceByMerIdMap[$merchantEntity->getMerId()])) && !isset($useCouponProduct[$storeCouponProductEntity->getProductId()][$cartEntity->getCartId()])) {
11703
+            //                         // 如果 当前该商家 该商品 的价格 超过了 “最低消费多少金额可用优惠券” 的金额 则记录该优惠金额,并记录该优惠券ID 后续设置为已使用
11704
+            //                         if (($productAttrValueEntity->getPrice()) >= $storeCouponUserEntity->getUseMinPrice()) {
11705
+            //                             $couponPrice = bcadd($couponPrice, $storeCouponUserEntity->getCouponPrice(), 2);
11706
+            //                             // 一个商家的 一种商品 只能使用一次优惠券
11707
+            //                             $useCouponProduct[$storeCouponProductEntity->getProductId()][$cartEntity->getCartId()][] = $storeCouponUserEntity->getCouponUserId();
11708
+            //                             break;
11709
+            //                         }
11710
+            //                     }
11711
+            //                 }
11712
+            //             } else {
11713
+            //                 // 店铺券(平台券-满减券)
11714
+            //
11715
+            //             }
11716
+            //         }
11717
+            //     }
11718
+            // }
11723 11719
 
11724 11720
             // 计算单价
11725 11721
             $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), 2);
11722
+            // 计算养老金 注意 此步骤需要传入商品的价格,因为上述 可能对商品的价格发生了改变
11723
+            $yanglaojin = bcadd($yanglaojin, $productRepository->yanglaojin($cartEntity->getProductId(), $price), 2);
11726 11724
             // 计算总价
11727 11725
             $totalPrice = bcadd($totalPrice, $price, 2);
11728 11726
             // 计算总数
@@ -11730,7 +11728,6 @@ class StoreOrderRepository extends BaseRepository
11730 11728
 
11731 11729
             // 如果是 普通商品 product_type 类型 0=普通产品
11732 11730
             if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11733
-                $productPriceByMerIdMap[$cartEntity->getMerId()][$cartEntity->getProductId()] = bcadd($productPriceByMerIdMap[$cartEntity->getMerId()][$cartEntity->getProductId()] ?? 0, $price, 2);
11734 11731
                 $validTotalPrice = bcadd($validTotalPrice, $price, 2);
11735 11732
             }
11736 11733
 
@@ -11807,43 +11804,8 @@ class StoreOrderRepository extends BaseRepository
11807 11804
                 }
11808 11805
             }
11809 11806
 
11810
-            $merchantMap[$cartEntity->getMerId()]['merchantEntity'] = $merchantEntity;
11811
-        }
11812 11807
 
11813
-        // 当前优惠金额
11814
-        $couponPrice = 0.00;
11815
-        // 需要使用掉的优惠券
11816
-        $useCouponProduct = [];
11817 11808
 
11818
-        foreach ($merchantMap as $merId => $item) {
11819
-            // 当前商户的实体信息
11820
-            /** @var MerchantEntity $merchantEntity */
11821
-            $merchantEntity = $item['merchantEntity'];
11822
-
11823
-            // 店铺券
11824
-            // 查询 当前用户 在当前 店铺的 优惠券
11825
-            $storeCouponUserEntityList = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid($merchantEntity->getMerId(), $userEntity->getUid());
11826
-            foreach ($storeCouponUserEntityList as $storeCouponUserEntity) {
11827
-                // 如果不能明确当前优惠券的 获取方式 ,则忽略当前的优惠券的有效性
11828
-                if (empty($storeCouponUserEntity->getType())) {
11829
-                    continue;
11830
-                }
11831
-                // 优惠卷关联商品 辅助表
11832
-                $storeCouponProductEntityList = $storeCouponProductRepository->getStoreCouponProductEntityListByCouponId($storeCouponUserEntity->getCouponId());
11833
-
11834
-                foreach ($storeCouponProductEntityList as $storeCouponProductEntity) {
11835
-                    // 如果当前 优惠券 所关联的 商品 是否在当前购买的 该商家的 商品列表中,(没有则说明此条关联记录 无用) 并且当前 该商家内 该商品没有已使用的优惠券
11836
-                    if (in_array($storeCouponProductEntity->getProductId(), array_keys($productPriceByMerIdMap[$merchantEntity->getMerId()])) && !isset($useCouponProduct[$merchantEntity->getMerId()][$storeCouponProductEntity->getProductId()])) {
11837
-                        // 如果 当前该商家 该商品 的价格 超过了 “最低消费多少金额可用优惠券” 的金额 则记录该优惠金额,并记录该优惠券ID 后续设置为已使用
11838
-                        if ($productPriceByMerIdMap[$merchantEntity->getMerId()][$storeCouponProductEntity->getProductId()] >= $storeCouponUserEntity->getUseMinPrice()) {
11839
-                            $couponPrice = bcadd($couponPrice, $storeCouponUserEntity->getCouponPrice(), 2);
11840
-                            // 一个商家的 一种商品 只能使用一次优惠券
11841
-                            $useCouponProduct[$merchantEntity->getMerId()][$storeCouponProductEntity->getProductId()] = $storeCouponUserEntity->getCouponUserId();
11842
-                            break;
11843
-                        }
11844
-                    }
11845
-                }
11846
-            }
11847 11809
         }
11848 11810
 
11849 11811