1
This commit is contained in:
@@ -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