订单字段优化

This commit is contained in:
Jack 2025-04-09 14:41:14 +08:00
parent fd1f9aff97
commit 37c3333665
15 changed files with 174 additions and 24 deletions

View File

@ -18,6 +18,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
@ -51,7 +52,7 @@ public class ShopMerchEntry implements Serializable {
private Integer biz_second_category;
@ApiModelProperty(value = "除去运费的商家分成比列95.00最大100最小0")
private String split_ratio;
private BigDecimal split_ratio;
@ApiModelProperty(value = "分账到账方式1-T+02-T+13-T+3...")
private Integer settlement_method;

View File

@ -92,6 +92,9 @@ public class ShopOrderData implements Serializable {
@ApiModelProperty(value = "实际运费金额-卖家可修改")
private BigDecimal order_shipping_fee;
@ApiModelProperty(value = "平台费(分给平台或代理商的费用),根据不同的店铺分类,从商品原价中扣除相应的费用。")
private BigDecimal platform_fee;
@ApiModelProperty(value = "代金券id/优惠券/返现:发放选择使用")
private Integer voucher_id;

View File

@ -49,7 +49,9 @@ public class MchOrderInfoDTO implements Serializable {
@ApiModelProperty(value = "订单标题")
private String order_title;
@ApiModelProperty(value = "同城配送取单号")
private String order_pickup_num;
private Long order_pickup_num;
@ApiModelProperty(value = "同城配送取单号字符串方式")
private String order_pickup_num_str;
@ApiModelProperty(value = "下单时间")
private Date order_time;
@ApiModelProperty(value = "支付时间")
@ -68,6 +70,10 @@ public class MchOrderInfoDTO implements Serializable {
private Integer delivery_type_id;
@ApiModelProperty(value = "订单运费")
private BigDecimal order_shipping_fee;
@ApiModelProperty(value = "平台费")
private BigDecimal platform_fee;
@ApiModelProperty(value = "优惠、折扣、活动费用")
private BigDecimal order_discount_amount;
@ApiModelProperty(value = "两点距离,单位米")
private Integer distance;

View File

@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
@ -122,4 +123,8 @@ public class ShopStoreBase implements Serializable {
@ApiModelProperty(value = "微信小程序二维码图片路径")
private String wx_qrcode;
@ApiModelProperty(value = "店铺分账比例数值 0.00-100.00 范围内,数值根据店铺分类计算得出,也可以超管指定一个数值。")
private BigDecimal split_ratio;
}

View File

@ -4,11 +4,14 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.suisung.mall.common.api.StateCode;
import com.suisung.mall.common.exception.ApiException;
import org.apache.commons.codec.binary.Base64;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.*;
@ -16,8 +19,6 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.codec.binary.Base64;
import org.springframework.util.StringUtils;
/**
* 常用工具方法
@ -154,7 +155,7 @@ public class CommonUtil {
* @return
*/
public static BigDecimal DecimalRoundHalfUp(BigDecimal d) {
return d.setScale(0, BigDecimal.ROUND_HALF_UP);
return d.setScale(0, RoundingMode.HALF_UP);
}
@ -236,6 +237,7 @@ public class CommonUtil {
/**
* 生成 md 摘要通用签名参考了顺丰同城的做法
* 参考https://openic.sf-express.com/#/quickstart
*
* @param postData
* @param appId
* @param appKey
@ -244,14 +246,14 @@ public class CommonUtil {
public static String generateOpenSign(String postData, String appId, String appKey) {
try {
if (StrUtil.isBlank(postData)|| StrUtil.isBlank(appId)|| StrUtil.isBlank(appKey)) {
if (StrUtil.isBlank(postData) || StrUtil.isBlank(appId) || StrUtil.isBlank(appKey)) {
logger.error("生成签名时缺少必要参数!");
return Strings.EMPTY;
}
StringBuilder sb = new StringBuilder(postData).append("&").append(appId).append("&").append(appKey);
String sb = postData + "&" + appId + "&" + appKey;
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] md5 = md.digest(sb.toString().getBytes(StandardCharsets.UTF_8));
byte[] md5 = md.digest(sb.getBytes(StandardCharsets.UTF_8));
int i;
StringBuffer buf = new StringBuffer();
for (byte b : md5) {
@ -274,6 +276,7 @@ public class CommonUtil {
/**
* 验证MD5摘要签名
*
* @param sign
* @param postData
* @param appId
@ -281,13 +284,13 @@ public class CommonUtil {
* @return
*/
public static boolean checkOpenSign(String sign, String postData, String appId, String appKey) {
if (StrUtil.isBlank(sign) || StrUtil.isBlank(postData)|| StrUtil.isBlank(appId)|| StrUtil.isBlank(appKey)) {
if (StrUtil.isBlank(sign) || StrUtil.isBlank(postData) || StrUtil.isBlank(appId) || StrUtil.isBlank(appKey)) {
logger.error("验签时缺少必要参数!");
return false;
}
String sn = generateOpenSign(postData, appId, appKey);
if(StringUtils.isEmpty(sn)){
if (StringUtils.isEmpty(sn)) {
logger.error("签名无效!");
return false;
}
@ -295,5 +298,18 @@ public class CommonUtil {
return sign.equals(sn);
}
/**
* 检查分账比例的数值是否在 0.00-100.00 范围内
*
* @param splitRatio
* @return
*/
public static boolean checkSplitRatio(BigDecimal splitRatio) {
if (splitRatio == null) {
return false;
}
return splitRatio.compareTo(BigDecimal.ZERO) >= 0 && splitRatio.compareTo(new BigDecimal(100)) <= 0;
}
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suisung.mall.common.modules.base.ShopBaseStoreCategory;
import com.suisung.mall.core.web.service.IBaseService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -30,4 +31,12 @@ public interface ShopBaseStoreCategoryService extends IBaseService<ShopBaseStore
*/
List<ShopBaseStoreCategory> selectParentListWithChildren(String keyword);
/**
* 获取店铺分类的分账比例数值
*
* @param storeCategoryId
* @return
*/
BigDecimal getStoreCategoryRatio(Integer storeCategoryId);
}

View File

@ -2,14 +2,17 @@ package com.suisung.mall.shop.base.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suisung.mall.common.modules.base.ShopBaseStoreCategory;
import com.suisung.mall.common.utils.CommonUtil;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.base.mapper.ShopBaseStoreCategoryMapper;
import com.suisung.mall.shop.base.service.ShopBaseStoreCategoryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -107,4 +110,28 @@ public class ShopBaseStoreCategoryServiceImpl extends BaseServiceImpl<ShopBaseSt
});
return tree;
}
@Override
public BigDecimal getStoreCategoryRatio(Integer storeCategoryId) {
BigDecimal splitRatio = new BigDecimal(100);
if (ObjectUtil.isEmpty(storeCategoryId)) {
return splitRatio;
}
ShopBaseStoreCategory shopBaseStoreCategory = get(storeCategoryId);
if (ObjectUtil.isEmpty(shopBaseStoreCategory)) {
return splitRatio;
}
splitRatio = shopBaseStoreCategory.getSplit_ratio();
if (splitRatio == null) {
splitRatio = new BigDecimal(100);
}
if (!CommonUtil.checkSplitRatio(splitRatio)) {
splitRatio = new BigDecimal(100);
}
return splitRatio;
}
}

View File

@ -8304,8 +8304,8 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
orderItems.add(ent.rebuild());
}
// 7位数取单号位数不够向左补0 同城配送的取单号
m.put("order_pickup_num_str", String.format("%07d", m.get("order_pickup_num")));
// 7位数取单号位数不够向左补0 同城配送的取单号String.format("%07d", m.get("order_pickup_num"))
m.put("order_pickup_num_str", fmtPickNum(Convert.toLong(m.get("order_pickup_num"))));
m.put("seller_message", "");//卖家留言
m.put("order_items", orderItems);//订单商品列表
m.put("order_items_count", orderItems.size());//商品数量
@ -8513,6 +8513,9 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
// 发快递普通物流的物流轨迹
mchOrderInfoDTO.setLogistics_traces(kdApiExpressSearchService.getLogisticsTraces(mchOrderInfoDTO.getOrder_id()));
}
// 取货号格式化
mchOrderInfoDTO.setOrder_pickup_num_str(fmtPickNum(mchOrderInfoDTO.getOrder_pickup_num()));
});
}
@ -8633,4 +8636,22 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
return jsonObject;
}
/**
* 取货单号格式化
*
* @param pickNum 一般是 Long 类型
* @return
*/
protected String fmtPickNum(Long pickNum) {
if (pickNum == null || pickNum <= 0) {
return "";
}
if (pickNum > 9999999) {
return String.valueOf(pickNum);
}
return String.format("%07d", pickNum);
}
}

View File

@ -12,6 +12,7 @@ import com.suisung.mall.core.web.service.IBaseService;
import org.springframework.data.util.Pair;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -160,4 +161,14 @@ public interface ShopStoreBaseService extends IBaseService<ShopStoreBase> {
* @return
*/
Boolean updateStoreBaseQrCode(Integer storeId, String wxQrCode);
/**
* 获取店铺的平台分账比例
* 根据店铺的大分小分类来计算分账比例
*
* @param storeId
* @param reCalculate 是否根据店铺的分类来重新计算
* @return 平台分账比例的数值
*/
BigDecimal getStorePlatformRatio(Integer storeId, boolean reCalculate);
}

View File

@ -25,6 +25,7 @@ import com.suisung.mall.common.utils.StringUtils;
import com.suisung.mall.common.utils.phone.PhoneNumberUtils;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.base.service.AccountBaseConfigService;
import com.suisung.mall.shop.base.service.ShopBaseStoreCategoryService;
import com.suisung.mall.shop.components.TaskService;
import com.suisung.mall.shop.esign.service.EsignContractFillingFileService;
import com.suisung.mall.shop.esign.service.EsignContractService;
@ -72,6 +73,9 @@ public class ShopMerchEntryServiceImpl extends BaseServiceImpl<ShopMerchEntryMap
@Resource
private ShopStoreBaseService shopStoreBaseService;
@Resource
private ShopBaseStoreCategoryService shopBaseStoreCategoryService;
@Autowired
private TaskService taskService;
@ -470,6 +474,8 @@ public class ShopMerchEntryServiceImpl extends BaseServiceImpl<ShopMerchEntryMap
approvalRemark = "审核未通过,请继续完善入驻资料信息。";
}
// 自动计算商家分成比例
record.setSplit_ratio(shopBaseStoreCategoryService.getStoreCategoryRatio(record.getBiz_category()));
updateWrapper.eq("id", id)
.set("approval_status", approvalStatus)

View File

@ -3024,10 +3024,12 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
ShopStoreBase shopStoreBase = new ShopStoreBase();
shopStoreBase.setUser_id(userId); // 店铺管理员用户Id
shopStoreBase.setStore_name(shopMerchEntry.getStore_name());
shopStoreBase.setStore_category_id(shopMerchEntry.getBiz_category());
shopStoreBase.setStore_category_id(shopMerchEntry.getBiz_category()); // 重要店铺分类id对应 shop_base_store_category 表的分类
shopStoreBase.setSplit_ratio(shopMerchEntry.getSplit_ratio()); // 分账比例
String storeFacadeImage = shopMerchEntry.getFront_facade_image();
shopStoreBase.setStore_logo(storeFacadeImage); // 临时使用门面照片做logo
// 省市区记录有序列表
List<ShopBaseDistrict> districtList = shopBaseDistrictService.getFullDistrictByDistrictCode(shopMerchEntry.getCounty_id());
shopStoreBase.setStore_district_id(shopBaseDistrictService.joinDistrict(districtList, 1, true, "/"));
@ -3420,6 +3422,49 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
return update(updateWrapper);
}
/**
* 获取店铺的平台分账比例
* 根据店铺的大分小分类来计算分账比例
*
* @param storeId
* @param reCalculate 是否根据店铺的分类来重新计算
* @return 平台分账比例的数值
*/
@Override
public BigDecimal getStorePlatformRatio(Integer storeId, boolean reCalculate) {
if (ObjectUtil.isEmpty(storeId)) {
return null;
}
ShopStoreBase shopStoreBase = get(storeId);
if (ObjectUtil.isEmpty(shopStoreBase)) {
return null;
}
BigDecimal splitRatio = shopStoreBase.getSplit_ratio();
if (splitRatio == null) {
splitRatio = new BigDecimal(100);
}
if (!reCalculate) {
return splitRatio;
}
Integer storeCategoryId = shopStoreBase.getStore_category_id();
if (ObjectUtil.isEmpty(storeCategoryId)) {
return splitRatio;
}
// 重新计算分账比例()
ShopBaseStoreCategory shopBaseStoreCategory = shopBaseStoreCategoryService.get(storeCategoryId);
if (ObjectUtil.isEmpty(shopBaseStoreCategory)) {
return splitRatio;
}
splitRatio = shopBaseStoreCategory.getSplit_ratio();
return ObjectUtil.isEmpty(splitRatio) ? new BigDecimal(100) : splitRatio;
}
/**
* 处理 store_slide 字段
*

View File

@ -120,10 +120,6 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
record.setFlag(record.getStatus());
record.setCreated_by(userId);
record.setUpdated_by(userId);
// if (record.getStatus() == null) {
// record.setStatus(CommonConstant.Enable);
// }
// 判断打票机是否已经存在
QueryWrapper<ShopStorePrinter> queryWrapper = new QueryWrapper<>();

View File

@ -553,6 +553,9 @@
<result property="arrival_time" column="arrival_time"/>
<result property="order_product_amount" column="order_product_amount"/>
<result property="order_payment_amount" column="order_payment_amount"/>
<result property="order_shipping_fee" column="order_shipping_fee"/>
<result property="order_discount_amount" column="order_discount_amount"/>
<result property="platform_fee" column="platform_fee"/>
<result property="currency_id" column="currency_id"/>
<result property="order_state_id" column="order_state_id"/>
<result property="delivery_type_id" column="delivery_type_id"/>
@ -640,6 +643,8 @@
AS is_new_buyer,
oi.payment_time,
od.order_shipping_fee,
od.order_discount_amount,
od.platform_fee,
od.order_message,
sb.store_id,
sb.store_name,

View File

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.suisung.mall.shop.order.mapper.ShopOrderDataMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
order_id
, order_desc, order_delay_time, delivery_type_id, delivery_time_id, delivery_time, delivery_time_rang,
delivery_time_h, delivery_time_i, delivery_istimer, invoice_type_id, invoice_company_code, order_invoice_title,
order_message, order_item_amount, order_discount_amount, order_adjust_fee, order_points_fee,
order_shipping_fee_amount, order_shipping_fee, voucher_id, voucher_number, voucher_price, redpacket_id,
order_shipping_fee_amount, order_shipping_fee, platform_fee, voucher_id, voucher_number, voucher_price, redpacket_id,
redpacket_number, redpacket_price, order_redpacket_price, order_resource_ext1, order_resource_ext2,
order_resource_ext3, trade_payment_money, trade_payment_recharge_card, trade_payment_credit,
order_refund_status, order_refund_amount, order_refund_agree_amount, order_return_status, order_return_num,
@ -16,5 +15,4 @@
order_cancel_identity, order_cancel_reason, order_cancel_time, order_bp_add, order_rebate, buyer_mobile,
order_heka
</sql>
</mapper>

View File

@ -1,15 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.suisung.mall.shop.store.mapper.ShopStoreBaseMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
store_id
, user_id, store_name, store_grade_id, store_logo, store_slogan, store_domain, store_area, store_district_id,
store_address, store_latitude, store_longitude, store_is_selfsupport, store_type, store_is_open, shop_parent_id,
store_category_id, store_state_id, store_time, store_end_time, product_category_ids, store_o2o_tags,
store_o2o_flag, store_o2o_merchant_id, store_circle, subsite_id, lkl_merchant_no, lkl_term_no
store_o2o_flag, store_o2o_merchant_id, store_circle, subsite_id, lkl_merchant_no, lkl_term_no, wx_qrcode,
split_ratio
</sql>
<select id="statisticState" resultType="java.util.Map">
SELECT store_state_id state,
count(*) count
@ -93,7 +94,8 @@
a.store_workingtime,
(SELECT count(*) FROM shop_store_same_city_transport_base where store_id=b.store_id) as same_city_setting_count,
(SELECT count(*) FROM shop_chain_base where store_id=b.store_id) as chain_count,
ST_Distance_Sphere(point(b.store_longitude, b.store_latitude), point(#{params.userLng}, #{params.userLat})) as distance
ST_Distance_Sphere(point(b.store_longitude, b.store_latitude), point(#{params.userLng}, #{params.userLat})) as
distance
FROM
shop_store_base b
INNER JOIN
@ -132,5 +134,4 @@
ORDER BY distance asc
</select>
</mapper>