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

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

sunxbiao 1 год назад
Родитель
Сommit
6a6b529272

+ 55 - 79
app/common/repositories/store/order/StoreOrderRepository.php

@@ -52,6 +52,8 @@ use app\controller\api\user\Volunteer;
52 52
 use app\entity\data\merchant\MerchantEntity;
53 53
 use app\entity\data\product\ShareEntity;
54 54
 use app\entity\data\store\CartEntity;
55
+use app\entity\data\store\StoreGroupOrderEntity;
56
+use app\entity\data\store\StoreOrderEntity;
55 57
 use app\entity\data\user\AddressEntity;
56 58
 use app\entity\data\user\UserEntity;
57 59
 use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
@@ -10708,9 +10710,9 @@ class StoreOrderRepository extends BaseRepository
10708 10710
         // 订单总数量
10709 10711
         $totalNum = 0;
10710 10712
         // 此笔订单产生的总 邮费
10711
-        $postage = 0.00;
10712
-
10713
-        $orderList = [];
10713
+        $totalPostage = 0.00;
10714
+        // 订单实体表
10715
+        $storeOrderEntityList = [];
10714 10716
 
10715 10717
         // 循环购物车 对购物车内的商品 进行条件验证 以及根据不同的商品 计算邮费
10716 10718
         foreach ($cartEntityList as $numKey => $cartEntity) {
@@ -10820,6 +10822,8 @@ class StoreOrderRepository extends BaseRepository
10820 10822
 
10821 10823
             // 计算单价 systemConfig('mer_365');
10822 10824
             $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), 2);
10825
+            // 平台拿到的钱(商户分润)
10826
+            $serviceMoney = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPlateMerProfit(), 2);
10823 10827
             // 计算养老金 注意 此步骤需要传入商品的价格,因为上述 可能对商品的价格发生了改变
10824 10828
             $yanglaojin = bcadd($yanglaojin, $productRepository->yanglaojin($cartEntity->getProductId(), $price), 2);
10825 10829
             // 计算总价
@@ -10835,10 +10839,11 @@ class StoreOrderRepository extends BaseRepository
10835 10839
             // 计算运费 获取该商品的运费模板 运费表
10836 10840
             // TODO  注意 这个地址好像有问题,我再 客户端->收货地址管理中 (rrx_user_address)增加的廊坊市 对应的城市编号是(code_list)315 且city_id 字段的值是 2,而我再后台设置 可配送地址时 ,廊坊市对应的编码是 58247
10837 10841
             // 判断商品是否是 供应链(微唯宝)商品
10842
+            $postage = 0.00;
10838 10843
             if (!empty($productAttrValueEntity->getGongSkuId())) {
10839 10844
                 $freight = GongApiRequest::freight($addressEntity->getCityId(), [['sku_id' => $productAttrValueEntity->getGongSkuId(), 'num' => $cartEntity->getCartNum()]]);
10840
-                $freight = $freight['freight'] ?? 0;
10841
-                $postage = bcadd($postage, $freight, 2);
10845
+                $postage = $freight['freight'] ?? 0;
10846
+                $totalPostage = bcadd($totalPostage, $postage, 2);
10842 10847
             } else {
10843 10848
                 $shippingTemplateEntity = $shippingTemplateRepository->getShippingTemplateEntityByShippingTemplateId($productEntity->getTempId());
10844 10849
                 if (empty($shippingTemplateEntity->getShippingTemplateId())) {
@@ -10890,15 +10895,16 @@ class StoreOrderRepository extends BaseRepository
10890 10895
                                 // 那本次 运费就是 首件运费 + ((重量 - 首件重量)/续件重量) * 续费单价
10891 10896
                                 // 那本次 运费就是 2 + ((5.03 - 2)/3)向上取整 * 3 = 8
10892 10897
                                 // 首件(重量or体积) 运费计算
10893
-                                $postage = bcadd($postage, $shippingTemplateRegionEntity->getFirstPrice(), 2);
10894 10898
                                 if ($number > $shippingTemplateRegionEntity->getFirst()) {
10895 10899
                                     // 数量(重量or体积) 超出 首件部分 也就是续费部分
10896 10900
                                     $excess = bcsub($number, $shippingTemplateRegionEntity->getFirst(), 3);
10897 10901
                                     // 查看 需 续费几次 并向上取整
10898 10902
                                     $continueNum = ceil(bcdiv($excess, $shippingTemplateRegionEntity->getContinue(), 3));
10899
-                                    $continueCost = bcmul($continueNum, $shippingTemplateRegionEntity->getContinuePrice(), 2);
10900
-                                    $postage = bcadd($postage, $continueCost, 2);
10903
+                                    $postage = bcmul($continueNum, $shippingTemplateRegionEntity->getContinuePrice(), 2);
10904
+                                } else {
10905
+                                    $postage = $shippingTemplateRegionEntity->getFirstPrice();
10901 10906
                                 }
10907
+                                $totalPostage = bcadd($totalPostage, $postage, 2);
10902 10908
                             }
10903 10909
                         }
10904 10910
                     }
@@ -10906,7 +10912,6 @@ class StoreOrderRepository extends BaseRepository
10906 10912
             }
10907 10913
 
10908 10914
 
10909
-
10910 10915
             // // 会员专区
10911 10916
             // if ($productEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']) {
10912 10917
             //
@@ -10924,77 +10929,48 @@ class StoreOrderRepository extends BaseRepository
10924 10929
             // 修改 购物车状态
10925 10930
             $storeCartRepository->update($cartEntity->getCartId(), ['is_pay' => CartEnum::IS_PAY['Yes']['code']]);
10926 10931
 
10927
-            // 修改优惠券状态
10928
-            // $storeCouponUserRepository->updates([], []);
10929
-
10930
-            // StoreGroupOrderEntity
10931
-
10932
-            // 组装数据
10933
-            $_order = [
10934
-                // 平台手续费(汇付通道服务费)
10935
-                'commission_rate' => (float)$merchantRepository->get($cartEntity->getMerId())->mer_commission_rate,
10936
-                // '0普通1自提'
10937
-                'order_type' => 0,
10938
-                // 一级佣金
10939
-                'extension_one' => 0.00,
10932
+            // 创建订单
10933
+            /** @var StoreOrderEntity $storeOrderEntity */
10934
+            $storeOrderEntity = StoreOrderEntity::newInstance();
10935
+            $storeOrderEntity->setCommissionRate((float)$merchantRepository->get($cartEntity->getMerId())->mer_commission_rate)
10940 10936
                 // 二级佣金 此字段已被用于分佣比例
10941
-                'extension_two' => $productAttrValueEntity->getExtensionTwo(),
10942
-
10943
-                // 'orderInfo' => $cartInfo['order'],
10944
-                // 'cartInfo' => $cartInfo['list'],
10945
-
10946
-                // 订单编号
10947
-                'order_sn' => $this->getNewOrderId() . ($numKey + 1),
10948
-                // 用户ID
10949
-                'uid' => $cartEntity->getUid(),
10950
-                // 收货人 用户姓名
10951
-                'real_name' => $addressEntity->getRealName(),
10952
-                // 收货人 用户电话
10953
-                'user_phone' => $addressEntity->getPhone(),
10954
-                // 收货人 地址
10955
-                'user_address' => $addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail(),
10956
-                // 详细地址id
10957
-                'user_address_ids' => 0,
10958
-                // 申请代理地址
10959
-                'area_manage_address_ids' => 0,
10960
-                'cart_id' => implode(',', array_column($cartInfo['list'], 'cart_id')),
10961
-                'total_num' => $cartInfo['order']['total_num'],
10962
-                'total_price' => $cartInfo['order']['total_price'],
10963
-                'total_postage' => $cartInfo['order']['postage_price'],
10964
-                'pay_postage' => $cartInfo['order']['postage_price'],
10965
-                'pay_price' => $cartInfo['order']['pay_price'],
10966
-                //                'pay_price' => '0.00',
10967
-                'mer_id' => $cartInfo['mer_id'],
10968
-                'cost' => $cost,
10969
-                'coupon_id' => implode(',', $useCoupon),
10970
-                'mark' => $mark[$cartInfo['mer_id']] ?? '',
10971
-                'coupon_price' => $cartInfo['order']['coupon_price'] > $cartInfo['order']['total_price'] ? $cartInfo['order']['total_price'] : $cartInfo['order']['coupon_price'],
10972
-                'pay_type' => $pay_type,
10973
-                'share_id' => $share_id,
10974
-                'share_uid' => $share_uid,
10975
-                'table_id' => $table_id,
10976
-                //                    'mer_money' => round($mer_money,2),
10977
-                'service_money' => $service_money ?? 0,
10978
-                'test_order' => $test_user,
10979
-                'dacang_id' => $dacang_id,
10980
-                'distribution_mode' => $distribution_mode,
10981
-                'ziti_address' => $ziti_address,
10982
-                'address_id' => $addressId,
10983
-                'seckill' => 0,
10984
-                'youhui_price' => $order['youhui_price'],
10985
-                'douhuomall' => 0,
10986
-                'fzone_paytype' => $fzone_paytype,
10987
-                'con_pri' => $product_attr_unique_datas['plate_mer_profit'],//计算商品选中的产品规格,然后计算利润,这个利润会在每周分红中进行分润
10988
-                'user_of_goods_id' => $getuserofgoodsid,
10989
-                'fzone_pay_jingdou' => $array_fzone_paytype_all['fzone_pay_jingdou'],
10990
-                'fzone_pay_vr' => $array_fzone_paytype_all['fzone_pay_vr'],
10991
-                'fzone_pay_jifen' => $array_fzone_paytype_all['fzone_pay_jifen'],
10992
-                'fzone_pay_price' => $array_fzone_paytype_all['fzone_pay_price'],
10993
-                'fzone_pay_other' => $array_fzone_paytype_all['fzone_pay_other'],
10994
-                'fzone_pay_note' => $array_fzone_paytype_all['fzone_pay_note'],
10995
-                'fzone_pay_type' => $array_fzone_paytype_all['fzone_pay_type'],
10996
-            ];
10997
-
10937
+                ->setExtensionTwo($productAttrValueEntity->getExtensionTwo())
10938
+                ->setOrderSn($this->getNewOrderId() . ($numKey + 1))
10939
+                ->setUid($cartEntity->getUid())
10940
+                ->setRealName($addressEntity->getRealName())
10941
+                ->setUserPhone($addressEntity->getPhone())
10942
+                ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
10943
+                ->setCartId($cartEntity->getCartId())
10944
+                ->setTotalNum($cartEntity->getCartNum())
10945
+                ->setTotalPrice($price)
10946
+                ->setTotalPostage($postage)
10947
+                ->setPayPostage($postage)
10948
+                ->setPayPrice($price)
10949
+                ->setMerId($cartEntity->getMerId())
10950
+                ->setCost(bcsub($price, $serviceMoney, 2))
10951
+                ->setPayType($storeOrderCreateRequestEntity->getPayType())
10952
+                ->setShareId($storeOrderCreateRequestEntity->getShareId())
10953
+                ->setShareUid($shareEntity->getUid())
10954
+                ->setServiceMoney($serviceMoney)
10955
+                ->setTestOrder($userEntity->getTestUser())
10956
+                ->setDacangId($productEntity->getDcId());
10957
+
10958
+
10959
+
10960
+
10961
+            // // 修改优惠券状态
10962
+            // // $storeCouponUserRepository->updates([], []);
10963
+            // /** @var StoreGroupOrderEntity $storeGroupOrderEntity */
10964
+            // $storeGroupOrderEntity = StoreGroupOrderEntity::newInstance();
10965
+            // $storeGroupOrderEntity->setUid($cartEntity->getUid())
10966
+            //     ->setGroupOrderSn($this->getNewOrderId() . '0')
10967
+            //     ->setTotalPostage($postage)
10968
+            //     ->setTotalPrice($price)
10969
+            //     ->setTotalNum($cartEntity->getCartNum())
10970
+            //     ->setRealName($addressEntity->getRealName())
10971
+            //     ->setUserPhone($addressEntity->getPhone())
10972
+            //     ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
10973
+            //     ->setPayPrice()
10998 10974
 
10999 10975
         }
11000 10976
 

Разница между файлами не показана из-за своего большого размера
+ 1738 - 0
app/entity/data/store/StoreOrderEntity.php