顺丰同城调试修复bug
This commit is contained in:
parent
2179f2c09b
commit
e56f8e46c5
@ -131,34 +131,6 @@ public class CommonUtil {
|
||||
.distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断任何一个对象是否有空值?
|
||||
* @param objs
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasAnyBlank(Object... objs) {
|
||||
if (objs == null || objs.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Object o : objs) {
|
||||
if (o == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断全部对象是否都不为空
|
||||
* @param objs
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAllNotBlank(Object... objs) {
|
||||
return !hasAnyBlank(objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Double 四舍五入,不保留小数点
|
||||
* @param d
|
||||
|
||||
@ -185,12 +185,18 @@
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.gavaghan/geodesy -->
|
||||
<dependency>
|
||||
<groupId>org.gavaghan</groupId>
|
||||
<artifactId>geodesy</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--打票机 使用的库 开始-->
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient-win -->
|
||||
@ -218,7 +224,6 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
|
||||
|
||||
@ -7,6 +7,11 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.suisung.mall.common.utils.PropertiesUtil;
|
||||
import com.suisung.mall.shop.entity.LocationBean;
|
||||
|
||||
import org.gavaghan.geodesy.Ellipsoid;
|
||||
import org.gavaghan.geodesy.GeodeticCalculator;
|
||||
import org.gavaghan.geodesy.GeodeticCurve;
|
||||
import org.gavaghan.geodesy.GlobalCoordinates;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BaiduUtil {
|
||||
@ -15,6 +20,12 @@ public class BaiduUtil {
|
||||
final static String ADDRESS_TO_LONGITUDEA_URL = "https://api.map.baidu.com/geocoding/v3/?address=";
|
||||
final static String BAIDU_GET_ADDRESS_URL = "http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location=";
|
||||
|
||||
/**
|
||||
* 通过地址获取经纬度
|
||||
*
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
public static LocationBean getLatAndLngByAddress(String address) {
|
||||
if (StrUtil.isBlank(address)) {
|
||||
return null;
|
||||
@ -31,6 +42,13 @@ public class BaiduUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过经纬度获取地址
|
||||
*
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @return
|
||||
*/
|
||||
public static String getAddressByLocation(String lng, String lat) {
|
||||
String url = BAIDU_GET_ADDRESS_URL + lat + "," + lng + "&output=json&pois=1&ak=" + AK;
|
||||
String strResult = HttpUtil.get(url);
|
||||
@ -46,4 +64,26 @@ public class BaiduUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据两点获取距离
|
||||
* 参考:https://www.cnblogs.com/xuzhw/p/10143626.html
|
||||
* 对比百度地图,计算结果和Sphere坐标系计算结果一致,表明计算结果正确,WGS84坐标系的计算结果存在几十米的误差。
|
||||
* 不同的坐标系精度不同,计算结果不一样。大家根据实际情况自己选择
|
||||
*
|
||||
* @param longitudeFrom
|
||||
* @param latitudeFrom
|
||||
* @param longitudeTo
|
||||
* @param latitudeTo
|
||||
* @return
|
||||
*/
|
||||
public static Double getDistance(Double longitudeFrom, Double latitudeFrom, Double longitudeTo, Double latitudeTo) {
|
||||
if (longitudeFrom == null || latitudeFrom == null || longitudeTo == null || latitudeTo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GlobalCoordinates source = new GlobalCoordinates(latitudeFrom, longitudeFrom);
|
||||
GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo);
|
||||
return new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target).getEllipsoidalDistance();
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.suisung.mall.common.api.*;
|
||||
import com.suisung.mall.common.constant.CommonConstant;
|
||||
import com.suisung.mall.common.constant.ConfigConstant;
|
||||
import com.suisung.mall.common.constant.ConstantError;
|
||||
import com.suisung.mall.common.constant.MqConstant;
|
||||
import com.suisung.mall.common.domain.UserDto;
|
||||
import com.suisung.mall.common.exception.ApiException;
|
||||
@ -1425,6 +1426,11 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
ShopUserDeliveryAddress deliveryAddress = userDeliveryAddressService.get((Integer) ud_id);
|
||||
Map address_row = Convert.toMap(String.class, Object.class, deliveryAddress);
|
||||
cart_data.put("address_row", address_row);
|
||||
|
||||
// 用户选中的收货地址 2024-12-05 add
|
||||
cart_data.put("delivery_address_row", deliveryAddress);
|
||||
cart_data.put("is_delivery", true);
|
||||
|
||||
} else {
|
||||
cart_data.put("is_delivery", false);
|
||||
}
|
||||
@ -1463,7 +1469,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
cart_data.put("ac_id", ac_id); // 拼团ID, 为0,在创建拼团
|
||||
}
|
||||
|
||||
// 处理邮费情况
|
||||
// 注:(重要)邮费检测和计算
|
||||
dealWithCalFee(cal_freight, cart_data, chain_id, is_edu);
|
||||
|
||||
// 判断是否上传素材
|
||||
@ -1560,7 +1566,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
if (address_row != null) {
|
||||
Integer district_id = Convert.toInt(address_row.get("ud_city_id"));
|
||||
// 注:(重要)配送费检测和计算
|
||||
shopUserCartService.calTransportFreight(cart_data, district_id);
|
||||
shopUserCartService.tryCalTransportFreight(cart_data, district_id,true);
|
||||
|
||||
boolean can_delivery = (boolean) cart_data.get("can_delivery");
|
||||
if (!can_delivery) {
|
||||
@ -5942,7 +5948,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
// 如果没有配送地址,则忽略地址选择问题。
|
||||
if (deliveryAddress != null && deliveryAddress.getUd_city_id() != null) {
|
||||
Integer district_id = deliveryAddress.getUd_city_id();
|
||||
shopUserCartService.calTransportFreight(cart_data, district_id); // 配送运费检测和计算
|
||||
shopUserCartService.tryCalTransportFreight(cart_data, district_id,true); // 配送运费检测和计算
|
||||
} else {
|
||||
throw new ApiException(I18nUtil._("请选择正确的收货地址!"));
|
||||
}
|
||||
@ -6045,6 +6051,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
ShopOrderData data_row = new ShopOrderData();
|
||||
String type_code = shopBaseStateCodeService.getCode(order_type, "state_code_code");
|
||||
|
||||
// 订单编号生成
|
||||
type_code = StrUtil.isBlank(type_code) ? "DD" : type_code;
|
||||
String xid = RootContext.getXID();
|
||||
RootContext.unbind();
|
||||
@ -6237,7 +6244,8 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
|
||||
Integer chain_store_id = chain_row.getStore_id();
|
||||
Integer base_store_id = (Integer) base_row.get("store_id");
|
||||
Integer delivery_type_id = (Integer) checkout_row.get("delivery_type_id");
|
||||
// TODO 注:配送方式:5-到店自提;10-普通快递;16-同城配送;
|
||||
Integer delivery_type_id = StateCode.DELIVERY_TYPE_SAME_CITY; //(Integer) checkout_row.get("delivery_type_id");
|
||||
|
||||
// 订单信息保存处理
|
||||
if (flag) {
|
||||
@ -8291,31 +8299,34 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
*/
|
||||
public SFCreateOrderReq buildSFOrderData(Integer devId, String orderId, Long orderPickupNum) {
|
||||
if (StrUtil.isBlank(orderId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ShopStoreBase shopStoreBase = shopStoreBaseService.get(orderId);
|
||||
ShopStoreInfo shopStoreInfo = shopStoreInfoService.get(orderId);
|
||||
ShopOrderDeliveryAddress shopOrderDeliveryAddress = shopOrderDeliveryAddressService.selectByOrderId(orderId);
|
||||
if (shopStoreBase == null || shopStoreInfo == null || shopOrderDeliveryAddress == null) {
|
||||
logger.error("缺少店铺Id");
|
||||
return null;
|
||||
}
|
||||
|
||||
ShopOrderBase shopOrderBase = shopOrderBaseService.getById(orderId);
|
||||
|
||||
QueryWrapper<ShopOrderItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_id", orderId);
|
||||
List<ShopOrderItem> shopOrderItemList = shopOrderItemService.list(queryWrapper);
|
||||
if (shopOrderBase == null || CollUtil.isEmpty(shopOrderItemList)) {
|
||||
logger.error("无法获取订单信息!");
|
||||
return null;
|
||||
}
|
||||
|
||||
ShopStoreBase shopStoreBase = shopStoreBaseService.get(shopOrderBase.getStore_id());
|
||||
ShopStoreInfo shopStoreInfo = shopStoreInfoService.get(shopOrderBase.getStore_id());
|
||||
ShopOrderDeliveryAddress shopOrderDeliveryAddress = shopOrderDeliveryAddressService.selectByOrderId(orderId);
|
||||
if (shopStoreBase == null || shopStoreInfo == null || shopOrderDeliveryAddress == null) {
|
||||
logger.error("无法获取店铺信息!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 7位数取单号,位数不够向左补0
|
||||
String orderPickupNumStr = String.format("%07d", orderPickupNum);
|
||||
|
||||
// TODO 顺丰同城业务员给的店铺id
|
||||
String shopId = "3243279847393";
|
||||
SFCreateOrderReq sfCreateOrderReq = new SFCreateOrderReq();
|
||||
sfCreateOrderReq.setDev_id(devId);
|
||||
sfCreateOrderReq.setShop_id(shopStoreBase.getStore_id().toString());
|
||||
sfCreateOrderReq.setShop_id(shopId); // TODO 顺丰同城业务员给的店铺id
|
||||
sfCreateOrderReq.setPush_time(DateUtil.currentSeconds());
|
||||
sfCreateOrderReq.setShop_order_id(orderId);
|
||||
sfCreateOrderReq.setOrder_time(shopOrderBase.getOrder_time().getTime() / 1000);
|
||||
@ -8373,7 +8384,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
Pair<Boolean, StandardAddressDTO> pairReceiveAddr = shopOrderDeliveryAddressService.checkAddress(shopOrderDeliveryAddress);
|
||||
SFOrderReceiveReq receive = new SFOrderReceiveReq();
|
||||
receive.setUser_name(shopOrderDeliveryAddress.getDa_name());
|
||||
receive.setUser_phone(shopOrderDeliveryAddress.getDa_telephone());
|
||||
receive.setUser_phone(shopOrderDeliveryAddress.getDa_mobile());
|
||||
receive.setUser_address(pairReceiveAddr.getSecond().getFullAddress());
|
||||
receive.setUser_lng(pairReceiveAddr.getSecond().getLongitude());
|
||||
receive.setUser_lat(pairReceiveAddr.getSecond().getLatitude());
|
||||
|
||||
@ -33,7 +33,7 @@ public class ShopStorePrinterController {
|
||||
@ApiOperation(value = "内部测试案例", notes = "内部测试案例")
|
||||
@RequestMapping(value = "/testcase", method = {RequestMethod.GET})
|
||||
public CommonResult TestCase() {
|
||||
Object data = shopStoreSameCityTransportBaseService.computeSameCityTransportFee(2L, BigDecimal.valueOf(120.085), BigDecimal.valueOf(23.37), 20000, BigDecimal.valueOf(102), BigDecimal.valueOf(96), BigDecimal.valueOf(94),true);
|
||||
Object data = shopStoreSameCityTransportBaseService.computeSameCityTransportFee(3L, BigDecimal.valueOf(110.07123874241765), BigDecimal.valueOf(23.366250981849255), 100, BigDecimal.valueOf(0.5), BigDecimal.valueOf(5.5), BigDecimal.valueOf(5.5),true);
|
||||
|
||||
return CommonResult.success(data);
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ package com.suisung.mall.shop.store.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
@ -37,6 +38,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -237,8 +239,6 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 计算同城订单配送费
|
||||
*
|
||||
@ -254,31 +254,28 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
*/
|
||||
@Override
|
||||
public SameCityDeliveryFeeRespDTO computeSameCityTransportFee(Long storeId, BigDecimal orderLongitude, BigDecimal orderLatitude, Integer weightGram, BigDecimal orderProductAmount, BigDecimal orderDiscountAmount, BigDecimal orderPayAmount, Boolean canThrow) {
|
||||
// 计算订单同城配送费,
|
||||
// 计算订单同城配送费,该函数的流程说明:
|
||||
// 1.先获取订单的经纬度,计算配送距离,获取配送范围,确定是否能配送,如果能计算基础运费?
|
||||
// 2.如果能配送,再订单总重量,订单原价金额,订单折后金额,订单实付金额
|
||||
// 3.根据两点经纬度,计算配送距离,结合订单总重量,计算基础运费。
|
||||
// 4.查看是否有运费优惠设置,如果有,就直接从基础运费中扣除优惠运费,得出最终的订单配送费。
|
||||
|
||||
// 该订单能否配送?
|
||||
Boolean canDelivery = false;
|
||||
|
||||
if (CommonUtil.hasAnyBlank(storeId, orderLongitude, orderLatitude) || storeId <= 0) {
|
||||
logger.error("同城配送费计算时,缺少必要的参数。");
|
||||
if (storeId == null || orderLongitude == null || orderLatitude == null || storeId <= 0) {
|
||||
logger.error("同城配送费计算时,缺少必要参数。");
|
||||
if (canThrow) {
|
||||
throw new ApiException(I18nUtil._("同城配送费计算时,缺少必要的参数。"));
|
||||
throw new ApiException(I18nUtil._("同城配送费计算缺少必要参数。"));
|
||||
}
|
||||
return new SameCityDeliveryFeeRespDTO(canDelivery, false, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "同城配送费计算时,缺少必要的参数。");
|
||||
return new SameCityDeliveryFeeRespDTO(false, false, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "同城配送费计算缺少必要的参数。");
|
||||
}
|
||||
|
||||
// 获取基础运费设置记录
|
||||
ShopStoreSameCityTransportBase transportBase = getShopStoreSameCityTransportBaseById(storeId);
|
||||
if (CommonUtil.hasAnyBlank(transportBase, transportBase.getStore_longitude(), transportBase.getStore_latitude(), transportBase.getDistance_base(), transportBase.getDelivery_base_fee())) {
|
||||
if (ObjectUtil.isNull(transportBase) || ObjectUtil.isNull(transportBase.getStore_longitude()) || ObjectUtil.isNull(transportBase.getStore_latitude()) || ObjectUtil.isNull(transportBase.getDistance_base()) || ObjectUtil.isNull(transportBase.getDelivery_base_fee())) {
|
||||
logger.error("同城配送费计算:无法获取基础运费设置记录,或店铺经纬度为空");
|
||||
if (canThrow) {
|
||||
throw new ApiException(I18nUtil._("商家未作同城配送设置。"));
|
||||
throw new ApiException(I18nUtil._("商家尚未配置同城配送相关设置。"));
|
||||
}
|
||||
return new SameCityDeliveryFeeRespDTO(canDelivery, false, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "商家未作同城配送设置。");
|
||||
return new SameCityDeliveryFeeRespDTO(false, false, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "商家尚未配置同城配送相关设置。");
|
||||
}
|
||||
|
||||
// 通过高德或百度地图api,计算两点的距离,如果服务不可用或无法计算,使用内部算法计算距离(单位米)
|
||||
@ -289,8 +286,7 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
// ### 基础配送费计算
|
||||
BigDecimal deliveryBaseFee = transportBase.getDelivery_base_fee();
|
||||
// 每增加一个距离累加运费
|
||||
if (CommonUtil.isAllNotBlank(transportBase.getDistance_increase_km(), transportBase.getDistance_increase_fee(), transportBase.getDistance_base()) && distance > transportBase.getDistance_base() * 1000) {
|
||||
// if (transportBase.getDistance_increase_km() != null && transportBase.getDistance_increase_fee() != null && transportBase.getDistance_base() != null && distance > transportBase.getDistance_base() * 1000) {
|
||||
if (transportBase.getDistance_increase_km() != null && transportBase.getDistance_increase_fee() != null && transportBase.getDistance_base() != null && distance > transportBase.getDistance_base() * 1000) {
|
||||
// 实际配送距离超出基础距离,单位km
|
||||
BigDecimal diffDistanceM = CommonUtil.DecimalRoundHalfUp(BigDecimal.valueOf(distance - transportBase.getDistance_base() * 1000).divide(BigDecimal.valueOf(1000)));
|
||||
// 累加的次数
|
||||
@ -308,8 +304,7 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
}
|
||||
|
||||
// 每增加一个重量累加运费(重量暂时忽略,配置的时候设置0)
|
||||
if (CommonUtil.isAllNotBlank(transportBase.getWeight_increase_kg(), transportBase.getWeight_increase_fee(), transportBase.getWeight_base()) && weightGram > transportBase.getWeight_base() * 1000) {
|
||||
// if (transportBase.getWeight_increase_kg() != null && transportBase.getWeight_increase_fee() != null && transportBase.getWeight_base() != null && weightGram > transportBase.getWeight_base() * 1000) {
|
||||
if (transportBase.getWeight_increase_kg() != null && transportBase.getWeight_increase_fee() != null && transportBase.getWeight_base() != null && weightGram > transportBase.getWeight_base() * 1000) {
|
||||
// 实际配送重量超出基础重量,单位kg
|
||||
BigDecimal diffWeightKg = CommonUtil.DecimalRoundHalfUp(BigDecimal.valueOf(weightGram - transportBase.getWeight_base() * 1000).divide(BigDecimal.valueOf(1000)));
|
||||
// 累加的次数
|
||||
@ -339,10 +334,14 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
return new SameCityDeliveryFeeRespDTO(true, false, deliveryBaseFee, BigDecimal.ZERO, deliveryBaseFee, "");
|
||||
}
|
||||
|
||||
int canDeliveryAreaCnt = 0;
|
||||
String canNotDeliveryReason = "有订单不在配送范围内或订单未达起送金额,请检查!";
|
||||
for (ShopStoreSameCityTransport transport : transportList) {
|
||||
// 判断订单距离在不在配送范围内?
|
||||
if (transport.getMax_delivery_radius() < distance) {
|
||||
// 订单距离不在配送范围内,返回不送了
|
||||
canDelivery = false;
|
||||
// canNotDeliveryReason = "有订单超出配送范围,请检查下单店铺位置!";//String.format("有订单超出%d米的配送范围!",transport.getMax_delivery_radius());
|
||||
canDeliveryAreaCnt+=1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -351,13 +350,12 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
(CommonConstant.Delivery_Amount_Comput_Type_Discounted.equals(transport.getMin_delivery_amount_type()) && transport.getMin_delivery_amount().compareTo(orderDiscountAmount) > 0) ||
|
||||
(CommonConstant.Delivery_Amount_Comput_Type_Payment.equals(transport.getMin_delivery_amount_type()) && transport.getMin_delivery_amount().compareTo(orderPayAmount) > 0)) {
|
||||
// 订单原价金额小于起送金额,返回订单不能送达了
|
||||
canDelivery = false;
|
||||
// canNotDeliveryReason ="有订单未满足起送金额,请检查您的订单金额!"; //String.format("有订单未满足%.2f元起送金额!",transport.getMin_delivery_amount());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!canDelivery) {
|
||||
canDelivery = true;
|
||||
}
|
||||
canDeliveryAreaCnt+=1;
|
||||
canNotDeliveryReason="";
|
||||
|
||||
// 获取优惠的配送费
|
||||
if ((CommonConstant.Delivery_Amount_Comput_Type_Original.equals(transport.getDelivery_discount_type()) && transport.getMin_delivery_discount_amount().compareTo(orderProductAmount) <= 0) ||
|
||||
@ -371,17 +369,17 @@ public class ShopStoreSameCityTransportBaseServiceImpl extends BaseServiceImpl<S
|
||||
}
|
||||
}
|
||||
|
||||
if(!canDelivery) {
|
||||
if (canDeliveryAreaCnt <= 0) {
|
||||
if (canThrow) {
|
||||
throw new ApiException(I18nUtil._("有订单不在配送范围内,请检查店铺的距离位置!"));
|
||||
throw new ApiException(I18nUtil._(canNotDeliveryReason));
|
||||
}
|
||||
return new SameCityDeliveryFeeRespDTO(false, false, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "有订单不在配送范围内,请检查订单详情!");
|
||||
return new SameCityDeliveryFeeRespDTO(false, false, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, canNotDeliveryReason);
|
||||
}
|
||||
|
||||
// 配送费不能负数,就是说优惠运费不能高于基础运费
|
||||
BigDecimal deliveryFee = deliveryBaseFee.subtract(reduceDeliveryFee);
|
||||
boolean isFee = deliveryFee.compareTo(BigDecimal.ZERO) <= 0;
|
||||
|
||||
return new SameCityDeliveryFeeRespDTO(canDelivery, isFee, deliveryBaseFee, reduceDeliveryFee, isFee ? BigDecimal.ZERO : deliveryFee, "");
|
||||
return new SameCityDeliveryFeeRespDTO(true, isFee, deliveryBaseFee, reduceDeliveryFee, isFee ? BigDecimal.ZERO : deliveryFee, "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,6 +131,18 @@ public interface ShopUserCartService extends IBaseService<ShopUserCart> {
|
||||
*/
|
||||
Map formatCartRows(List<Map> cart_rows, Map activity_rows, ProductVo productVo, FixOrderVo fixOrderVo);
|
||||
|
||||
/**
|
||||
* 尝试去操作:配送区域判断及运费, 并修正最终数据
|
||||
* <p>
|
||||
* 1、单品在一个订单中,运费规则计算
|
||||
* 2、配送区域问题
|
||||
*
|
||||
* @param cart_data 最终数据
|
||||
* @param district_id 配送地区(城市id)
|
||||
* @param canThrow 关键数据缺失,抛出 api 异常错误
|
||||
*/
|
||||
void tryCalTransportFreight(Map cart_data, Integer district_id, boolean canThrow);
|
||||
|
||||
/**
|
||||
* 配送区域判断及运费, 并修正最终数据
|
||||
* <p>
|
||||
|
||||
@ -53,7 +53,6 @@ import com.suisung.mall.shop.user.service.ShopUserCartService;
|
||||
import com.suisung.mall.shop.user.service.ShopUserDeliveryAddressService;
|
||||
import com.suisung.mall.shop.user.service.ShopUserVoucherService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -143,7 +142,7 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
private ShopProductImageService shopProductImageService;
|
||||
|
||||
@Resource
|
||||
private ShopStoreSameCityTransportBaseService shopStoreSameCityTransportBaseService;
|
||||
private ShopStoreSameCityTransportBaseService shopStoreSameCityTransportBaseService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@ -749,6 +748,9 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
}
|
||||
}
|
||||
|
||||
data.put("address_row", address_row); // 用户所有的收货地址
|
||||
data.put("delivery_address_row", delivery_address_row); //用户选择的收货地址
|
||||
|
||||
// 城市id
|
||||
Integer district_id = Convert.toInt(delivery_address_row.get("ud_city_id"));
|
||||
if (CollUtil.isNotEmpty(delivery_address_row) && CheckUtil.isNotEmpty(district_id)) {
|
||||
@ -767,9 +769,6 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
data.put("show_oos", !has_stock); //无库存
|
||||
}
|
||||
|
||||
data.put("address_row", address_row); // 用户所有的收货地址
|
||||
data.put("delivery_address_row", delivery_address_row); //用户选择的收货地址
|
||||
|
||||
// todo validPeriod
|
||||
|
||||
// 配送时间
|
||||
@ -2461,25 +2460,32 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
}
|
||||
|
||||
/**
|
||||
* 配送区域判断及运费, 并修正最终数据
|
||||
* 尝试去操作:配送区域判断及运费, 并修正最终数据
|
||||
* <p>
|
||||
* 1、单品在一个订单中,运费规则计算
|
||||
* 2、配送区域问题
|
||||
*
|
||||
* @param cart_data 最终数据
|
||||
* @param district_id 配送地区(城市id)
|
||||
* @param canThrow 关键数据缺失,抛出 api 异常错误
|
||||
*/
|
||||
@Override
|
||||
public void calTransportFreight(Map cart_data, Integer district_id) {
|
||||
if(cart_data==null || district_id==null){
|
||||
public void tryCalTransportFreight(Map cart_data, Integer district_id, boolean canThrow) {
|
||||
if (cart_data == null || district_id == null) {
|
||||
throw new ApiException(I18nUtil._("参数有误!"));
|
||||
}
|
||||
|
||||
boolean can_delivery = true;
|
||||
// 配送方式 5-门店自取;10-普通快递;16-同城配送;
|
||||
Integer delivery_type_id = Convert.toInt(cart_data.get("delivery_type_id"), StateCode.DELIVERY_TYPE_SAME_CITY);
|
||||
|
||||
// 同城配送运费计算分支
|
||||
if (delivery_type_id == StateCode.DELIVERY_TYPE_SAME_CITY) {
|
||||
ShopUserDeliveryAddress uAddress = Convert.convert(ShopUserDeliveryAddress.class, cart_data.get("delivery_address_row"));
|
||||
if (uAddress == null && canThrow) {
|
||||
throw new ApiException(I18nUtil._("至少选择一个配送地址!"));
|
||||
}
|
||||
|
||||
// 配送不到这个区域商品id
|
||||
cart_data.put("transport_type_none_ids", new ArrayList());
|
||||
// 配送不到这个区域商品记录
|
||||
@ -2492,6 +2498,13 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
// items:一个或多个店铺的订单
|
||||
List<Map> items = (List<Map>) cart_data.get("items");
|
||||
for (Map store_row : items) {
|
||||
|
||||
// 检查店铺城市和收货地址是否同一城市?
|
||||
List<Integer> storeDistrictId = Convert.toList(Integer.class, store_row.get("store_district_id"));
|
||||
if (canThrow && uAddress!=null && storeDistrictId != null && storeDistrictId.size() > 0 && !CollUtil.contains(storeDistrictId, uAddress.getUd_city_id())) {
|
||||
throw new ApiException(I18nUtil._("订单不在同一城市,请检查您下单所在店铺的具体位置!"));
|
||||
}
|
||||
|
||||
// 一个店铺的订单
|
||||
Long storeId = Convert.toLong(store_row.get("store_id"));
|
||||
BigDecimal storeLng = Convert.toBigDecimal(store_row.get("store_longitude"));
|
||||
@ -2504,27 +2517,27 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
BigDecimal orderPaymentAmount = Convert.toBigDecimal(store_row.get("productMoneySelGoods"));
|
||||
|
||||
// 同城配送运费检查和计算(只返回数据,不能配送不抛异常)
|
||||
SameCityDeliveryFeeRespDTO sameCityDeliveryFeeResp = shopStoreSameCityTransportBaseService.computeSameCityTransportFee(storeId,storeLng,storeLat,0,productMoneyOriginGoods,orderSelDiscountAmount,orderPaymentAmount,true);
|
||||
SameCityDeliveryFeeRespDTO sameCityDeliveryFeeResp = shopStoreSameCityTransportBaseService.computeSameCityTransportFee(storeId, storeLng, storeLat, 0, productMoneyOriginGoods, orderSelDiscountAmount, orderPaymentAmount, canThrow);
|
||||
|
||||
// 是否能配送(在配送范围内)
|
||||
Boolean canDelivery = sameCityDeliveryFeeResp.getCanDelivery();
|
||||
Boolean canDelivery = sameCityDeliveryFeeResp.getCanDelivery();
|
||||
|
||||
BigDecimal freight = sameCityDeliveryFeeResp.getDeliveryFee();
|
||||
// 还差 postFreeBalance 元即可免运费
|
||||
BigDecimal postFreeBalance = BigDecimal.ZERO;
|
||||
if(!sameCityDeliveryFeeResp.getIsFree()){
|
||||
postFreeBalance = sameCityDeliveryFeeResp.getBaseDeliveryFee().subtract(sameCityDeliveryFeeResp.getReduceDeliveryFee());
|
||||
if (!sameCityDeliveryFeeResp.getIsFree()) {
|
||||
postFreeBalance = sameCityDeliveryFeeResp.getBaseDeliveryFee().subtract(freight);
|
||||
}
|
||||
|
||||
store_row.put("postFree", sameCityDeliveryFeeResp.getIsFree()); // 是否免运费
|
||||
store_row.put("freight", sameCityDeliveryFeeResp.getDeliveryFee()); // 运费金额
|
||||
store_row.put("freight", freight); // 运费金额
|
||||
store_row.put("postFreeBalance", postFreeBalance); // 还需postFreeBalance元即可免邮费
|
||||
|
||||
// 订单的总运费 + 本次订单的运费
|
||||
orderSelFreightAmount = orderSelFreightAmount.add(Convert.toBigDecimal(sameCityDeliveryFeeResp.getDeliveryFee())); // 重要:订单运费金额
|
||||
|
||||
if(canDelivery) {
|
||||
if (canDelivery) {
|
||||
// 如果能配送,最终支付金额+本次订单的运费。
|
||||
orderSelMoneyAmount = orderSelMoneyAmount.add(Convert.toBigDecimal(store_row.get("order_money_select_items")));// 重要:订单折后金额(订单金额-折扣金额)
|
||||
orderSelMoneyAmount = orderSelMoneyAmount.add(freight);// 重要
|
||||
}
|
||||
}
|
||||
|
||||
@ -2765,6 +2778,20 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配送区域判断及运费, 并修正最终数据
|
||||
* <p>
|
||||
* 1、单品在一个订单中,运费规则计算
|
||||
* 2、配送区域问题
|
||||
*
|
||||
* @param cart_data 最终数据
|
||||
* @param district_id 配送地区(城市id)
|
||||
*/
|
||||
@Override
|
||||
public void calTransportFreight(Map cart_data, Integer district_id) {
|
||||
tryCalTransportFreight(cart_data, district_id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* item info 基础数据, 活动的通过活动修正。
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user