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