|
@@ -975,16 +975,66 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
*/
|
|
|
if (3 != orderParamBo.getCartType()) {
|
|
|
// 非二手订单, 非活动商品,非阶梯价商品,非运费商品,非赠品 才可以写入复购价
|
|
|
- boolean flag = ((!secondHandOrderFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
|
|
|
+ boolean purchaseFlag = ((!secondHandOrderFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
|
|
|
+ boolean historyFlag = false;
|
|
|
// 不是二手订单才可以写入价格库
|
|
|
- if (flag) {
|
|
|
- // 查询当前商品复购价
|
|
|
- //PurchasePricePo purchase = submitMapper.getPurchasePricePo(orderParamBo.getUserId(), orderProduct.getProductId());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ if (purchaseFlag) {
|
|
|
+ // 机构价大于成本价 ---成本价已经在整理订单商品时计算好(固定或比例)
|
|
|
+ boolean costFlag = MathUtil.compare(orderProduct.getPrice(), orderProduct.getCostPrice()) > 0;
|
|
|
+ // 查询当前商品复购价信息
|
|
|
+ PurchasePricePo purchase = submitMapper.getPurchasePricePo(mainOrder.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(mainOrder.getOrderTime());
|
|
|
+ // 更新复购价格库
|
|
|
+ submitMapper.updatePurchasePrice(purchase);
|
|
|
+ historyFlag = true;
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>更新复购价格库(update[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + mainOrder.getOrderId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 没有复购价
|
|
|
+ if (costFlag) {
|
|
|
+ // 新增复购价到价格库
|
|
|
+ purchase = new PurchasePricePo();
|
|
|
+ purchase.setUserId(mainOrder.getUserId());
|
|
|
+ purchase.setClubId(mainOrder.getClubId());
|
|
|
+ purchase.setOrderId(mainOrder.getOrderId());
|
|
|
+ purchase.setProductId(orderProduct.getProductId());
|
|
|
+ purchase.setShopId(orderProduct.getShopId());
|
|
|
+ purchase.setShopName(orderProduct.getShopName());
|
|
|
+ purchase.setCurrentPrice(orderProduct.getPrice());
|
|
|
+ purchase.setTaxRate(orderProduct.getTaxRate());
|
|
|
+ purchase.setCreateTime(mainOrder.getOrderTime());
|
|
|
+ purchase.setUpdateTime(mainOrder.getOrderTime());
|
|
|
+ purchase.setDelFlag(0);
|
|
|
+ // 新增复购价格库
|
|
|
+ submitMapper.insertPurchasePrice(purchase);
|
|
|
+ historyFlag = true;
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增复购价格库(insert[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + mainOrder.getOrderId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (historyFlag) {
|
|
|
+ // 历史复购价记录
|
|
|
+ PurchaseHistoryPo purchaseHistory = new PurchaseHistoryPo();
|
|
|
+ purchaseHistory.setUserId(mainOrder.getUserId());
|
|
|
+ purchaseHistory.setClubId(mainOrder.getClubId());
|
|
|
+ purchaseHistory.setOrderId(mainOrder.getOrderId());
|
|
|
+ purchaseHistory.setProductId(orderProduct.getProductId());
|
|
|
+ purchaseHistory.setCurrentCostPrice(orderProduct.getCostPrice());
|
|
|
+ purchaseHistory.setPrice(orderProduct.getPrice());
|
|
|
+ purchaseHistory.setCreateTime(mainOrder.getOrderTime());
|
|
|
+ purchaseHistory.setDelFlag(0);
|
|
|
+ submitMapper.insertPurchaseHistory(purchaseHistory);
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增历史复购价记录(insert[repeat_purchase_price_history])ProductId:" + orderProduct.getProductId() + ",orderId:" + mainOrder.getOrderId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|