Преглед изворни кода

Merge branch 'dev-sxb' into dev

sunxbiao пре 10 месеци
родитељ
комит
f3ee95d38a

+ 149 - 93
app/common/repositories/store/order/StoreOrderRepository.php

@@ -85,6 +85,7 @@ use app\entity\data\user\UserAddressEntity;
85
 use app\entity\data\user\UserBillEntity;
85
 use app\entity\data\user\UserBillEntity;
86
 use app\entity\data\user\UserEntity;
86
 use app\entity\data\user\UserEntity;
87
 use app\entity\monomer\store\FzonePayTypeEntity;
87
 use app\entity\monomer\store\FzonePayTypeEntity;
88
+use app\entity\request\api\store\order\CalculatePostageRequestEntity;
88
 use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
89
 use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
89
 use app\model\common\JdOrderModel;
90
 use app\model\common\JdOrderModel;
90
 use app\model\common\TbOrderModel;
91
 use app\model\common\TbOrderModel;
@@ -11706,6 +11707,7 @@ class StoreOrderRepository extends BaseRepository
11706
         $userEntity = $verifyResult['userEntity'];
11707
         $userEntity = $verifyResult['userEntity'];
11707
         /** @var CartEntity[] $cartEntityList 发起创建订单的购物车列表 */
11708
         /** @var CartEntity[] $cartEntityList 发起创建订单的购物车列表 */
11708
         $cartEntityList = $verifyResult['cartEntityList'];
11709
         $cartEntityList = $verifyResult['cartEntityList'];
11710
+        /** @var CartEntity[] $cartEntityMap 发起创建订单的购物车映射 */
11709
         $cartEntityMap = array_column($cartEntityList, null, 'cartId');
11711
         $cartEntityMap = array_column($cartEntityList, null, 'cartId');
11710
         $cartIdList = array_keys($cartEntityMap);
11712
         $cartIdList = array_keys($cartEntityMap);
11711
         /** @var UserAddressEntity $addressEntity 地址信息 */
11713
         /** @var UserAddressEntity $addressEntity 地址信息 */
@@ -11733,19 +11735,6 @@ class StoreOrderRepository extends BaseRepository
11733
         // /** @var StoreCouponUserRepository $storeCouponUserRepository */
11735
         // /** @var StoreCouponUserRepository $storeCouponUserRepository */
11734
         // $storeCouponUserRepository = app()->make(StoreCouponUserRepository::class);
11736
         // $storeCouponUserRepository = app()->make(StoreCouponUserRepository::class);
11735
 
11737
 
11736
-        // 获取 运费表数据  商品 对应的 运费模板
11737
-        /** @var ShippingTemplateRepository $shippingTemplateRepository */
11738
-        $shippingTemplateRepository = app()->make(ShippingTemplateRepository::class);
11739
-        // 获取  商品 对应的 运费模板 de 指定不配送区域表
11740
-        /** @var ShippingTemplateUndeliveRepository $shippingTemplateUndeliveRepository */
11741
-        $shippingTemplateUndeliveRepository = app()->make(ShippingTemplateUndeliveRepository::class);
11742
-        // 获取  商品 对应的 运费模板 de 指定包邮信息表
11743
-        /** @var ShippingTemplateFreeRepository $shippingTemplateFreeRepository */
11744
-        $shippingTemplateFreeRepository = app()->make(ShippingTemplateFreeRepository::class);
11745
-        // 获取  商品 对应的 运费模板 de 配送区域表
11746
-        /** @var ShippingTemplateRegionRepository $shippingTemplateRegionRepository */
11747
-        $shippingTemplateRegionRepository = app()->make(ShippingTemplateRegionRepository::class);
11748
-
11749
         // 商品
11738
         // 商品
11750
         /** @var ProductRepository $productRepository */
11739
         /** @var ProductRepository $productRepository */
11751
         $productRepository = app()->make(ProductRepository::class);
11740
         $productRepository = app()->make(ProductRepository::class);
@@ -11835,85 +11824,13 @@ class StoreOrderRepository extends BaseRepository
11835
 
11824
 
11836
             // 计算运费 获取该商品的运费模板 运费表
11825
             // 计算运费 获取该商品的运费模板 运费表
11837
             // 判断商品是否是 供应链(微唯宝)商品
11826
             // 判断商品是否是 供应链(微唯宝)商品
11838
-            $postage = 0.00;
11839
-            if (!empty($productAttrValueEntity->getGongSkuId())) {
11840
-                $freight = GongApiRequest::freight($addressEntity->getCityId(), [['sku_id' => $productAttrValueEntity->getGongSkuId(), 'num' => $cartEntity->getCartNum()]]);
11841
-                $postage = $freight['freight'] ?? 0;
11842
-            } else {
11843
-                $shippingTemplateEntity = $shippingTemplateRepository->getShippingTemplateEntityByShippingTemplateId($productEntity->getTempId());
11844
-                if (empty($shippingTemplateEntity->getShippingTemplateId())) {
11845
-                    throw new ValidateException('未查询到商品所绑定的运费模板');
11846
-                } else {
11847
-                    // 判断是否开启 开启指定区域不配送
11848
-                    if ($shippingTemplateEntity->getUndelivery() == ShippingTemplateEnum::UNDELIVERY['Yes']['code']) {
11849
-                        // 获取运费模板的 指定不配送区域列表
11850
-                        $shippingTemplateUndeliveryEntityList = $shippingTemplateUndeliveRepository->getShippingTemplateUndeliveryEntityListByTempId($shippingTemplateEntity->getShippingTemplateId());
11851
-                        foreach ($shippingTemplateUndeliveryEntityList as $shippingTemplateUndeliveryEntity) {
11852
-                            // 验证 此次配送地址 是否在不配送区域中
11853
-                            if (in_array($addressEntity->getCityId(), $shippingTemplateUndeliveryEntity->getCityIdList())) {
11854
-                                throw new ValidateException($productEntity->getStoreName() . '此商品不支持该配送区域');
11855
-                            }
11856
-                        }
11857
-                    }
11858
-
11859
-                    $isBaoYou = false;
11860
-                    $number = 0.00;
11861
-                    // 获取 当前商品的 计费方式 (计费方式 0=数量 1=重量 2=体积)
11862
-                    if ($shippingTemplateEntity->getType() == ShippingTemplateEnum::TYPE['Quantity']['code']) {
11863
-                        $number = $cartEntity->getCartNum();
11864
-                    } else if ($shippingTemplateEntity->getType() == ShippingTemplateEnum::TYPE['Weight']['code']) {
11865
-                        $number = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getWeight(), 2);
11866
-                    } else {
11867
-                        $number = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getVolume(), 2);
11868
-                    }
11869
-
11870
-                    // 获取 指定包邮信息 包邮信息表
11871
-                    $shippingTemplateFreeEntityList = $shippingTemplateFreeRepository->getShippingTemplateFreeEntityListByTempId($shippingTemplateEntity->getShippingTemplateId());
11872
-                    foreach ($shippingTemplateFreeEntityList as $shippingTemplateFreeEntity) {
11873
-                        // 判断当前收货地址 是不是 在 指定 包邮 地点内
11874
-                        if (in_array($addressEntity->getCityId(), $shippingTemplateFreeEntity->getCityIdList())) {
11875
-                            // 判断当前 商品 是否符合 最高包邮数量上限 和 最低包邮金额
11876
-                            if ($number <= $shippingTemplateFreeEntity->getNumber() && $price >= $shippingTemplateFreeEntity->getPrice()) {
11877
-                                $isBaoYou = true;
11878
-                                break;
11879
-                            }
11880
-                        }
11881
-                    }
11882
-
11883
-                    // 如果不包邮 则需要计算邮费
11884
-                    if (!$isBaoYou){
11885
-                        // 配送区域表
11886
-                        $shippingTemplateRegionEntityList = $shippingTemplateRegionRepository->getShippingTemplateRegionEntityListByTempId($shippingTemplateEntity->getShippingTemplateId());
11887
-                        if (empty($shippingTemplateRegionEntityList)) {
11888
-                            throw new ValidateException($productEntity->getStoreName() . '此商品不支持该配送区域');
11889
-                        }
11890
-                        $isPeiSong = false;
11891
-                        foreach ($shippingTemplateRegionEntityList as $shippingTemplateRegionEntity) {
11892
-                            // 判断当前收货地址 是否在可配送区域内
11893
-                            if (in_array($addressEntity->getCityId(), $shippingTemplateRegionEntity->getCityIdList()) || $shippingTemplateRegionEntity->getCityId() == 0) {
11894
-                                // 比如 该商品 重量 5.03kg 首件重量 2kg 运费 2元  续件重量 3kg 续费3元
11895
-                                // 那本次 运费就是 首件运费 + ((重量 - 首件重量)/续件重量) * 续费单价
11896
-                                // 那本次 运费就是 2 + ((5.03 - 2)/3)向上取整 * 3 = 8
11897
-                                // 首件(重量or体积) 运费计算
11898
-                                if ($number > $shippingTemplateRegionEntity->getFirst()) {
11899
-                                    // 数量(重量or体积) 超出 首件部分 也就是续费部分
11900
-                                    $excess = bcsub($number, $shippingTemplateRegionEntity->getFirst(), 3);
11901
-                                    // 查看 需 续费几次 并向上取整
11902
-                                    $continueNum = ceil(bcdiv($excess, $shippingTemplateRegionEntity->getContinue(), 3));
11903
-                                    $postage = bcmul($continueNum, $shippingTemplateRegionEntity->getContinuePrice(), 2);
11904
-                                } else {
11905
-                                    $postage = $shippingTemplateRegionEntity->getFirstPrice();
11906
-                                }
11907
-                                $isPeiSong = true;
11908
-                                break;
11909
-                            }
11910
-                        }
11911
-                        if (!$isPeiSong) {
11912
-                            throw new ValidateException($productEntity->getStoreName() . '此商品不支持该配送区域');
11913
-                        }
11914
-                    }
11915
-                }
11916
-            }
11827
+            // $postage = $this->calculatePostage(
11828
+            //     $productEntity,
11829
+            //     $productAttrValueEntity,
11830
+            //     $cartEntity->getCartNum(),
11831
+            //     $addressEntity->getCityId()
11832
+            // );
11833
+            $postage = 0.00; // 默认全都包邮s
11917
 
11834
 
11918
             // 汇付手续费 (订单价格 + 邮费) * 汇付手续费比例
11835
             // 汇付手续费 (订单价格 + 邮费) * 汇付手续费比例
11919
             $commissionRate = bcmul(bcadd($price, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT), CommonEnum::HUIFU_COMMISSION_CHARGE, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11836
             $commissionRate = bcmul(bcadd($price, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT), CommonEnum::HUIFU_COMMISSION_CHARGE, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
@@ -11970,7 +11887,7 @@ class StoreOrderRepository extends BaseRepository
11970
                 ->setSeckill($productSeckillEntity->getId())
11887
                 ->setSeckill($productSeckillEntity->getId())
11971
                 ->setYouhuiPrice($youhuiPrice)
11888
                 ->setYouhuiPrice($youhuiPrice)
11972
                 ->setDouhuomall(empty($productEntity->getSpuId())?StoreOrderEnum::DOHUOMALL['PlatformOrder']['code']:StoreOrderEnum::DOHUOMALL['SupplyChainOrder']['code'])
11889
                 ->setDouhuomall(empty($productEntity->getSpuId())?StoreOrderEnum::DOHUOMALL['PlatformOrder']['code']:StoreOrderEnum::DOHUOMALL['SupplyChainOrder']['code'])
11973
-                ->setDouhuomallStatus(StoreOrderEnum::DOHUOMALL_STATUS['NotSubmittedToWeiweiBao']['code'])
11890
+                ->setDouhuomallStatus(empty($productEntity->getSpuId()) ? null : StoreOrderEnum::DOHUOMALL_STATUS['NotSubmittedToWeiweiBao']['code'])
11974
                 ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType())
11891
                 ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType())
11975
                 ->setConPri($serviceMoney);
11892
                 ->setConPri($serviceMoney);
11976
             $storeOrderEntityList[] = $storeOrderEntity;
11893
             $storeOrderEntityList[] = $storeOrderEntity;
@@ -12291,4 +12208,143 @@ class StoreOrderRepository extends BaseRepository
12291
             'storeProductAttrValueEntityMap' => $storeProductAttrValueEntityMap,
12208
             'storeProductAttrValueEntityMap' => $storeProductAttrValueEntityMap,
12292
         ];
12209
         ];
12293
     }
12210
     }
12211
+
12212
+    /**
12213
+     * 根据 商品属性 唯一值、城市ID、数量 计算运费
12214
+     * @param CalculatePostageRequestEntity $calculatePostageRequestEntity
12215
+     * @return float|int|mixed|string
12216
+     */
12217
+    public function getPostageByUniqueAndCityIdAndNum(CalculatePostageRequestEntity $calculatePostageRequestEntity)
12218
+    {
12219
+        // 商品属性
12220
+        /** @var ProductAttrValueRepository $storeProductAttrValueRepository */
12221
+        $storeProductAttrValueRepository = app()->make(ProductAttrValueRepository::class);
12222
+        $storeProductAttrValueEntityList = $storeProductAttrValueRepository->getStoreProductAttrValueEntityByUnique($calculatePostageRequestEntity->getUnique());
12223
+        if (empty($storeProductAttrValueEntityList->getProductId())) {
12224
+            throw new ValidateException('未查询到商品属性信息');
12225
+        }
12226
+
12227
+        // 商品
12228
+        /** @var ProductRepository $storeProductRepository */
12229
+        $storeProductRepository = app()->make(ProductRepository::class);
12230
+        $storeProductEntity = $storeProductRepository->getStoreProductEntityByProductId($storeProductAttrValueEntityList->getProductId());
12231
+        if (empty($storeProductEntity->getProductId())) {
12232
+            throw new ValidateException('未查询到商品信息');
12233
+        }
12234
+
12235
+        return $this->calculatePostage(
12236
+            $storeProductEntity,
12237
+            $storeProductAttrValueEntityList,
12238
+            $calculatePostageRequestEntity->getNum(),
12239
+            $calculatePostageRequestEntity->getCityId()
12240
+        );
12241
+    }
12242
+
12243
+    /**
12244
+     * 计算运费
12245
+     * @param StoreProductEntity $productEntity
12246
+     * @param StoreProductAttrValueEntity $productAttrValueEntity
12247
+     * @param int $num
12248
+     * @param int $cityId
12249
+     * @return float|int|mixed|string
12250
+     */
12251
+    public function calculatePostage(StoreProductEntity $productEntity, StoreProductAttrValueEntity $productAttrValueEntity, int $num, int $cityId)
12252
+    {
12253
+        // 获取 运费表数据  商品 对应的 运费模板
12254
+        /** @var ShippingTemplateRepository $shippingTemplateRepository */
12255
+        $shippingTemplateRepository = app()->make(ShippingTemplateRepository::class);
12256
+        // 获取  商品 对应的 运费模板 de 指定不配送区域表
12257
+        /** @var ShippingTemplateUndeliveRepository $shippingTemplateUndeliveRepository */
12258
+        $shippingTemplateUndeliveRepository = app()->make(ShippingTemplateUndeliveRepository::class);
12259
+        // 获取  商品 对应的 运费模板 de 指定包邮信息表
12260
+        /** @var ShippingTemplateFreeRepository $shippingTemplateFreeRepository */
12261
+        $shippingTemplateFreeRepository = app()->make(ShippingTemplateFreeRepository::class);
12262
+        // 获取  商品 对应的 运费模板 de 配送区域表
12263
+        /** @var ShippingTemplateRegionRepository $shippingTemplateRegionRepository */
12264
+        $shippingTemplateRegionRepository = app()->make(ShippingTemplateRegionRepository::class);
12265
+        // 计算 该款商品 总金额
12266
+        $price = bcmul($num, $productAttrValueEntity->getPrice(), CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
12267
+        $postage = 0.00;
12268
+
12269
+        if (!empty($productAttrValueEntity->getGongSkuId())) {
12270
+            $freight = GongApiRequest::freight($cityId, [['sku_id' => $productAttrValueEntity->getGongSkuId(), 'num' => $num]]);
12271
+            $postage = $freight['freight'] ?? 0;
12272
+        } else {
12273
+            $shippingTemplateEntity = $shippingTemplateRepository->getShippingTemplateEntityByShippingTemplateId($productEntity->getTempId());
12274
+            if (empty($shippingTemplateEntity->getShippingTemplateId())) {
12275
+                throw new ValidateException('未查询到商品所绑定的运费模板');
12276
+            } else {
12277
+                // 判断是否开启 开启指定区域不配送
12278
+                if ($shippingTemplateEntity->getUndelivery() == ShippingTemplateEnum::UNDELIVERY['Yes']['code']) {
12279
+                    // 获取运费模板的 指定不配送区域列表
12280
+                    $shippingTemplateUndeliveryEntityList = $shippingTemplateUndeliveRepository->getShippingTemplateUndeliveryEntityListByTempId($shippingTemplateEntity->getShippingTemplateId());
12281
+                    foreach ($shippingTemplateUndeliveryEntityList as $shippingTemplateUndeliveryEntity) {
12282
+                        // 验证 此次配送地址 是否在不配送区域中
12283
+                        if (in_array($cityId, $shippingTemplateUndeliveryEntity->getCityIdList())) {
12284
+                            throw new ValidateException($productEntity->getStoreName() . '此商品不支持该配送区域');
12285
+                        }
12286
+                    }
12287
+                }
12288
+
12289
+                $isBaoYou = false;
12290
+                $number = 0.00;
12291
+                // 获取 当前商品的 计费方式 (计费方式 0=数量 1=重量 2=体积)
12292
+                if ($shippingTemplateEntity->getType() == ShippingTemplateEnum::TYPE['Quantity']['code']) {
12293
+                    $number = $num;
12294
+                } else if ($shippingTemplateEntity->getType() == ShippingTemplateEnum::TYPE['Weight']['code']) {
12295
+                    $number = bcmul($num, $productAttrValueEntity->getWeight(), 2);
12296
+                } else {
12297
+                    $number = bcmul($num, $productAttrValueEntity->getVolume(), 2);
12298
+                }
12299
+
12300
+                // 获取 指定包邮信息 包邮信息表
12301
+                $shippingTemplateFreeEntityList = $shippingTemplateFreeRepository->getShippingTemplateFreeEntityListByTempId($shippingTemplateEntity->getShippingTemplateId());
12302
+                foreach ($shippingTemplateFreeEntityList as $shippingTemplateFreeEntity) {
12303
+                    // 判断当前收货地址 是不是 在 指定 包邮 地点内
12304
+                    if (in_array($cityId, $shippingTemplateFreeEntity->getCityIdList())) {
12305
+                        // 判断当前 商品 是否符合 最高包邮数量上限 和 最低包邮金额
12306
+                        if ($number <= $shippingTemplateFreeEntity->getNumber() && $price >= $shippingTemplateFreeEntity->getPrice()) {
12307
+                            $isBaoYou = true;
12308
+                            break;
12309
+                        }
12310
+                    }
12311
+                }
12312
+
12313
+                // 如果不包邮 则需要计算邮费
12314
+                if (!$isBaoYou) {
12315
+                    // 配送区域表
12316
+                    $shippingTemplateRegionEntityList = $shippingTemplateRegionRepository->getShippingTemplateRegionEntityListByTempId($shippingTemplateEntity->getShippingTemplateId());
12317
+                    if (empty($shippingTemplateRegionEntityList)) {
12318
+                        throw new ValidateException($productEntity->getStoreName() . '此商品不支持该配送区域');
12319
+                    }
12320
+                    $isPeiSong = false;
12321
+                    foreach ($shippingTemplateRegionEntityList as $shippingTemplateRegionEntity) {
12322
+                        // 判断当前收货地址 是否在可配送区域内
12323
+                        if (in_array($cityId, $shippingTemplateRegionEntity->getCityIdList()) || $shippingTemplateRegionEntity->getCityId() == 0) {
12324
+                            // 比如 该商品 重量 5.03kg 首件重量 2kg 运费 2元  续件重量 3kg 续费3元
12325
+                            // 那本次 运费就是 首件运费 + ((重量 - 首件重量)/续件重量) * 续费单价
12326
+                            // 那本次 运费就是 2 + ((5.03 - 2)/3)向上取整 * 3 = 8
12327
+                            // 首件(重量or体积) 运费计算
12328
+                            if ($number > $shippingTemplateRegionEntity->getFirst()) {
12329
+                                // 数量(重量or体积) 超出 首件部分 也就是续费部分
12330
+                                $excess = bcsub($number, $shippingTemplateRegionEntity->getFirst(), 3);
12331
+                                // 查看 需 续费几次 并向上取整
12332
+                                $continueNum = ceil(bcdiv($excess, $shippingTemplateRegionEntity->getContinue(), 3));
12333
+                                $postage = bcmul($continueNum, $shippingTemplateRegionEntity->getContinuePrice(), 2);
12334
+                            } else {
12335
+                                $postage = $shippingTemplateRegionEntity->getFirstPrice();
12336
+                            }
12337
+                            $isPeiSong = true;
12338
+                            break;
12339
+                        }
12340
+                    }
12341
+                    if (!$isPeiSong) {
12342
+                        throw new ValidateException($productEntity->getStoreName() . '此商品不支持该配送区域');
12343
+                    }
12344
+                }
12345
+            }
12346
+        }
12347
+
12348
+        return $postage;
12349
+    }
12294
 }
12350
 }

+ 28 - 0
app/controller/api/store/order/StoreOrder.php

@@ -20,8 +20,10 @@ use app\common\repositories\store\product\ProductAttrValueRepository;
20
 use app\common\repositories\user\UserAddressRepository;
20
 use app\common\repositories\user\UserAddressRepository;
21
 use app\common\repositories\user\UserRepository;
21
 use app\common\repositories\user\UserRepository;
22
 use app\entity\data\user\UserEntity;
22
 use app\entity\data\user\UserEntity;
23
+use app\entity\request\api\store\order\CalculatePostageRequestEntity;
23
 use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
24
 use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
24
 use app\traits\ShouxinyiApiRequest;
25
 use app\traits\ShouxinyiApiRequest;
26
+use app\validate\api\store\order\CalculatePostageValidate;
25
 use app\validate\api\store\order\StoreOrderCreateValidate;
27
 use app\validate\api\store\order\StoreOrderCreateValidate;
26
 use crmeb\basic\BaseController;
28
 use crmeb\basic\BaseController;
27
 use app\common\repositories\store\order\StoreCartRepository;
29
 use app\common\repositories\store\order\StoreCartRepository;
@@ -1999,4 +2001,30 @@ class StoreOrder extends BaseController
1999
     }
2001
     }
2000
 
2002
 
2001
 
2003
 
2004
+    /**
2005
+     * 计算运费
2006
+     *
2007
+     * @param CalculatePostageValidate $calculatePostageValidate
2008
+     * @return mixed
2009
+     */
2010
+    public function calculatePostage(CalculatePostageValidate $calculatePostageValidate)
2011
+    {
2012
+        // 1、接收参数
2013
+        $calculatePostageValidateResult = $calculatePostageValidate->validateRequest();
2014
+        // 如果验证失败,返回错误
2015
+        if ($calculatePostageValidateResult['status'] == 'error') {
2016
+            return app('json')->fail($calculatePostageValidateResult['message']);
2017
+        }
2018
+
2019
+        // 验证通过,继续处理数据
2020
+        /** @var CalculatePostageRequestEntity $calculatePostageRequestEntity */
2021
+        $calculatePostageRequestEntity = $calculatePostageValidateResult['data'];
2022
+
2023
+        // 2. 获取运费
2024
+        $postage = $this->repository->getPostageByUniqueAndCityIdAndNum($calculatePostageRequestEntity);
2025
+
2026
+        return app('json')->success([
2027
+            'postage' => $postage
2028
+        ]);
2029
+    }
2002
 }
2030
 }

+ 69 - 0
app/entity/request/api/store/order/CalculatePostageRequestEntity.php

@@ -0,0 +1,69 @@
1
+<?php
2
+
3
+namespace app\entity\request\api\store\order;
4
+
5
+use app\entity\request\RequestCommonEntity;
6
+
7
+class CalculatePostageRequestEntity extends RequestCommonEntity
8
+{
9
+    // 收货地址 城市ID
10
+    public $cityId = 0;
11
+    // 商品ID
12
+    public $unique = '';
13
+    // 购买数量
14
+    public $num = 0;
15
+
16
+    /**
17
+     * @return int
18
+     */
19
+    public function getCityId(): int
20
+    {
21
+        return $this->cityId;
22
+    }
23
+
24
+    /**
25
+     * @param int $cityId
26
+     * @return CalculatePostageRequestEntity
27
+     */
28
+    public function setCityId(int $cityId): CalculatePostageRequestEntity
29
+    {
30
+        $this->cityId = $cityId;
31
+        return $this;
32
+    }
33
+
34
+    /**
35
+     * @return string
36
+     */
37
+    public function getUnique(): string
38
+    {
39
+        return $this->unique;
40
+    }
41
+
42
+    /**
43
+     * @param string $unique
44
+     * @return CalculatePostageRequestEntity
45
+     */
46
+    public function setUnique(string $unique): CalculatePostageRequestEntity
47
+    {
48
+        $this->unique = $unique;
49
+        return $this;
50
+    }
51
+
52
+    /**
53
+     * @return int
54
+     */
55
+    public function getNum(): int
56
+    {
57
+        return $this->num;
58
+    }
59
+
60
+    /**
61
+     * @param int $num
62
+     * @return CalculatePostageRequestEntity
63
+     */
64
+    public function setNum(int $num): CalculatePostageRequestEntity
65
+    {
66
+        $this->num = $num;
67
+        return $this;
68
+    }
69
+}

+ 42 - 0
app/validate/api/store/order/CalculatePostageValidate.php

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace app\validate\api\store\order;
4
+
5
+use app\entity\request\api\store\order\CalculatePostageRequestEntity;
6
+use app\validate\CommonValidate;
7
+use think\facade\Log;
8
+
9
+class CalculatePostageValidate extends CommonValidate
10
+{
11
+
12
+    protected $rule = [
13
+        'cityId' => 'require|integer|egt:0',
14
+        'unique' => 'require',
15
+        'num' => 'require|integer|gt:0'
16
+    ];
17
+
18
+    protected $message = [
19
+        'cityId.require' => '城市ID不能为空!',
20
+        'cityId.integer' => '城市ID必须是整数!',
21
+        'cityId.egt' => '城市ID必须大于等于0!',
22
+        'unique.require' => '唯一标识不能为空!',
23
+        'num.require' => '购买数量不能为空!',
24
+        'num.integer' => '购买数量必须是整数!',
25
+        'num.gt' => '购买数量必须大于0!'
26
+    ];
27
+
28
+    /**
29
+     * 将Request参数获取与验证封装到验证类中
30
+     *
31
+     * @return array
32
+     */
33
+    public function validateRequest(): array
34
+    {
35
+        $data = $this->request->param();
36
+        Log::info('request-api-store-order-CalculatePostage-params:' . json_encode($data));
37
+        if (!$this->check($data)) {
38
+            return ['status' => 'error', 'message' => $this->getError()];
39
+        }
40
+        return ['status' => 'success', 'data' => CalculatePostageRequestEntity::newInstance($data)];
41
+    }
42
+}

+ 2 - 0
route/api.php

@@ -85,6 +85,8 @@ Route::group('api/', function () {
85
             Route::post('tests/:order_sn', '/tests');
85
             Route::post('tests/:order_sn', '/tests');
86
             Route::post('create', '/createOrder');//创建订单
86
             Route::post('create', '/createOrder');//创建订单
87
             Route::post('createNew', '/createOrderNew');//创建订单
87
             Route::post('createNew', '/createOrderNew');//创建订单
88
+            // 通过 商品ID 商品数量 ,使用商品选用的运费模板 计算邮费
89
+            Route::get('calculatePostage', '/calculatePostage');
88
             Route::post('delete', '/delete');//删除订单
90
             Route::post('delete', '/delete');//删除订单
89
             Route::post('create_annual_cost', '/create_annual_costorder');
91
             Route::post('create_annual_cost', '/create_annual_costorder');
90
             Route::post('create_activation_code_order', '/create_activation_code_order');
92
             Route::post('create_activation_code_order', '/create_activation_code_order');