|
@@ -482,6 +482,11 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
List<String> productIdList = new ArrayList<>();
|
|
|
List<String> skuIdList = new ArrayList<>();
|
|
|
|
|
|
+ // 余额抵扣金额
|
|
|
+ AtomicReference<Double> balance = new AtomicReference(0);
|
|
|
+ if (1 == orderParamBo.getBalancePayFlag()) {
|
|
|
+ balance.set(orderParamBo.getAbleUserMoney());
|
|
|
+ }
|
|
|
// 子订单订单列表
|
|
|
List<OrderShopPo> shopOrderList = new ArrayList<>();
|
|
|
JSONArray orderInfo = orderParamBo.getOrderInfo();
|
|
@@ -602,10 +607,8 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
secondHandOrderFlag = true;
|
|
|
}
|
|
|
// 是否添加税费,不含税商品 开票需添加税费
|
|
|
- boolean taxFlag = false;
|
|
|
- if (0 == organizeId) {
|
|
|
- taxFlag = (Integer.valueOf(0).equals(product.getIncludedTax()) && (Integer.valueOf(1).equals(product.getInvoiceType()) || Integer.valueOf(2).equals(product.getInvoiceType())));
|
|
|
- }
|
|
|
+ boolean taxFlag = (Integer.valueOf(0).equals(product.getIncludedTax()) && (Integer.valueOf(1).equals(product.getInvoiceType()) || Integer.valueOf(2).equals(product.getInvoiceType())));
|
|
|
+
|
|
|
Double shopTax = 0d;
|
|
|
// 图片路径
|
|
|
String image = ImageUtil.getImageUrl("product", product.getImage(), domain);
|
|
@@ -715,14 +718,15 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
product.setLadderPrices(ladderPrices);
|
|
|
product.setActProduct(2);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ /*else {
|
|
|
// 复购价
|
|
|
Double repurchase = baseMapper.getRepurchasePrice(skuId, orderParamBo.getUserId());
|
|
|
if (null != repurchase && repurchase > 0) {
|
|
|
discountPrice = repurchase;
|
|
|
}
|
|
|
product.setActProduct(0);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
if (MathUtil.compare(discountPrice, BigDecimal.ZERO) == 0) {
|
|
|
return ResponseJson.error("商品购买价格不能为0!", null);
|
|
@@ -738,12 +742,23 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 不含税不可开票商品和未知商品,税率置为0
|
|
|
product.setTaxRate(0d);
|
|
|
}
|
|
|
+ log.info("productTax==="+productTax);
|
|
|
// 商品价格
|
|
|
- product.setPrice(productPrice);
|
|
|
+ if (Integer.valueOf(0).equals(product.getIncludedTax())) {
|
|
|
+ if (null != product.getTaxRate() && product.getTaxRate() > 0d) {
|
|
|
+ product.setPrice(MathUtil.add(productPrice, MathUtil.mul(productPrice, MathUtil.div(product.getTaxRate(), 100, 2))).doubleValue());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ product.setPrice(productPrice);
|
|
|
+ }
|
|
|
// 商品税后价格
|
|
|
Double productTaxPrice = MathUtil.add(productPrice, productTax).doubleValue();
|
|
|
+ log.info("productTaxPrice==="+productTaxPrice);
|
|
|
// 折后税后单价
|
|
|
+ log.info("discountPrice==="+discountPrice);
|
|
|
+ log.info("discountTax==="+discountTax);
|
|
|
Double discountTaxPrice = MathUtil.add(discountPrice, discountTax).doubleValue();
|
|
|
+ log.info("discountTaxPrice===="+discountTaxPrice);
|
|
|
// 折扣率 = 折后单价/机构价
|
|
|
Double discountRate = MathUtil.mul(MathUtil.div(discountTaxPrice, productTaxPrice), 100).doubleValue();
|
|
|
// 单个商品的金额
|
|
@@ -811,7 +826,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
}
|
|
|
// 折后单价
|
|
|
- product.setDiscountPrice(discountPrice);
|
|
|
+ product.setDiscountPrice(discountTaxPrice);
|
|
|
// 折扣率 = 折后单价/机构价
|
|
|
product.setDiscount(discountRate);
|
|
|
if (svipPriceFlag || (null != promotions && promotions.getType() == 1 && promotions.getMode() == 1)) {
|
|
@@ -835,22 +850,28 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
// 成本价
|
|
|
Double costPrice = null;
|
|
|
- // 判断是否选中固定成本价
|
|
|
+
|
|
|
+ log.info("product.getDiscountPrice()===="+product.getDiscountPrice());
|
|
|
+ /**
|
|
|
+ * 判断是否选中固定成本价
|
|
|
+ * 版本不在使用税费,成本取消再加 机构税费
|
|
|
+ */
|
|
|
if (null != product.getCostPrice() && 1 == product.getCostCheckFlag() && product.getCostPrice() >= 0d) {
|
|
|
costPrice = product.getCostPrice();
|
|
|
}
|
|
|
// 判断是否选中比例成本价
|
|
|
if (null != product.getCostProportional() && 2 == product.getCostCheckFlag() && product.getCostProportional() > 0d) {
|
|
|
// 通过售价*比例得到成本价
|
|
|
- double discountTax = 0d;
|
|
|
+ /*double discountTax = 0d;
|
|
|
if (taxFlag) {
|
|
|
discountTax = MathUtil.div(MathUtil.mul(product.getDiscountPrice(), product.getTaxRate()), 100, 2).doubleValue();
|
|
|
- }
|
|
|
- costPrice = MathUtil.div(MathUtil.mul(MathUtil.add(product.getDiscountPrice(), discountTax), product.getCostProportional()), 100, 2).doubleValue();
|
|
|
+ }*/
|
|
|
+ costPrice = MathUtil.div(MathUtil.mul(product.getDiscountPrice(), product.getCostProportional()), 100, 2).doubleValue();
|
|
|
}
|
|
|
if (null == costPrice) {
|
|
|
return ResponseJson.error("订单商品成本异常!", null);
|
|
|
}
|
|
|
+ log.info("costPrice===="+costPrice);
|
|
|
product.setCostPrice(costPrice);
|
|
|
// 付供应商税费
|
|
|
if (null == product.getShopTaxRate() || product.getShopTaxRate() <= 0) {
|
|
@@ -867,12 +888,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 单个商品付供应商总税费
|
|
|
product.setShouldPayTotalTax(MathUtil.mul(shopTax, productNum).doubleValue());
|
|
|
// 付供应商 商品费=成本价*(购买数量 + 赠品数量)
|
|
|
- Double costAmount = null;
|
|
|
- if (0 == organizeId) {
|
|
|
- costAmount = MathUtil.mul(costPrice, MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
- } else {
|
|
|
- costAmount = MathUtil.mul(product.getPrice(), MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
- }
|
|
|
+ Double costAmount = MathUtil.mul(costPrice, MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
product.setShopProductAmount(costAmount);
|
|
|
log.info("product.getShopProductAmount()***" + product.getShopProductAmount());
|
|
|
//应付供应商(单)=成本价+供应商税费(单)
|
|
@@ -932,6 +948,8 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
product.setShopPercent(organizeSkuInfo.getShopPercent());
|
|
|
}
|
|
|
// 加入订单商品列表
|
|
|
+ // 商品价格设置为 折后价格
|
|
|
+ product.setPrice(product.getDiscountPrice());
|
|
|
orderProductList.add(product);
|
|
|
productIdList.add(product.getProductId().toString());
|
|
|
skuIdList.add(product.getSkuId().toString());
|
|
@@ -945,9 +963,9 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
needPayAmount.set(MathUtil.add(needPayAmount.get(), postage).doubleValue());
|
|
|
log.info("postage=-***====" + postage);
|
|
|
isColdChina.set(MathUtil.add(isColdChina.get(), shopIsColdChina.get()).doubleValue());
|
|
|
- log.info("isColdChina.get()=------=-=-====" + isColdChina.get());
|
|
|
+ log.info("shopIsColdChina.get()=------=-=-====" + shopIsColdChina.get());
|
|
|
// 需要支付金额 shouldPayFee + 冷链费
|
|
|
- needPayAmount.set(MathUtil.add(needPayAmount.get(), isColdChina.get()).doubleValue());
|
|
|
+ needPayAmount.set(MathUtil.add(needPayAmount.get(), shopIsColdChina.get()).doubleValue());
|
|
|
// 统计总运费
|
|
|
postageFee.set(MathUtil.add(postageFee.get(), postage).doubleValue());
|
|
|
log.info("统计总运费+--+-+-" + postageFee.get());
|
|
@@ -1010,7 +1028,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 超级会员优惠金额
|
|
|
shopOrder.setSvipShopReduction(svipShopReduction.get());
|
|
|
// 总价(含税) = totalFee + 冷链费
|
|
|
- shopOrder.setTotalAmount(MathUtil.add(MathUtil.add(shopProductFee.get(), postage).doubleValue(), isColdChina.get()).doubleValue());
|
|
|
+ shopOrder.setTotalAmount(MathUtil.add(MathUtil.add(shopProductFee.get(), postage).doubleValue(), shopIsColdChina.get()).doubleValue());
|
|
|
// 总金额 = 订单商品totalAmount
|
|
|
shopOrder.setProductAmount(shopAmount.get());
|
|
|
// 需要支付金额 shouldPayFee +运费
|
|
@@ -1021,8 +1039,9 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
shopOrder.setShopProductAmount(shopProductAmount.get());
|
|
|
// 付给供应商税费
|
|
|
shopOrder.setShopTaxFee(shopTaxFee.get());
|
|
|
- // 付供应商 = 商品费 + 运费 + 税费 + 冷链费
|
|
|
- shopOrder.setShouldPayShopAmount(MathUtil.add(MathUtil.add(shopProductAmount.get(), shopTaxFee.get()).doubleValue(), isColdChina.get()).doubleValue());
|
|
|
+ // 付供应商 = 商品费 + 运费 + 冷链费
|
|
|
+ // 版本不加 税费
|
|
|
+ shopOrder.setShouldPayShopAmount(MathUtil.add(MathUtil.add(shopProductAmount.get(), postageFee.get()).doubleValue(), shopIsColdChina.get()).doubleValue());
|
|
|
// 付给供应商运费
|
|
|
// shopOrder.setShopPostFee(0d);
|
|
|
// 已付供应商金额
|
|
@@ -1036,6 +1055,27 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 普通订单
|
|
|
shopOrder.setOrderType(1);
|
|
|
}
|
|
|
+ // 余额支付标识,0不使用,1使用
|
|
|
+ log.info("balance.get()====="+balance.get());
|
|
|
+ if (1 == orderParamBo.getBalancePayFlag() && 3 == orderParamBo.getCartType() && balance.get() > 0) {
|
|
|
+ // 使用余额支付
|
|
|
+ shopOrder.setUseBalanceFlag(1);
|
|
|
+ // 部分抵扣
|
|
|
+ if (MathUtil.compare(shopOrder.getNeedPayAmount(), balance.get()) > 0) {
|
|
|
+ // 余额抵扣金额
|
|
|
+ shopOrder.setAccountAmount(balance.get());
|
|
|
+ } else {
|
|
|
+ // 余额抵扣金额
|
|
|
+ shopOrder.setAccountAmount(shopOrder.getNeedPayAmount());
|
|
|
+ }
|
|
|
+ balance.updateAndGet( b -> balance.get() - shopOrder.getNeedPayAmount());
|
|
|
+ } else {
|
|
|
+ // 使用余额支付
|
|
|
+ shopOrder.setUseBalanceFlag(0);
|
|
|
+ // 余额抵扣金额
|
|
|
+ shopOrder.setAccountAmount(0d);
|
|
|
+ }
|
|
|
+ log.info("shopOrder.getAccountAmount()===="+shopOrder.getAccountAmount());
|
|
|
// 运费标记
|
|
|
shopOrder.setShopPostFlag(postageFlag);
|
|
|
// 添加到子订单列表
|
|
@@ -1237,7 +1277,6 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
|
|
|
log.info("订单总额" + payTotalFee.get());
|
|
|
// 判断前端传入orderShouldPayFee订单应付金额,和后台计算应付金额对比
|
|
|
- // orderParamBo.setOrderShouldPayFee(MathUtil.sub(orderParamBo.getOrderShouldPayFee(), isColdChina.get()).doubleValue());
|
|
|
log.info("【提交订单】>>>>>后台计算payableAmount:" + payableAmount.get() + " ,前端传入orderShouldPayFee:" + orderParamBo.getOrderShouldPayFee());
|
|
|
// compare return[-1:v1<v2, 0:v1=v2, 1:v1>v2]
|
|
|
int compare = MathUtil.compare(orderParamBo.getOrderShouldPayFee(), payableAmount.get());
|
|
@@ -1246,8 +1285,6 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return ResponseJson.error("订单付款金额不正确!", null);
|
|
|
}
|
|
|
- // 加冷链费
|
|
|
- // orderParamBo.setOrderShouldPayFee(MathUtil.add(orderParamBo.getOrderShouldPayFee(), isColdChina.get()).doubleValue());
|
|
|
// 售后条款
|
|
|
Integer clauseId = orderParamBo.getClauseId();
|
|
|
String clauseName = null;
|
|
@@ -1402,7 +1439,6 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
*/
|
|
|
AtomicReference<String> shopOrderIds = new AtomicReference<>();
|
|
|
AtomicInteger shopOrderIndex = new AtomicInteger(1);
|
|
|
- log.info("shopOrderList===****=====" + shopOrderList);
|
|
|
shopOrderList.forEach(shopOrder -> {
|
|
|
shopOrder.setOrderId(mainOrder.getOrderId());
|
|
|
shopOrder.setOrderNo(mainOrder.getOrderNo());
|
|
@@ -1447,7 +1483,6 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
if (!shopFlag) {
|
|
|
shopOrder.setShopPostFee(0d);
|
|
|
}*/
|
|
|
- log.info("shopOrder.getIsColdChina()******" + shopOrder.getIsColdChina() + "=====shopOrder.getShopPostFee()" + shopOrder.getShopPostFee());
|
|
|
/*
|
|
|
* 保存子订单
|
|
|
*/
|
|
@@ -2050,8 +2085,9 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
shopOrder.setShopProductAmount(shopProductAmount.get());
|
|
|
// 付给供应商税费
|
|
|
shopOrder.setShopTaxFee(shopTaxFee.get());
|
|
|
- // 付供应商 = 商品费 + 运费 + 税费
|
|
|
- shopOrder.setShouldPayShopAmount(MathUtil.add(MathUtil.add(shopProductAmount.get(), shopTaxFee.get()).doubleValue(), isColdChina.get()).doubleValue());
|
|
|
+ // 付供应商 = 商品费 + 运费 + 冷链费
|
|
|
+ // 暂时不加 税费
|
|
|
+ shopOrder.setShouldPayShopAmount(MathUtil.add(MathUtil.add(shopProductAmount.get(), oldShop.get(0).getShopPostFee()).doubleValue(), isColdChina.get()).doubleValue());
|
|
|
// 付给供应商运费
|
|
|
shopOrder.setShopPostFee(oldShop.get(0).getShopPostFee());
|
|
|
// 运费类型
|
|
@@ -2067,6 +2103,10 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 普通订单
|
|
|
shopOrder.setOrderType(1);
|
|
|
}
|
|
|
+ // 余额抵扣金额
|
|
|
+ shopOrder.setAccountAmount(oldShop.get(0).getAccountAmount());
|
|
|
+ // 是否使用余额抵扣
|
|
|
+ shopOrder.setUseBalanceFlag(oldShop.get(0).getUseBalanceFlag());
|
|
|
orderShopPos.add(shopOrder);
|
|
|
}
|
|
|
return orderShopPos;
|