|
@@ -68,8 +68,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
@Resource
|
|
|
private RemoteCallService remoteCallService;
|
|
|
@Resource
|
|
|
- private PayOrderMapper payOrderMapper;
|
|
|
-
|
|
|
+ private ShipMapper shipMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -129,7 +128,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public ResponseJson<Map<String, Object>> generateOrder(SubmitDto submitDto) {
|
|
|
- log.info("submitDto==="+submitDto);
|
|
|
+ log.info("submitDto===" + submitDto);
|
|
|
// 获取机构用户Id
|
|
|
Integer clubUserId = baseMapper.getUserIdByClubId(submitDto.getClubId());
|
|
|
if (null == clubUserId || clubUserId == 0) {
|
|
@@ -259,54 +258,54 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
} else {
|
|
|
// 联合丽格*/
|
|
|
- if (1 == invoiceType || 2 == invoiceType) {
|
|
|
- InvoicePo invoice = new InvoicePo();
|
|
|
- String invoiceTitle = (String) orderInvoice.get("invoiceTitle");
|
|
|
- if (StringUtils.isEmpty(invoiceTitle)) {
|
|
|
- return ResponseJson.error("发票抬头信息不正确!", null);
|
|
|
- }
|
|
|
- invoice.setType(invoiceType);
|
|
|
- invoice.setInvoiceTitle(invoiceTitle);
|
|
|
- String corporationTaxNum = (String) orderInvoice.get("corporationTaxNum");
|
|
|
- if (1 == invoiceType) {
|
|
|
- // 普通发票:发票类型、发票内容(商品明细)、抬头(公司名称)、纳税人识别号[普通发票的公司]
|
|
|
- Integer invoiceTitleType = (Integer) orderInvoice.get("invoiceTitleType");
|
|
|
- String registeredAddress = (String) orderInvoice.get("registeredAddress");
|
|
|
- String registeredPhone = (String) orderInvoice.get("registeredPhone");
|
|
|
- String openBank = (String) orderInvoice.get("openBank");
|
|
|
- String bankAccountNo = (String) orderInvoice.get("bankAccountNo");
|
|
|
- // 抬头类型
|
|
|
- Integer headingType = (Integer) orderInvoice.get("headingType");
|
|
|
- if (0 != headingType) {
|
|
|
- if (StringUtils.isEmpty(corporationTaxNum)) {
|
|
|
- return ResponseJson.error("纳税人识别号信息不正确!", null);
|
|
|
- }
|
|
|
+ if (1 == invoiceType || 2 == invoiceType) {
|
|
|
+ InvoicePo invoice = new InvoicePo();
|
|
|
+ String invoiceTitle = (String) orderInvoice.get("invoiceTitle");
|
|
|
+ if (StringUtils.isEmpty(invoiceTitle)) {
|
|
|
+ return ResponseJson.error("发票抬头信息不正确!", null);
|
|
|
+ }
|
|
|
+ invoice.setType(invoiceType);
|
|
|
+ invoice.setInvoiceTitle(invoiceTitle);
|
|
|
+ String corporationTaxNum = (String) orderInvoice.get("corporationTaxNum");
|
|
|
+ if (1 == invoiceType) {
|
|
|
+ // 普通发票:发票类型、发票内容(商品明细)、抬头(公司名称)、纳税人识别号[普通发票的公司]
|
|
|
+ Integer invoiceTitleType = (Integer) orderInvoice.get("invoiceTitleType");
|
|
|
+ String registeredAddress = (String) orderInvoice.get("registeredAddress");
|
|
|
+ String registeredPhone = (String) orderInvoice.get("registeredPhone");
|
|
|
+ String openBank = (String) orderInvoice.get("openBank");
|
|
|
+ String bankAccountNo = (String) orderInvoice.get("bankAccountNo");
|
|
|
+ // 抬头类型
|
|
|
+ Integer headingType = (Integer) orderInvoice.get("headingType");
|
|
|
+ if (0 != headingType) {
|
|
|
+ if (StringUtils.isEmpty(corporationTaxNum)) {
|
|
|
+ return ResponseJson.error("纳税人识别号信息不正确!", null);
|
|
|
}
|
|
|
- invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
- invoice.setHeadingType(headingType);
|
|
|
- invoice.setInvoiceTitleType(invoiceTitleType);
|
|
|
- invoice.setRegisteredAddress(registeredAddress);
|
|
|
- invoice.setRegisteredPhone(registeredPhone);
|
|
|
- invoice.setOpenBank(openBank);
|
|
|
- invoice.setBankAccountNo(bankAccountNo);
|
|
|
}
|
|
|
- if (2 == invoiceType) {
|
|
|
- // 增值税发票:发票类型、发票、抬头(公司名称)、纳税人识别号、注册地址、注册电话、开户银行、开户银行账户
|
|
|
- String registeredAddress = (String) orderInvoice.get("registeredAddress");
|
|
|
- String registeredPhone = (String) orderInvoice.get("registeredPhone");
|
|
|
- String openBank = (String) orderInvoice.get("openBank");
|
|
|
- String bankAccountNo = (String) orderInvoice.get("bankAccountNo");
|
|
|
- if (StringUtils.isEmpty(registeredAddress) || StringUtils.isEmpty(registeredPhone) || StringUtils.isEmpty(openBank) || StringUtils.isEmpty(bankAccountNo)) {
|
|
|
- return ResponseJson.error("发票信息不完整!", null);
|
|
|
- }
|
|
|
- invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
- invoice.setRegisteredAddress(registeredAddress);
|
|
|
- invoice.setRegisteredPhone(registeredPhone);
|
|
|
- invoice.setOpenBank(openBank);
|
|
|
- invoice.setBankAccountNo(bankAccountNo);
|
|
|
+ invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
+ invoice.setHeadingType(headingType);
|
|
|
+ invoice.setInvoiceTitleType(invoiceTitleType);
|
|
|
+ invoice.setRegisteredAddress(registeredAddress);
|
|
|
+ invoice.setRegisteredPhone(registeredPhone);
|
|
|
+ invoice.setOpenBank(openBank);
|
|
|
+ invoice.setBankAccountNo(bankAccountNo);
|
|
|
+ }
|
|
|
+ if (2 == invoiceType) {
|
|
|
+ // 增值税发票:发票类型、发票、抬头(公司名称)、纳税人识别号、注册地址、注册电话、开户银行、开户银行账户
|
|
|
+ String registeredAddress = (String) orderInvoice.get("registeredAddress");
|
|
|
+ String registeredPhone = (String) orderInvoice.get("registeredPhone");
|
|
|
+ String openBank = (String) orderInvoice.get("openBank");
|
|
|
+ String bankAccountNo = (String) orderInvoice.get("bankAccountNo");
|
|
|
+ if (StringUtils.isEmpty(registeredAddress) || StringUtils.isEmpty(registeredPhone) || StringUtils.isEmpty(openBank) || StringUtils.isEmpty(bankAccountNo)) {
|
|
|
+ return ResponseJson.error("发票信息不完整!", null);
|
|
|
}
|
|
|
- orderParamBo.setOrderInvoice(invoice);
|
|
|
+ invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
+ invoice.setRegisteredAddress(registeredAddress);
|
|
|
+ invoice.setRegisteredPhone(registeredPhone);
|
|
|
+ invoice.setOpenBank(openBank);
|
|
|
+ invoice.setBankAccountNo(bankAccountNo);
|
|
|
}
|
|
|
+ orderParamBo.setOrderInvoice(invoice);
|
|
|
+ }
|
|
|
// 返佣订单标识 0非返佣订单,1返佣订单,2普通订单含有返佣服务费
|
|
|
Integer rebateFlag = (Integer) payInfo.get("rebateFlag");
|
|
|
// rebateflag=2时,有rebateFee
|
|
@@ -503,7 +502,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
if (1252 == shopId) {
|
|
|
secondHandOrderFlag = true;
|
|
|
}
|
|
|
- log.info("postageFlag*****************"+postageFlag);
|
|
|
+ log.info("postageFlag*****************" + postageFlag);
|
|
|
// 运费
|
|
|
Double postage = Double.parseDouble(postageString);
|
|
|
// 供应商名称
|
|
@@ -871,7 +870,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
costAmount = MathUtil.mul(product.getPrice(), MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
}
|
|
|
product.setShopProductAmount(costAmount);
|
|
|
- log.info("product.getShopProductAmount()***"+product.getShopProductAmount());
|
|
|
+ log.info("product.getShopProductAmount()***" + product.getShopProductAmount());
|
|
|
//应付供应商(单)=成本价+供应商税费(单)
|
|
|
Double singleShopFee = MathUtil.add(product.getCostPrice(), shopTax).doubleValue();
|
|
|
product.setSingleShopFee(singleShopFee);
|
|
@@ -914,8 +913,8 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 商品总金额
|
|
|
shopAmount.set(MathUtil.add(shopAmount.get(), product.getTotalAmount()).doubleValue());
|
|
|
// 付供应商 商品费
|
|
|
- log.info("shopProductAmount.get()"+shopProductAmount.get());
|
|
|
- log.info("product.getShopProductAmount()"+product.getShopProductAmount());
|
|
|
+ log.info("shopProductAmount.get()" + shopProductAmount.get());
|
|
|
+ log.info("product.getShopProductAmount()" + product.getShopProductAmount());
|
|
|
shopProductAmount.set(MathUtil.add(shopProductAmount.get(), product.getShopProductAmount()).doubleValue());
|
|
|
// 付供应商税费
|
|
|
shopTaxFee.set(MathUtil.add(shopTaxFee.get(), product.getShouldPayTotalTax()).doubleValue());
|
|
@@ -932,18 +931,18 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
skuIdList.add(product.getSkuId().toString());
|
|
|
}
|
|
|
// 设置运费
|
|
|
- if (( 1 == postageFlag && 0 == mainOrder.getUserBeans() ) || ( 0 == postageFlag && isColdChina.get() > 0.00d && 0 != organizeId ) || ( -1 == postageFlag && isColdChina.get() > 0.00d && 0 != organizeId )) {
|
|
|
+ if ((1 == postageFlag && 0 == mainOrder.getUserBeans()) || (0 == postageFlag && isColdChina.get() > 0.00d && 0 != organizeId) || (-1 == postageFlag && isColdChina.get() > 0.00d && 0 != organizeId)) {
|
|
|
// postage = MathUtil.add(shopIsColdChina.get(), postage).doubleValue();
|
|
|
shopOrder.setShopPostFee(postage);
|
|
|
}
|
|
|
// 需要支付金额 shouldPayFee +运费
|
|
|
// needPayAmount.set(MathUtil.add(needPayAmount.get(), postage).doubleValue());
|
|
|
- log.info("postage=-***===="+postage);
|
|
|
+ log.info("postage=-***====" + postage);
|
|
|
isColdChina.set(MathUtil.add(isColdChina.get(), shopIsColdChina.get()).doubleValue());
|
|
|
- log.info("isColdChina.get()=------=-=-===="+isColdChina.get());
|
|
|
+ log.info("isColdChina.get()=------=-=-====" + isColdChina.get());
|
|
|
// 统计总运费
|
|
|
postageFee.set(MathUtil.add(postageFee.get(), postage).doubleValue());
|
|
|
- log.info("统计总运费+--+-+-"+postageFee.get());
|
|
|
+ log.info("统计总运费+--+-+-" + postageFee.get());
|
|
|
Integer count = submitMapper.findSplitResult(productIdList);
|
|
|
if (count > 0) {
|
|
|
//有商品无分帐号,走线下
|
|
@@ -1031,7 +1030,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
// 运费标记
|
|
|
shopOrder.setShopPostFlag(postageFlag);
|
|
|
- log.info("shopOrder.getShopPostFlag()*****************"+shopOrder.getShopPostFlag());
|
|
|
+ log.info("shopOrder.getShopPostFlag()*****************" + shopOrder.getShopPostFlag());
|
|
|
// 添加到子订单列表
|
|
|
shopOrderList.add(shopOrder);
|
|
|
// 统计商品总金额
|
|
@@ -1136,7 +1135,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 设置运费
|
|
|
// mainOrder.setPostage(orderParamBo.getPostage());
|
|
|
// 订单总额 = 商品费 + 运费
|
|
|
- log.info("总运费"+postageFee.get());
|
|
|
+ log.info("总运费" + postageFee.get());
|
|
|
payTotalFee.set(MathUtil.add(productTotalFee.get(), postageFee.get()).doubleValue());
|
|
|
// 运费标志:0包邮 -1到付 1遵循运费规则
|
|
|
// mainOrder.setPostageFlag(orderParamBo.getPostageFlag());
|
|
@@ -1224,7 +1223,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
mainOrder.setRebateFee(orderParamBo.getRebateFee());
|
|
|
}
|
|
|
|
|
|
- log.info("订单总额"+payTotalFee.get());
|
|
|
+ log.info("订单总额" + payTotalFee.get());
|
|
|
// 判断前端传入orderShouldPayFee订单应付金额,和后台计算应付金额对比
|
|
|
// orderParamBo.setOrderShouldPayFee(MathUtil.sub(orderParamBo.getOrderShouldPayFee(), isColdChina.get()).doubleValue());
|
|
|
log.info("【提交订单】>>>>>后台计算payableAmount:" + payableAmount.get() + " ,前端传入orderShouldPayFee:" + orderParamBo.getOrderShouldPayFee());
|
|
@@ -1438,7 +1437,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
if (!shopFlag) {
|
|
|
shopOrder.setShopPostFee(0d);
|
|
|
}*/
|
|
|
- log.info("shopOrder.getIsColdChina()******"+shopOrder.getIsColdChina()+"=====shopOrder.getShopPostFee()"+shopOrder.getShopPostFee());
|
|
|
+ log.info("shopOrder.getIsColdChina()******" + shopOrder.getIsColdChina() + "=====shopOrder.getShopPostFee()" + shopOrder.getShopPostFee());
|
|
|
/*
|
|
|
* 保存子订单
|
|
|
*/
|
|
@@ -1660,7 +1659,7 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
submitMapper.updateOnlinePayFlag(onlinePayFlag, mainOrder.getOrderId());
|
|
|
// 更新子订单线上支付
|
|
|
- if(0 != organizeId && item) {
|
|
|
+ if (0 != organizeId && item) {
|
|
|
String onlinePayWays = "1,2,3,4,5";
|
|
|
submitMapper.updateOnlinePayWays(onlinePayWays, mainOrder.getOrderId());
|
|
|
}
|
|
@@ -2253,4 +2252,493 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
return ResponseJson.success(info);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseJson updateOrder(List<OrderProductVo> orderProducts) {
|
|
|
+ /**
|
|
|
+ * 仅未付款可修改订单
|
|
|
+ * 当前版本仅修改订单商品价格
|
|
|
+ * 余额抵扣修改时,未确认修改抵扣记录抵扣金额,已确认则根据差价修改抵扣记录,并返还余额/或再抵扣
|
|
|
+ */
|
|
|
+ ShopOrderVo shopOrder = shipMapper.getShopOrder(orderProducts.get(0).getShopOrderId());
|
|
|
+
|
|
|
+ // 店铺促销活动状态
|
|
|
+ PromotionsVo shopPromotions = baseMapper.getPromotionByShopId(shopOrder.getShopId());
|
|
|
+ if (shopPromotions != null && shopPromotions.getSeen() != null && shopPromotions.getSeen() == 2) {
|
|
|
+ shopPromotions = null;
|
|
|
+ }
|
|
|
+ boolean svipUserFlag = null != baseMapper.getSvipUserIdByUserId(shopOrder.getUserId());
|
|
|
+ // 用户组织Id
|
|
|
+ Integer organizeId = baseMapper.getOrganizeId(orderProducts.get(0).getOrganizeId());
|
|
|
+ // 是否包含活动商品
|
|
|
+ boolean hasActProductFlag = false;
|
|
|
+ // 超级会员优惠
|
|
|
+ AtomicDouble svipFullReduction = new AtomicDouble(0);
|
|
|
+ // 促销满减优惠
|
|
|
+ AtomicDouble promotionFullReduction = new AtomicDouble(0);
|
|
|
+ //促销活动ids
|
|
|
+ List<Integer> promotionsIds = new ArrayList<>();
|
|
|
+ // 促销活动信息
|
|
|
+ List<PromotionsVo> promotionList = new ArrayList<>();
|
|
|
+ // 商品总数量
|
|
|
+ AtomicInteger shopProductCount = new AtomicInteger(0);
|
|
|
+ // 佣金 = 应付采美
|
|
|
+ AtomicDouble brokerage = new AtomicDouble(0);
|
|
|
+ // 需要支付金额
|
|
|
+ AtomicDouble needPayAmount = new AtomicDouble(0);
|
|
|
+ // 商品总金额
|
|
|
+ AtomicDouble shopAmount = new AtomicDouble(0);
|
|
|
+ // 付供应商 商品费
|
|
|
+ AtomicDouble shopProductAmount = new AtomicDouble(0);
|
|
|
+ // 付供应商税费
|
|
|
+ AtomicDouble shopTaxFee = new AtomicDouble(0);
|
|
|
+ // 商品费
|
|
|
+ AtomicDouble shopProductFee = new AtomicDouble(0);
|
|
|
+ // 供应商下参与店铺促销的商品总价
|
|
|
+ AtomicDouble shopPromotionFee = new AtomicDouble(0);
|
|
|
+ // 供应商超级会员优惠
|
|
|
+ AtomicDouble svipShopReduction = new AtomicDouble(0);
|
|
|
+ // 不包含店铺满减的子订单应付
|
|
|
+ AtomicDouble realNeedPay = new AtomicDouble(0);
|
|
|
+ // 订单商品列表
|
|
|
+ List<OrderProductPo> orderProductList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (OrderProductVo orderProduct : orderProducts) {
|
|
|
+ Integer skuId = orderProduct.getSkuId();
|
|
|
+ Integer productNum = orderProduct.getNum();
|
|
|
+ Integer presentNum = orderProduct.getPresentNum();
|
|
|
+ Integer productType = orderProduct.getProductType();
|
|
|
+ if (null == skuId) {
|
|
|
+ return ResponseJson.error("订单商品数据异常!", null);
|
|
|
+ }
|
|
|
+ if (null == productNum || productNum == 0) {
|
|
|
+ return ResponseJson.error("商品购买数量异常!", null);
|
|
|
+ }
|
|
|
+ // 获取数据库商品信息
|
|
|
+ OrderProductPo dbProduct = null;
|
|
|
+ if (0 == organizeId) {
|
|
|
+ dbProduct = submitMapper.getProductDetails(skuId);
|
|
|
+ } else {
|
|
|
+ dbProduct = submitMapper.getProductOrganizeDetails(skuId);
|
|
|
+ }
|
|
|
+ OrderProductPo product = new OrderProductPo();
|
|
|
+ BeanUtils.copyProperties(dbProduct, product);
|
|
|
+ product.setOrderProductId(orderProduct.getOrderProductId());
|
|
|
+ product.setPrice(orderProduct.getPrice());
|
|
|
+
|
|
|
+ if (null == product) {
|
|
|
+ return ResponseJson.error("订单商品不存在!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否添加税费,不含税商品 开票需添加税费
|
|
|
+ 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())));
|
|
|
+ }
|
|
|
+ Double shopTax = 0d;
|
|
|
+
|
|
|
+ // 超级会员优惠商品详情
|
|
|
+ SvipProductPo svipProductPo = submitMapper.getSvipProductDetails(product.getSkuId());
|
|
|
+ // 是否以超级会员优惠价格购买
|
|
|
+ boolean svipPriceFlag = null != svipProductPo && 1 == svipProductPo.getSvipProductFlag() && svipUserFlag;
|
|
|
+ // 是否是促销赠品
|
|
|
+ if (productType == 2) {
|
|
|
+ // 促销赠品数+1
|
|
|
+ product.setPrice(0d);
|
|
|
+ product.setDiscountPrice(0d);
|
|
|
+ product.setDiscount(0d);
|
|
|
+ product.setTotalAmount(0d);
|
|
|
+ product.setTotalFee(0d);
|
|
|
+ product.setTaxRate(0d);
|
|
|
+ product.setAddedValueTax(0d);
|
|
|
+ product.setTotalAddedValueTax(0d);
|
|
|
+ } else {
|
|
|
+ // 不是赠品,获取商品购买价格(超级会员优惠商品价格>>>活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
|
|
|
+ Double productPrice = product.getPrice();
|
|
|
+ Double discountPrice = product.getPrice();
|
|
|
+ // 商品税费
|
|
|
+ Double productTax = 0d;
|
|
|
+ Double discountTax = 0d;
|
|
|
+ // 商品是否处于活动状态
|
|
|
+ PromotionsVo promotions = null;
|
|
|
+ // 店铺促销优先
|
|
|
+ if (null == shopPromotions) {
|
|
|
+ promotions = baseMapper.getPromotionByProductId(product.getProductId());
|
|
|
+ if (null != promotions && 1 == promotions.getType() && 1 == promotions.getMode()) {
|
|
|
+ //单品促销的优惠价时,touchPrice取当前sku的
|
|
|
+ promotions.setTouchPrice(baseMapper.getTouchPriceBySku(skuId, promotions.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //促销活动如果协销不可见,置为空
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2) {
|
|
|
+ promotions = null;
|
|
|
+ }
|
|
|
+ // 计算单价
|
|
|
+ // 超级会员单价折扣计算
|
|
|
+ if (0 == organizeId) {
|
|
|
+ if (null != svipProductPo && 1 == svipProductPo.getSvipProductFlag()) {
|
|
|
+ // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
|
|
|
+ if (svipUserFlag) {
|
|
|
+ if (1 == svipProductPo.getSvipPriceType()) {
|
|
|
+ // 折扣价
|
|
|
+ discountPrice = MathUtil.div(MathUtil.mul(productPrice, svipProductPo.getSvipDiscount()), 100, 2).doubleValue();
|
|
|
+ } else if (2 == svipProductPo.getSvipPriceType()) {
|
|
|
+ // 直接优惠价
|
|
|
+ discountPrice = svipProductPo.getSvipDiscountPrice();
|
|
|
+ }
|
|
|
+ // 商品超级会员优惠
|
|
|
+ BigDecimal svipReduction = MathUtil.sub(productPrice, discountPrice);
|
|
|
+ if (taxFlag) {
|
|
|
+ // 商品税费超级会员优惠
|
|
|
+ BigDecimal svipTaxReduction = MathUtil.div(MathUtil.mul(svipReduction, product.getTaxRate()), 100, 2);
|
|
|
+ svipReduction = MathUtil.add(svipReduction, svipTaxReduction);
|
|
|
+ }
|
|
|
+ // 统计超级会员优惠
|
|
|
+ product.setSvipReduction(svipReduction.doubleValue());
|
|
|
+ svipShopReduction.set(MathUtil.add(svipShopReduction, MathUtil.mul(svipReduction, productNum)).doubleValue());
|
|
|
+ svipFullReduction.set(MathUtil.add(svipFullReduction, MathUtil.mul(svipReduction, productNum)).doubleValue());
|
|
|
+ // 保存订单商品svip数据
|
|
|
+ product.setSvipPriceFlag(1);
|
|
|
+ product.setSvipPriceType(svipProductPo.getSvipPriceType());
|
|
|
+ product.setSvipDiscount(1 == svipProductPo.getSvipPriceType() ? svipProductPo.getSvipDiscount() : 0.00d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 有单品优惠价促销活动
|
|
|
+ else if (null != promotions || null != shopPromotions) {
|
|
|
+ // 是否包含活动商品(受订单未支付自动关闭时间影响) 0 否 1 是
|
|
|
+ hasActProductFlag = true;
|
|
|
+ // 关闭阶梯价格,活动优先
|
|
|
+ product.setLadderPriceFlag(0);
|
|
|
+ product.setActProduct(1);
|
|
|
+ if (null != promotions && promotions.getType() == 1 && promotions.getMode() == 1) {
|
|
|
+ discountPrice = promotions.getTouchPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //有阶梯价
|
|
|
+ else if (1 == product.getLadderPriceFlag()) {
|
|
|
+ // 启用了阶梯价格
|
|
|
+ List<LadderPriceVo> ladderPrices = baseMapper.getLadderPriceList(skuId);
|
|
|
+ // 判断阶梯价格的购买数量校验
|
|
|
+ int minBuyNumber = null != ladderPrices.get(0) ? ladderPrices.get(0).getBuyNum() : 0;
|
|
|
+ if (productNum < minBuyNumber) {
|
|
|
+ return ResponseJson.error("商品购买量低于最小起订量!", null);
|
|
|
+ }
|
|
|
+ //根据商品购买数量获取商品对应阶梯价格
|
|
|
+ for (LadderPriceVo ladderPrice : ladderPrices) {
|
|
|
+ if (productNum >= ladderPrice.getBuyNum()) {
|
|
|
+ discountPrice = ladderPrice.getBuyPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ product.setLadderPrices(ladderPrices);
|
|
|
+ product.setActProduct(2);
|
|
|
+ } else {
|
|
|
+ // 复购价
|
|
|
+ Double repurchase = baseMapper.getRepurchasePrice(skuId, shopOrder.getUserId());
|
|
|
+ if (null != repurchase && repurchase > 0) {
|
|
|
+ discountPrice = repurchase;
|
|
|
+ }
|
|
|
+ product.setActProduct(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (MathUtil.compare(discountPrice, BigDecimal.ZERO) == 0) {
|
|
|
+ return ResponseJson.error("商品购买价格不能为0!", null);
|
|
|
+ }
|
|
|
+ // 不含税可开票商品计算税费
|
|
|
+ if (null == product.getTaxRate() || product.getTaxRate() <= 0) {
|
|
|
+ product.setTaxRate(0d);
|
|
|
+ }
|
|
|
+ if (taxFlag) {
|
|
|
+ productTax = MathUtil.div(MathUtil.mul(productPrice, product.getTaxRate()), 100, 2).doubleValue();
|
|
|
+ discountTax = MathUtil.div(MathUtil.mul(discountPrice, product.getTaxRate()), 100, 2).doubleValue();
|
|
|
+ } else if (!Integer.valueOf(1).equals(product.getIncludedTax())) {
|
|
|
+ // 不含税不可开票商品和未知商品,税率置为0
|
|
|
+ product.setTaxRate(0d);
|
|
|
+ }
|
|
|
+ // 商品价格
|
|
|
+ product.setPrice(productPrice);
|
|
|
+ // 商品税后价格
|
|
|
+ Double productTaxPrice = MathUtil.add(productPrice, productTax).doubleValue();
|
|
|
+ // 折后税后单价
|
|
|
+ Double discountTaxPrice = MathUtil.add(discountPrice, discountTax).doubleValue();
|
|
|
+ // 折扣率 = 折后单价/机构价
|
|
|
+ Double discountRate = MathUtil.mul(MathUtil.div(discountTaxPrice, productTaxPrice), 100).doubleValue();
|
|
|
+ // 单个商品的金额
|
|
|
+ Double productAmount = MathUtil.mul(productTaxPrice, productNum).doubleValue();
|
|
|
+ // 单个商品的折后金额
|
|
|
+ Double productFee = MathUtil.mul(discountTaxPrice, productNum).doubleValue();
|
|
|
+ // 不包含单品满减的商品金额
|
|
|
+ Double realProductFee = productFee;
|
|
|
+ // 单个商品总税费
|
|
|
+ Double taxFee = MathUtil.mul(discountTax, productNum).doubleValue();
|
|
|
+ if (hasActProductFlag && null != promotions) {
|
|
|
+ // 单品促销
|
|
|
+ if (0 == organizeId) {
|
|
|
+ if (promotions.getType() == 1) {
|
|
|
+ // 是否满足单品优惠条件(满足优惠价或者满减在这里进行设值)
|
|
|
+ if (promotions.getMode() == 1 || MathUtil.compare(productFee, promotions.getTouchPrice()) >= 0) {
|
|
|
+ // 满减
|
|
|
+ if (promotions.getMode() == 2) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 1) {
|
|
|
+ //叠加优惠计算
|
|
|
+ //叠加倍数
|
|
|
+ Double floor = Math.floor(MathUtil.div(productFee, promotions.getTouchPrice()).doubleValue());
|
|
|
+ promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ productFee = MathUtil.sub(productFee, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue();
|
|
|
+ } else {
|
|
|
+ // 统计订单总满减金额
|
|
|
+ promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
|
|
|
+ // 统计单个商品的折后金额
|
|
|
+ productFee = MathUtil.sub(productFee, promotions.getReducedPrice()).doubleValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加到总促销
|
|
|
+ if (!promotionsIds.contains(promotions.getId())) {
|
|
|
+ promotionsIds.add(promotions.getId());
|
|
|
+ promotions.setPromotionsId(promotions.getId());
|
|
|
+ promotionList.add(promotions);
|
|
|
+ }
|
|
|
+ product.setOrderPromotionsId(promotions.getId());
|
|
|
+ }
|
|
|
+ // 凑单优惠
|
|
|
+ } else if (promotions.getType() == 2) {
|
|
|
+ // 商品添加到总促销
|
|
|
+ PromotionPriceVo promotionPrice = new PromotionPriceVo();
|
|
|
+ promotionPrice.setProductId(product.getProductId());
|
|
|
+ promotionPrice.setNumber(productNum);
|
|
|
+ promotionPrice.setPrice(discountTaxPrice);
|
|
|
+ if (null == promotions.getProductList()) {
|
|
|
+ promotions.setProductList(new ArrayList<>());
|
|
|
+ }
|
|
|
+ promotions.getProductList().add(promotionPrice);
|
|
|
+ if (!promotionsIds.contains(promotions.getId())) {
|
|
|
+ promotionsIds.add(promotions.getId());
|
|
|
+ promotions.setPromotionsId(promotions.getId());
|
|
|
+ promotionList.add(promotions);
|
|
|
+ } else {
|
|
|
+ PromotionsVo finalPromotions = promotions;
|
|
|
+ promotionList.forEach(promotionsTemp -> {
|
|
|
+ if (finalPromotions.getId().equals(promotionsTemp.getId())) {
|
|
|
+ promotionsTemp.getProductList().add(promotionPrice);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ product.setOrderPromotionsId(promotions.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 折后单价
|
|
|
+ product.setDiscountPrice(discountPrice);
|
|
|
+ // 折扣率 = 折后单价/机构价
|
|
|
+ product.setDiscount(discountRate);
|
|
|
+ if (svipPriceFlag || (null != promotions && promotions.getType() == 1 && promotions.getMode() == 1)) {
|
|
|
+ // 超级会员价/单品优惠折扣率设置为100%
|
|
|
+ product.setDiscount(100d);
|
|
|
+ }
|
|
|
+ // 单个商品的金额
|
|
|
+ product.setTotalAmount(productAmount);
|
|
|
+ // 单个商品的折后金额
|
|
|
+ product.setTotalFee(productFee);
|
|
|
+ product.setShouldPayFee(productFee);
|
|
|
+ product.setRealProductFee(realProductFee);
|
|
|
+ // 税费
|
|
|
+ product.setAddedValueTax(discountTax);
|
|
|
+ product.setTotalAddedValueTax(taxFee);
|
|
|
+ }
|
|
|
+ // 成本价
|
|
|
+ Double costPrice = null;
|
|
|
+ // 判断是否选中固定成本价
|
|
|
+ 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;
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ if (null == costPrice) {
|
|
|
+ return ResponseJson.error("订单商品成本异常!", null);
|
|
|
+ }
|
|
|
+ product.setCostPrice(costPrice);
|
|
|
+ // 付供应商税费
|
|
|
+ if (null == product.getShopTaxRate() || product.getShopTaxRate() <= 0) {
|
|
|
+ product.setShopTaxRate(product.getTaxRate());
|
|
|
+ }
|
|
|
+ if (taxFlag) {
|
|
|
+ shopTax = MathUtil.div(MathUtil.mul(costPrice, product.getShopTaxRate()), 100, 2).doubleValue();
|
|
|
+ } else if (!Integer.valueOf(1).equals(product.getIncludedTax())) {
|
|
|
+ // 不含税不可开票商品和未知商品,税率置为0
|
|
|
+ product.setShopTaxRate(0d);
|
|
|
+ }
|
|
|
+ // 单个付供应商税费
|
|
|
+ product.setSingleShouldPayTotalTax(shopTax);
|
|
|
+ // 单个商品付供应商总税费
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ product.setShopProductAmount(costAmount);
|
|
|
+
|
|
|
+ //应付供应商(单)=成本价+供应商税费(单)
|
|
|
+ Double singleShopFee = MathUtil.add(product.getCostPrice(), shopTax).doubleValue();
|
|
|
+ product.setSingleShopFee(singleShopFee);
|
|
|
+ // 应付供应商(总)=应付供应商(单) * 商品数量
|
|
|
+ Double shopFee = MathUtil.add(product.getCostPrice(), shopTax).doubleValue();
|
|
|
+ product.setShopFee(shopFee);
|
|
|
+ // 付第三方,默认0
|
|
|
+ product.setOtherFee(0d);
|
|
|
+ product.setSingleOtherFee(0d);
|
|
|
+ //应付采美(单)=单价+机构税费(单)-(成本(单)+供应商税费(单))
|
|
|
+ Double singleCmFee = MathUtil.sub(MathUtil.add(BigDecimal.valueOf(product.getPrice()), product.getAddedValueTax()), MathUtil.add(product.getCostPrice(), shopTax)).doubleValue();
|
|
|
+ product.setSingleCmFee(singleCmFee);
|
|
|
+ // 应付采美(总)=应付采美(单)*商品数量
|
|
|
+ Double cmFee = MathUtil.mul(singleCmFee, productNum).doubleValue();
|
|
|
+ product.setCmFee(cmFee);
|
|
|
+ // 默认未支付
|
|
|
+ product.setPayStatus(0);
|
|
|
+ // 默认非再次购买商品
|
|
|
+ product.setBuyAgainFlag(0);
|
|
|
+ // 未出库数量
|
|
|
+ product.setNotOutStore(productNum);
|
|
|
+ /*
|
|
|
+ * 子订单金额计算
|
|
|
+ */
|
|
|
+
|
|
|
+ // 佣金 = 应付采美
|
|
|
+ brokerage.set(MathUtil.add(brokerage.get(), product.getCmFee()).doubleValue());
|
|
|
+ // 需要支付金额 shouldPayFee +运费
|
|
|
+ needPayAmount.set(MathUtil.add(needPayAmount.get(), product.getShouldPayFee()).doubleValue());
|
|
|
+ // 不包含单品满减的子订单需付金额
|
|
|
+ realNeedPay.set(MathUtil.add(realNeedPay.get(), product.getRealProductFee()).doubleValue());
|
|
|
+ // 统计 总金额 包括税费
|
|
|
+ shopProductFee.set(MathUtil.add(shopProductFee.get(), product.getTotalFee()).doubleValue());
|
|
|
+ // 统计子订单内可参与店铺促销的商品总金额
|
|
|
+ if (!svipPriceFlag) {
|
|
|
+ // 超级会员购买优惠商品,不能参与店铺促销
|
|
|
+ shopPromotionFee.set(MathUtil.add(shopPromotionFee.get(), product.getTotalFee()).doubleValue());
|
|
|
+ }
|
|
|
+ // 商品总金额
|
|
|
+ shopAmount.set(MathUtil.add(shopAmount.get(), product.getTotalAmount()).doubleValue());
|
|
|
+ // 付供应商 商品费
|
|
|
+ log.info("shopProductAmount.get()" + shopProductAmount.get());
|
|
|
+ log.info("product.getShopProductAmount()" + product.getShopProductAmount());
|
|
|
+ shopProductAmount.set(MathUtil.add(shopProductAmount.get(), product.getShopProductAmount()).doubleValue());
|
|
|
+ // 付供应商税费
|
|
|
+ shopTaxFee.set(MathUtil.add(shopTaxFee.get(), product.getShouldPayTotalTax()).doubleValue());
|
|
|
+ if (0 != organizeId) {
|
|
|
+ // 佣金比例 外部商城sku配置比例
|
|
|
+ CmOrganizeSkuPo organizeSkuInfo = submitMapper.getOrganizeSkuInfo(skuId);
|
|
|
+ product.setCmPercent(organizeSkuInfo.getCmPercent());
|
|
|
+ product.setOrganizePercent(organizeSkuInfo.getOrganizePercent());
|
|
|
+ product.setShopPercent(organizeSkuInfo.getShopPercent());
|
|
|
+ }
|
|
|
+ // 加入订单商品列表
|
|
|
+ orderProductList.add(product);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (0 == organizeId) {
|
|
|
+ if (null != shopPromotions) {
|
|
|
+ // 是否满足满减满赠
|
|
|
+ if (MathUtil.compare(shopPromotionFee.get(), shopPromotions.getTouchPrice()) >= 0) {
|
|
|
+ // 是否包含活动商品(受订单未支付自动关闭时间影响) 0 否 1 是
|
|
|
+ hasActProductFlag = true;
|
|
|
+ // 满减
|
|
|
+ if (shopPromotions.getMode() == 2) {
|
|
|
+ if (shopPromotions.getDiscount() != null && shopPromotions.getDiscount() == 1) {
|
|
|
+ //叠加优惠计算
|
|
|
+ //叠加倍数
|
|
|
+ Double floor = Math.floor(MathUtil.div(shopPromotionFee.get(), shopPromotions.getTouchPrice()).doubleValue());
|
|
|
+ // 供应商满减金额
|
|
|
+ shopOrder.setPromotionFullReduction(MathUtil.mul(shopPromotions.getReducedPrice(), floor).doubleValue());
|
|
|
+ // 统计订单总满减金额
|
|
|
+ promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ // 统计店铺商品总金额
|
|
|
+ shopProductFee.set(MathUtil.sub(shopProductFee.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ // 统计需要支付金额
|
|
|
+ needPayAmount.set(MathUtil.sub(needPayAmount.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ // 统计需要支付金额
|
|
|
+ shopAmount.set(MathUtil.sub(shopAmount.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ } else {
|
|
|
+ // 供应商满减金额
|
|
|
+ shopOrder.setPromotionFullReduction(shopPromotions.getReducedPrice());
|
|
|
+ // 统计订单总满减金额
|
|
|
+ promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), shopPromotions.getReducedPrice()).doubleValue());
|
|
|
+ // 统计店铺商品总金额
|
|
|
+ shopProductFee.set(MathUtil.sub(shopProductFee.get(), shopPromotions.getReducedPrice()).doubleValue());
|
|
|
+ // 统计需要支付金额
|
|
|
+ needPayAmount.set(MathUtil.sub(needPayAmount.get(), shopPromotions.getReducedPrice()).doubleValue());
|
|
|
+ // 统计需要支付金额
|
|
|
+ shopAmount.set(MathUtil.sub(shopAmount.get(), shopPromotions.getReducedPrice()).doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加到总促销
|
|
|
+ if (!promotionsIds.contains(shopPromotions.getId())) {
|
|
|
+ promotionsIds.add(shopPromotions.getId());
|
|
|
+ shopPromotions.setPromotionsId(shopPromotions.getId());
|
|
|
+ promotionList.add(shopPromotions);
|
|
|
+ }
|
|
|
+ shopOrder.setOrderPromotionsId(shopPromotions.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 佣金 采美应收
|
|
|
+ shopOrder.setBrokerage(brokerage.get());
|
|
|
+ // 可退款金额 = 余额抵扣金额
|
|
|
+ shopOrder.setCanRefundAmount(needPayAmount.get());
|
|
|
+ // 购买商品数
|
|
|
+ shopOrder.setItemCount(shopProductCount.get());
|
|
|
+ // 超级会员优惠金额
|
|
|
+ shopOrder.setSvipShopReduction(svipShopReduction.get());
|
|
|
+ // 总价(含税) = totalFee
|
|
|
+ shopOrder.setTotalAmount(MathUtil.add(shopProductFee.get(), shopOrder.getShopPostFee()).doubleValue());
|
|
|
+ // 总金额 = 订单商品totalAmount
|
|
|
+ shopOrder.setProductAmount(shopAmount.get());
|
|
|
+ // 需要支付金额 shouldPayFee +运费
|
|
|
+ shopOrder.setNeedPayAmount(needPayAmount.get());
|
|
|
+ // 设值
|
|
|
+ shopOrder.setRealNeedPay(realNeedPay.get());
|
|
|
+ // 付供应商 商品费=成本价*(购买数量 + 赠品数量)
|
|
|
+ shopOrder.setShopProductAmount(shopProductAmount.get());
|
|
|
+ // 付给供应商税费
|
|
|
+ shopOrder.setShopTaxFee(shopTaxFee.get());
|
|
|
+ // 付供应商 = 商品费 + 运费 + 税费
|
|
|
+ shopOrder.setShouldPayShopAmount(MathUtil.add(shopProductAmount.get(), shopTaxFee.get()).doubleValue());
|
|
|
+
|
|
|
+ orderProductList.forEach(o -> submitMapper.updateOrderProduct(o));
|
|
|
+ /**
|
|
|
+ * 由于余额抵扣过的子订单可以修改,有收款非余额抵扣的仅需改变子订单相关应收/应付金额
|
|
|
+ * 如果有余额抵扣,应计算余额抵扣金额,如果子订单应收总金额减少且余额抵扣金额大于应收,
|
|
|
+ * 则退还余额给用户,同时计算子订单的收款状态修改
|
|
|
+ */
|
|
|
+ List<BalanceRecordPo> records = baseMapper.findShopOrderBalanceRecord(shopOrder.getShopOrderId());
|
|
|
+ if (null != records && records.size() > 0) {
|
|
|
+ double total = records.stream().mapToDouble(BalanceRecordPo::getAmount).sum();
|
|
|
+ /**
|
|
|
+ * 总抵扣金额 < 子订单应收,改变子订单状态,子订单部分收,抵扣金额>子订单应收,退余额,子订单已收
|
|
|
+ * shopOrderStatus: 0待确认,11待收待发,12待收部发,13待收全发,21部收待发,22部收部发,23部收全发,31已收待发,
|
|
|
+ * 32已收部发,33已收全发,4交易完成,5订单完成,6已关闭,7交易全退
|
|
|
+ */
|
|
|
+ String status = shopOrder.getStatus().toString();
|
|
|
+ if (total < shopOrder.getNeedPayAmount()) {
|
|
|
+ shopOrder.setReceiptStatus(2);
|
|
|
+ }else{
|
|
|
+ shopOrder.setReceiptStatus(3);
|
|
|
+ shopOrder.setAccountAmount(total);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ submitMapper.updateShopOrder(shopOrder);
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|