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

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

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

+ 69 - 35
app/common/repositories/store/order/StoreOrderRepository.php

@@ -24,6 +24,8 @@ use app\common\repositories\merchant\order\OrderGzcRepository;
24 24
 use app\common\repositories\merchant\order\OrderMerchantRepository;
25 25
 use app\common\repositories\BaseRepository;
26 26
 use app\common\repositories\product\SeckillRepository;
27
+use app\common\repositories\store\coupon\StoreCouponProductRepository;
28
+use app\common\repositories\store\coupon\StoreCouponRepository;
27 29
 use app\common\repositories\store\coupon\StoreCouponUserRepository;
28 30
 use app\common\repositories\store\MerchantTakeRepository;
29 31
 use app\common\repositories\store\product\ProductAttrValueRepository;
@@ -11554,6 +11556,21 @@ class StoreOrderRepository extends BaseRepository
11554 11556
         // 商户设置秒杀商品关联表
11555 11557
         /** @var StoreSeckillActiveRepository $storeSeckillActiveRepository */
11556 11558
         $storeSeckillActiveRepository = app()->make(StoreSeckillActiveRepository::class);
11559
+        // 优惠券 列表(商户or平台)
11560
+        /** @var StoreCouponRepository $storeCouponRepository */
11561
+        $storeCouponRepository = app()->make(StoreCouponRepository::class);
11562
+        // 优惠券 商品 关联表
11563
+        /** @var StoreCouponProductRepository $storeCouponProductRepository */
11564
+        $storeCouponProductRepository = app()->make(StoreCouponProductRepository::class);
11565
+
11566
+        $list = [];
11567
+        $yanglaojin = 0.00;
11568
+        $price = 0.00;
11569
+        $totalPrice = 0.00;
11570
+        $totalNum = 0;
11571
+        $productPriceMap = [];
11572
+        $validTotalPrice = 0.00;
11573
+        $product_cart = [];
11557 11574
 
11558 11575
         foreach ($cartEntityList as $cartEntity) {
11559 11576
             // 验证商户
@@ -11597,9 +11614,12 @@ class StoreOrderRepository extends BaseRepository
11597 11614
                 }
11598 11615
             }
11599 11616
 
11617
+            // 开始 计算 **************
11618
+
11600 11619
             // 计算养老金
11601
-            $yanglaojin = $productRepository->yanglaojin($cartEntity->getProductId());
11620
+            $yanglaojin = bcadd($yanglaojin, $productRepository->yanglaojin($cartEntity->getProductId()), 2);
11602 11621
 
11622
+            // 验证是否是秒杀产品
11603 11623
             if ($productEntity->getSeckill() == ProductEnum::SECKILL['Yes']['code'] && !is_null($productEntity->getDcPrice()) && $productEntity->getDcPrice() > 0.00) {
11604 11624
                 // 获取 在活动期间内的 秒杀活动记录
11605 11625
                 $seckillEntity = $seckillRepository->getSeckillEntityByProductId($cartEntity->getProductId());
@@ -11609,48 +11629,62 @@ class StoreOrderRepository extends BaseRepository
11609 11629
                 }
11610 11630
             }
11611 11631
 
11612
-            // TODO 写到这了,对应 StoreCartRepository.php 的 70 的else 内
11613
-
11614
-        }
11615
-
11616
-
11632
+            // // 将商户 存贮
11633
+            // $merchantEntityArr = $merchantEntity->toArray();
11634
+            //
11635
+            // // 这块有问题???? 这个优惠券查出来的意义是什么,而且这种组合方式也有问题 一个商户假如有多个商品
11636
+            // // 获取 当前消费者 有没有 从该商家发型的优惠券里 进行领取
11637
+            // $couponCountByMerIdUid = $storeCouponRepository->validMerCouponExists($cartEntity->getMerId(), $cartEntity->getUid());
11638
+            // if ($couponCountByMerIdUid > 0) {
11639
+            //     $merchantEntityArr['hasCoupon'] = $couponCountByMerIdUid;
11640
+            // }
11641
+            //
11642
+            // if (($list[$cartEntity->getMerId()]['hasCoupon'] ?? 0) == 0) {
11643
+            //     // 获取该商品 所绑定的优惠券
11644
+            //     $couponIdListByProductId = $storeCouponProductRepository->productByCouponId($cartEntity->getProductId());
11645
+            //     if (!empty($couponIdListByProductId)) {
11646
+            //         $list[$cartEntity->getMerId()]['hasCoupon'] = $storeCouponRepository->validProductCouponExists([$cartEntity->getProductId()], $cartEntity->getUid());
11647
+            //     }
11648
+            // }
11649
+            //
11650
+            // $list[$cartEntity->getMerId()] = $merchantEntityArr;
11651
+            // $list[$cartEntity->getMerId()]['hasCoupon'] = 0;
11652
+            // // 应该还有商品信息等数据
11653
+            // $list[$cartEntity->getMerId()]['list'][] = $cartEntity->toArray();
11654
+
11655
+
11656
+            // ??? 暂时不理解这一步
11657
+            // type => '商品类型:1:普通商品。2:爆款商品。3:消费积分商品 。5:会员专享商品(城中大仓)6:每日免费领商品 7:商户特殊商品 8:共富会员商品 9:共富高级会员商品 10:高级会员商品 11村代理商品(废弃) 12镇代理商品(废弃) 13县代理商品(废弃)  14- 合伙人商品 15 股权商品 16合伙人+股权商品',
11658
+            // ProductType => 0.普通商品 1.秒杀商品
11659
+            $productEntity->setProductType($productEntity->getType());
11660
+            // 计算单价
11661
+            $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), 2);
11662
+            // 计算总价
11663
+            $totalPrice = bcadd($totalPrice, $price, 2);
11664
+            // 计算总数
11665
+            $totalNum = bcadd($totalNum, $cartEntity->getCartNum(), 2);
11666
+
11667
+            // 如果是 普通商品 product_type 类型 0=普通产品
11668
+            if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11669
+                $productPriceMap[$cartEntity->getProductId()] = bcadd($productPriceMap[$cartEntity->getProductId()] ?? 0, $price, 2);
11617 11670
 
11618
-        // 计算 邮费
11619
-        $postage_price = 0.00;
11620
-        $product_price = [];
11621
-        $valid_total_price = 0.00;
11622
-        $product_cart = [];
11671
+            }
11623 11672
 
11624
-        // ??? 暂时不理解这一步
11625
-        // type => '商品类型:1:普通商品。2:爆款商品。3:消费积分商品 。5:会员专享商品(城中大仓)6:每日免费领商品 7:商户特殊商品 8:共富会员商品 9:共富高级会员商品 10:高级会员商品 11村代理商品(废弃) 12镇代理商品(废弃) 13县代理商品(废弃)  14- 合伙人商品 15 股权商品 16合伙人+股权商品',
11626
-        // ProductType => 0.普通商品 1.秒杀商品
11627
-        $productEntity->setProductType($productEntity->getType());
11673
+            $product_cart[$cartEntityList->getProductId()] = [$cartEntityList->getCartId()];
11628 11674
 
11629
-        $seckillEntity = $seckillRepository->getSeckillEntityByProductId($cartEntityList->getProductId());
11630
-        // ??? 暂时不理解这一步
11631
-        if (!empty($seckillEntity->getId())) {
11632
-            // 把 商品属性的 价格 改成 大仓会员价
11633
-            $productAttrValueEntity->setPrice($productAttrValueEntity->getDacangPrice());
11675
+            // unset($cartInfo['list'][$_k]['product']['temp']);
11676
+            // $cartInfo['list'][$_k] = $cart;
11677
+            // if (!$address || !$cart['product']['temp']) {
11678
+            //     $cartInfo['list'][$_k]['undelivered'] = true;
11679
+            //     $noDeliver = true;
11680
+            //     continue;
11681
+            // }
11634 11682
         }
11635 11683
 
11636
-        // 计算 订单价格 总价 单价 (目前一笔订单只能有一个购物车 购物车内 只能有一件商品)
11637
-        $total_price = $price = bcmul($cartEntityList->getCartNum(), $productAttrValueEntity->getPrice(), 2);
11638
-        $total_num = $cartEntityList->getCartNum();
11639 11684
 
11640
-        // 如果是 普通商品 product_type 类型 0=普通产品
11641
-        if ($cartEntityList->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11642
-            $valid_total_price = $product_price[$cartEntityList->getProductId()] = $price;
11643
-        }
11644 11685
 
11645
-        $product_cart[$cartEntityList->getProductId()] = [$cartEntityList->getCartId()];
11646 11686
 
11647
-        // unset($cartInfo['list'][$_k]['product']['temp']);
11648
-        // $cartInfo['list'][$_k] = $cart;
11649
-        // if (!$address || !$cart['product']['temp']) {
11650
-        //     $cartInfo['list'][$_k]['undelivered'] = true;
11651
-        //     $noDeliver = true;
11652
-        //     continue;
11653
-        // }
11687
+
11654 11688
 
11655 11689
         return [
11656 11690
             // 'youhui_price' => 0.00, // 随机减金额