1
This commit is contained in:
@@ -154,6 +154,21 @@ public class JDOrder extends BaseEntity {
|
||||
/** 后返备注中是否存在异常项(1是 0否),便于列表筛选 */
|
||||
private Integer rebateRemarkHasAbnormal;
|
||||
|
||||
/** 售价渠道:direct 直款,xianyu 闲鱼(仅 F 单使用) */
|
||||
private String sellingPriceType;
|
||||
|
||||
/** 售价(对客成交价,可手动改) */
|
||||
private Double sellingPrice;
|
||||
|
||||
/** 利润(可手动改;非 H-TF/F 一般为空) */
|
||||
private Double profit;
|
||||
|
||||
/** 售价是否手动锁定(1 是:不再按型号配置自动回填) */
|
||||
private Integer sellingPriceManual;
|
||||
|
||||
/** 利润是否手动锁定(1 是:保存时不再自动重算) */
|
||||
private Integer profitManual;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@ public class ProductJdConfig extends BaseEntity
|
||||
/** 佣金(支付) - 支付给下单人的佣金 */
|
||||
private BigDecimal commissionPay;
|
||||
|
||||
/** 参考售价(直款渠道) */
|
||||
private BigDecimal sellingPriceDirect;
|
||||
|
||||
/** 参考售价(闲鱼渠道,订单侧仍会 ×0.984 计算实收) */
|
||||
private BigDecimal sellingPriceXianyu;
|
||||
|
||||
public ProductJdConfig() {
|
||||
}
|
||||
|
||||
@@ -76,6 +82,22 @@ public class ProductJdConfig extends BaseEntity
|
||||
this.commissionPay = commissionPay;
|
||||
}
|
||||
|
||||
public BigDecimal getSellingPriceDirect() {
|
||||
return sellingPriceDirect;
|
||||
}
|
||||
|
||||
public void setSellingPriceDirect(BigDecimal sellingPriceDirect) {
|
||||
this.sellingPriceDirect = sellingPriceDirect;
|
||||
}
|
||||
|
||||
public BigDecimal getSellingPriceXianyu() {
|
||||
return sellingPriceXianyu;
|
||||
}
|
||||
|
||||
public void setSellingPriceXianyu(BigDecimal sellingPriceXianyu) {
|
||||
this.sellingPriceXianyu = sellingPriceXianyu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProductJdConfig{" +
|
||||
@@ -84,6 +106,8 @@ public class ProductJdConfig extends BaseEntity
|
||||
", commission=" + commission +
|
||||
", commissionReceive=" + commissionReceive +
|
||||
", commissionPay=" + commissionPay +
|
||||
", sellingPriceDirect=" + sellingPriceDirect +
|
||||
", sellingPriceXianyu=" + sellingPriceXianyu +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ruoyi.jarvis.service;
|
||||
|
||||
import com.ruoyi.jarvis.domain.JDOrder;
|
||||
|
||||
/**
|
||||
* 订单利润/售价:按分销标识规则计算并写回订单对象(由列表保存前调用)。
|
||||
*/
|
||||
public interface IJDOrderProfitService {
|
||||
|
||||
/**
|
||||
* 根据分销标识、型号配置、手动标记等,填充售价(自动时)并计算利润。
|
||||
* 会修改传入的 {@code order}。
|
||||
*/
|
||||
void recalculate(JDOrder order);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.ruoyi.jarvis.service.impl;
|
||||
|
||||
import com.ruoyi.jarvis.domain.JDOrder;
|
||||
import com.ruoyi.jarvis.domain.ProductJdConfig;
|
||||
import com.ruoyi.jarvis.service.IJDOrderProfitService;
|
||||
import com.ruoyi.jarvis.service.IProductJdConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
@Service
|
||||
public class JDOrderProfitServiceImpl implements IJDOrderProfitService {
|
||||
|
||||
private static final double XIANYU_NET_FACTOR = 0.984;
|
||||
|
||||
@Autowired
|
||||
private IProductJdConfigService productJdConfigService;
|
||||
|
||||
@Override
|
||||
public void recalculate(JDOrder order) {
|
||||
if (order == null) {
|
||||
return;
|
||||
}
|
||||
String mark = order.getDistributionMark() == null ? "" : order.getDistributionMark().trim();
|
||||
boolean profitLocked = order.getProfitManual() != null && order.getProfitManual() == 1;
|
||||
boolean sellingLocked = order.getSellingPriceManual() != null && order.getSellingPriceManual() == 1;
|
||||
|
||||
if ("H-TF".equals(mark)) {
|
||||
order.setSellingPriceType(null);
|
||||
order.setSellingPrice(null);
|
||||
if (!profitLocked) {
|
||||
String buyer = order.getBuyer();
|
||||
boolean fan = buyer != null && buyer.trim().startsWith("凡-");
|
||||
order.setProfit(fan ? 65.0 : 15.0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ("F".equals(mark)) {
|
||||
if (!sellingLocked) {
|
||||
fillSellingPriceFromConfig(order);
|
||||
}
|
||||
if (!profitLocked) {
|
||||
computeProfitForF(order);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!profitLocked) {
|
||||
order.setProfit(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillSellingPriceFromConfig(JDOrder order) {
|
||||
String type = order.getSellingPriceType();
|
||||
if (type == null || type.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String model = order.getModelNumber();
|
||||
if (model == null || model.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ProductJdConfig cfg = productJdConfigService.selectProductJdConfigByModel(model.trim());
|
||||
if (cfg == null) {
|
||||
return;
|
||||
}
|
||||
if ("direct".equals(type)) {
|
||||
BigDecimal p = cfg.getSellingPriceDirect();
|
||||
if (p != null) {
|
||||
order.setSellingPrice(p.doubleValue());
|
||||
}
|
||||
} else if ("xianyu".equals(type)) {
|
||||
BigDecimal p = cfg.getSellingPriceXianyu();
|
||||
if (p != null) {
|
||||
order.setSellingPrice(p.doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void computeProfitForF(JDOrder order) {
|
||||
String type = order.getSellingPriceType();
|
||||
Double sp = order.getSellingPrice();
|
||||
if (type == null || type.isEmpty() || sp == null) {
|
||||
order.setProfit(null);
|
||||
return;
|
||||
}
|
||||
double pay = order.getPaymentAmount() != null ? order.getPaymentAmount() : 0.0;
|
||||
double rebate = order.getRebateAmount() != null ? order.getRebateAmount() : 0.0;
|
||||
double netReceipt;
|
||||
if ("xianyu".equals(type)) {
|
||||
netReceipt = BigDecimal.valueOf(sp).multiply(BigDecimal.valueOf(XIANYU_NET_FACTOR))
|
||||
.setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
} else if ("direct".equals(type)) {
|
||||
netReceipt = sp;
|
||||
} else {
|
||||
order.setProfit(null);
|
||||
return;
|
||||
}
|
||||
order.setProfit(BigDecimal.valueOf(netReceipt - pay - rebate)
|
||||
.setScale(2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.jarvis.service.impl;
|
||||
|
||||
import com.ruoyi.jarvis.domain.JDOrder;
|
||||
import com.ruoyi.jarvis.mapper.JDOrderMapper;
|
||||
import com.ruoyi.jarvis.service.IJDOrderProfitService;
|
||||
import com.ruoyi.jarvis.service.IJDOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -14,6 +15,9 @@ public class JDOrderServiceImpl implements IJDOrderService {
|
||||
@Autowired
|
||||
private JDOrderMapper jdOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private IJDOrderProfitService jdOrderProfitService;
|
||||
|
||||
@Override
|
||||
public List<JDOrder> selectJDOrderList(JDOrder jdOrder) {
|
||||
return jdOrderMapper.selectJDOrderList(jdOrder);
|
||||
@@ -31,6 +35,7 @@ public class JDOrderServiceImpl implements IJDOrderService {
|
||||
|
||||
@Override
|
||||
public int insertJDOrder(JDOrder jdOrder) {
|
||||
jdOrderProfitService.recalculate(jdOrder);
|
||||
return jdOrderMapper.insertJDOrder(jdOrder);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,16 @@ public class ProductJdConfigServiceImpl implements IProductJdConfigService
|
||||
config.setCommissionPay(new BigDecimal(commissionPayObj.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Object spd = map.get("sellingPriceDirect");
|
||||
if (spd != null) {
|
||||
config.setSellingPriceDirect(spd instanceof BigDecimal ? (BigDecimal) spd : new BigDecimal(spd.toString()));
|
||||
}
|
||||
Object spx = map.get("sellingPriceXianyu");
|
||||
if (spx != null) {
|
||||
config.setSellingPriceXianyu(spx instanceof BigDecimal ? (BigDecimal) spx : new BigDecimal(spx.toString()));
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
@@ -147,13 +156,28 @@ public class ProductJdConfigServiceImpl implements IProductJdConfigService
|
||||
if (StringUtils.isEmpty(productJdConfig.getProductModel())) {
|
||||
return 0;
|
||||
}
|
||||
String redisKey = PRODUCT_JD_CONFIG_KEY + productJdConfig.getProductModel();
|
||||
Map<String, Object> map = new java.util.HashMap<>();
|
||||
Map<String, Object> old = redisCache.getCacheMap(redisKey);
|
||||
if (old != null && !old.isEmpty()) {
|
||||
map.putAll(old);
|
||||
}
|
||||
map.put("productModel", productJdConfig.getProductModel());
|
||||
map.put("jdUrl", productJdConfig.getJdUrl());
|
||||
map.put("commission", productJdConfig.getCommission() != null ? productJdConfig.getCommission() : BigDecimal.ZERO);
|
||||
map.put("commissionReceive", productJdConfig.getCommissionReceive() != null ? productJdConfig.getCommissionReceive() : BigDecimal.ZERO);
|
||||
map.put("commissionPay", productJdConfig.getCommissionPay() != null ? productJdConfig.getCommissionPay() : BigDecimal.ZERO);
|
||||
redisCache.setCacheMap(PRODUCT_JD_CONFIG_KEY + productJdConfig.getProductModel(), map);
|
||||
if (productJdConfig.getSellingPriceDirect() != null) {
|
||||
map.put("sellingPriceDirect", productJdConfig.getSellingPriceDirect());
|
||||
} else {
|
||||
map.remove("sellingPriceDirect");
|
||||
}
|
||||
if (productJdConfig.getSellingPriceXianyu() != null) {
|
||||
map.put("sellingPriceXianyu", productJdConfig.getSellingPriceXianyu());
|
||||
} else {
|
||||
map.remove("sellingPriceXianyu");
|
||||
}
|
||||
redisCache.setCacheMap(redisKey, map);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user