|
@@ -1,6 +1,7 @@
|
|
|
package com.caimei365.order.components;
|
|
|
|
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
|
+import com.caimei365.order.model.po.*;
|
|
|
import com.caimei365.order.model.vo.*;
|
|
|
import com.caimei365.order.utils.MathUtil;
|
|
|
import com.caimei365.order.utils.ImageUtil;
|
|
@@ -12,10 +13,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
/**
|
|
@@ -222,4 +221,116 @@ public class ProductService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新复购价格库
|
|
|
+ * @param order 主订单
|
|
|
+ * @param orderProduct 订单商品
|
|
|
+ * @param secondFlag 是否二手商品
|
|
|
+ * @param note 日志备注
|
|
|
+ */
|
|
|
+ public void savePurchasePrice(OrderPo order, OrderProductPo orderProduct, boolean secondFlag, String note) {
|
|
|
+ // 非二手订单, 非活动商品,非阶梯价商品,非运费商品,非赠品 才可以写入复购价
|
|
|
+ boolean purchaseFlag = ((!secondFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
|
|
|
+ boolean historyFlag = false;
|
|
|
+ // 不是二手订单才可以写入价格库
|
|
|
+ if (purchaseFlag) {
|
|
|
+ Date date = new Date();
|
|
|
+ String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
|
|
|
+ // 机构价大于成本价 ---成本价已经在整理订单商品时计算好(固定或比例)
|
|
|
+ boolean costFlag = MathUtil.compare(orderProduct.getPrice(), orderProduct.getCostPrice()) > 0;
|
|
|
+ // 查询当前商品复购价信息
|
|
|
+ PurchasePricePo purchase = baseMapper.getPurchasePricePo(order.getUserId(), orderProduct.getProductId());
|
|
|
+ // 已有复购价
|
|
|
+ if (null != purchase) {
|
|
|
+ // 复购价大于机构价(降价)
|
|
|
+ boolean priceFlag1 = MathUtil.compare(purchase.getCurrentPrice(), orderProduct.getPrice()) > 0;
|
|
|
+ // 成本价大于复购价(亏本)
|
|
|
+ boolean priceFlag2 = MathUtil.compare(orderProduct.getCostPrice(), purchase.getCurrentPrice()) > 0;
|
|
|
+ if (priceFlag2 || (priceFlag1 && costFlag)) {
|
|
|
+ // 更新价格库复购价
|
|
|
+ purchase.setCurrentPrice(orderProduct.getPrice());
|
|
|
+ purchase.setTaxRate(orderProduct.getTaxRate());
|
|
|
+ purchase.setUpdateTime(curDateStr);
|
|
|
+ // 更新复购价格库
|
|
|
+ baseMapper.updatePurchasePrice(purchase);
|
|
|
+ historyFlag = true;
|
|
|
+ log.info(note + ">>>>>>>>>>>更新复购价格库(update[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + order.getOrderId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 没有复购价
|
|
|
+ if (costFlag) {
|
|
|
+ // 新增复购价到价格库
|
|
|
+ purchase = new PurchasePricePo();
|
|
|
+ purchase.setUserId(order.getUserId());
|
|
|
+ purchase.setClubId(order.getClubId());
|
|
|
+ purchase.setOrderId(order.getOrderId());
|
|
|
+ purchase.setProductId(orderProduct.getProductId());
|
|
|
+ purchase.setShopId(orderProduct.getShopId());
|
|
|
+ purchase.setShopName(orderProduct.getShopName());
|
|
|
+ purchase.setCurrentPrice(orderProduct.getPrice());
|
|
|
+ purchase.setTaxRate(orderProduct.getTaxRate());
|
|
|
+ purchase.setCreateTime(curDateStr);
|
|
|
+ purchase.setUpdateTime(curDateStr);
|
|
|
+ purchase.setDelFlag(0);
|
|
|
+ // 新增复购价格库
|
|
|
+ baseMapper.insertPurchasePrice(purchase);
|
|
|
+ historyFlag = true;
|
|
|
+ log.info(note + ">>>>>>>>>>>新增复购价格库(insert[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + order.getOrderId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (historyFlag) {
|
|
|
+ // 历史复购价记录
|
|
|
+ PurchaseHistoryPo purchaseHistory = new PurchaseHistoryPo();
|
|
|
+ purchaseHistory.setUserId(order.getUserId());
|
|
|
+ purchaseHistory.setClubId(order.getClubId());
|
|
|
+ purchaseHistory.setOrderId(order.getOrderId());
|
|
|
+ purchaseHistory.setProductId(orderProduct.getProductId());
|
|
|
+ purchaseHistory.setCurrentCostPrice(orderProduct.getCostPrice());
|
|
|
+ purchaseHistory.setPrice(orderProduct.getPrice());
|
|
|
+ purchaseHistory.setCreateTime(curDateStr);
|
|
|
+ purchaseHistory.setDelFlag(0);
|
|
|
+ baseMapper.insertPurchaseHistory(purchaseHistory);
|
|
|
+ log.info(note + ">>>>>>>>>>>新增历史复购价记录(insert[repeat_purchase_price_history])ProductId:" + orderProduct.getProductId() + ",orderId:" + order.getOrderId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存余额抵扣到收款记录
|
|
|
+ * @param balancePayFee 余额抵扣
|
|
|
+ * @param orderId 主订单Id
|
|
|
+ * @param note 日志备注
|
|
|
+ */
|
|
|
+ public void saveDiscernReceipt(Double balancePayFee, Integer orderId, String note) {
|
|
|
+ Date date = new Date();
|
|
|
+ String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
|
|
|
+ // 识别款项表
|
|
|
+ DiscernReceiptPo discernReceipt = new DiscernReceiptPo();
|
|
|
+ discernReceipt.setPayWay(3);
|
|
|
+ discernReceipt.setPayType(16);
|
|
|
+ discernReceipt.setReceiptType(1);
|
|
|
+ discernReceipt.setReceiptStatus(3);
|
|
|
+ discernReceipt.setReceiptAmount(balancePayFee);
|
|
|
+ discernReceipt.setConfirmType(4);
|
|
|
+ discernReceipt.setReceiptDate(curDateStr);
|
|
|
+ discernReceipt.setConfirmDate(curDateStr);
|
|
|
+ discernReceipt.setReviewDate(curDateStr);
|
|
|
+ discernReceipt.setUpdateDate(curDateStr);
|
|
|
+ discernReceipt.setDelFlag(0);
|
|
|
+ // 保存 收款记录
|
|
|
+ baseMapper.insertDiscernReceipt(discernReceipt);
|
|
|
+ log.info(note + ">>>>>>>>>>>保存识别款项(insert[cm_discern_receipt])id:" + discernReceipt.getId() + ",orderId:" + orderId);
|
|
|
+ // 收款项和订单关系表
|
|
|
+ OrderReceiptRelationPo relation = new OrderReceiptRelationPo();
|
|
|
+ relation.setReceiptId(discernReceipt.getId());
|
|
|
+ relation.setOrderId(orderId);
|
|
|
+ relation.setAssociateAmount(balancePayFee);
|
|
|
+ relation.setRelationType(2);
|
|
|
+ relation.setDelFlag(0);
|
|
|
+ // 保存 收款项和订单关系
|
|
|
+ baseMapper.insertOrderReceiptRelation(relation);
|
|
|
+ log.info(note + ">>>>>>>>>>>收款项和订单关系(insert[cm_receipt_order_relation])id:" + relation.getId() + ",orderId:" + orderId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|