|
@@ -20,11 +20,9 @@ import com.caimei365.order.utils.MathUtil;
|
|
|
import com.google.common.util.concurrent.AtomicDouble;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
@@ -285,6 +283,8 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
mainOrder.setRefundType(0);
|
|
|
// 未确认付款供应商
|
|
|
mainOrder.setAffirmPaymentFlag(0);
|
|
|
+ // 是否开发票
|
|
|
+ mainOrder.setInvoiceFlag(orderUserBo.getInvoiceType());
|
|
|
|
|
|
/*
|
|
|
* 整理订单商品信息
|
|
@@ -295,6 +295,8 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
AtomicInteger presentCount = new AtomicInteger(0);
|
|
|
// 促销赠品数量
|
|
|
AtomicInteger promotionalGiftsCount = new AtomicInteger(0);
|
|
|
+ // 促销满减优惠
|
|
|
+ AtomicDouble promotionFullReduction = new AtomicDouble(0);
|
|
|
// 商品总金额 (商品单价乘以数量,再加上税费)
|
|
|
AtomicDouble productTotalFee = new AtomicDouble(0);
|
|
|
// 订单总额(小计金额减去经理折扣后,再加上运费[默认0])
|
|
@@ -315,10 +317,14 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 订单商品列表
|
|
|
List<ProductBo> orderProductList = new ArrayList<>();
|
|
|
List<String> productIdList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 子订单订单列表
|
|
|
+ List<ShopOrderPo> shopOrderList = new ArrayList<>();
|
|
|
JSONArray orderInfo = orderUserBo.getOrderInfo();
|
|
|
for (Object infoObject: orderInfo) {
|
|
|
JSONObject shopInfo = (JSONObject) infoObject;
|
|
|
Integer shopId = (Integer) shopInfo.get("shopId");
|
|
|
+ String shopNote = (String) shopInfo.get("note");
|
|
|
if (null == shopId) {
|
|
|
return ResponseJson.error("供应商数据异常!", null);
|
|
|
}
|
|
@@ -328,8 +334,39 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
// 供应商名称
|
|
|
String shopName = submitMapper.getShopNameById(shopId);
|
|
|
+ /*
|
|
|
+ * 初始化子订单
|
|
|
+ */
|
|
|
+ ShopOrderPo shopOrder = new ShopOrderPo();
|
|
|
+ shopOrder.setShopId(shopId);
|
|
|
+ shopOrder.setShopName(shopName);
|
|
|
+ shopOrder.setNote(shopNote);
|
|
|
+ // 用户Id
|
|
|
+ shopOrder.setUserId(orderUserBo.getUserId());
|
|
|
+ shopOrder.setClubId(orderUserBo.getClubId());
|
|
|
+ if (3 == orderUserBo.getCartType()) {
|
|
|
+ // 协销订单
|
|
|
+ shopOrder.setSpId(orderUserBo.getBuyUserId());
|
|
|
+ }
|
|
|
+ // 商品总数量
|
|
|
+ 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);
|
|
|
+
|
|
|
+ // 店铺促销活动状态
|
|
|
+ PromotionsVo shopPromotions = baseMapper.getPromotionByShopId(shopId);
|
|
|
// 商品信息ids
|
|
|
List<Integer> shopProductIds = new ArrayList<>();
|
|
|
+ // 商品费
|
|
|
+ AtomicDouble shopProductFee = new AtomicDouble(0);
|
|
|
// 遍历所有商品
|
|
|
for (Object productObject : productArr) {
|
|
|
JSONObject productTemp = (JSONObject) productObject;
|
|
@@ -394,7 +431,8 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
product.setTaxRate(0d);
|
|
|
product.setAddedValueTax(0d);
|
|
|
product.setTotalAddedValueTax(0d);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
// 获取商品购买价格(活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
|
|
|
Double productPrice = product.getPrice();
|
|
|
Double discountPrice = product.getPrice();
|
|
@@ -402,7 +440,11 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
Double productTax = 0d;
|
|
|
Double discountTax = 0d;
|
|
|
// 商品是否处于活动状态
|
|
|
- PromotionsVo promotions = baseMapper.getPromotionByProductId(productId);
|
|
|
+ PromotionsVo promotions = null;
|
|
|
+ // 店铺促销优先
|
|
|
+ if (null == shopPromotions) {
|
|
|
+ promotions = baseMapper.getPromotionByProductId(productId);
|
|
|
+ }
|
|
|
// 计算单价
|
|
|
if (promotions != null) {
|
|
|
// 是否包含活动商品(受订单未支付自动关闭时间影响) 0 否 1 是
|
|
@@ -452,49 +494,74 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
// 商品价格
|
|
|
productPrice = MathUtil.add(productPrice, productTax).doubleValue();
|
|
|
- product.setPrice(productPrice);
|
|
|
// 折后单价
|
|
|
discountPrice = MathUtil.add(discountPrice, discountTax).doubleValue();
|
|
|
- product.setDiscountPrice(discountPrice);
|
|
|
// 折扣率 = 折后单价/机构价
|
|
|
Double discountRate = MathUtil.mul(MathUtil.div(discountPrice, productPrice), 100).doubleValue();
|
|
|
- product.setDiscount(discountRate);
|
|
|
// 单个商品的金额
|
|
|
Double productAmount = MathUtil.mul(productPrice, productNum).doubleValue();
|
|
|
- product.setTotalAmount(productAmount);
|
|
|
// 单个商品的折后金额
|
|
|
Double productFee = MathUtil.mul(discountPrice, productNum).doubleValue();
|
|
|
- product.setTotalFee(productFee);
|
|
|
- product.setShouldPayFee(productFee);
|
|
|
// 单个商品总税费
|
|
|
Double taxFee = MathUtil.mul(discountTax, productNum).doubleValue();
|
|
|
- // 税费
|
|
|
- product.setAddedValueTax(discountTax);
|
|
|
- product.setTotalAddedValueTax(taxFee);
|
|
|
if (hasActProductFlag && null != promotions) {
|
|
|
- // 商品添加到总促销
|
|
|
- PromotionPriceVo promotionPrice = new PromotionPriceVo();
|
|
|
- promotionPrice.setProductId(productId);
|
|
|
- promotionPrice.setNumber(productNum);
|
|
|
- promotionPrice.setPrice(discountPrice);
|
|
|
- promotions.getProductList().add(promotionPrice);
|
|
|
- if (!promotionsIds.contains(promotions.getId())) {
|
|
|
- promotionsIds.add(promotions.getId());
|
|
|
- promotions.setPromotionsId(promotions.getId());
|
|
|
- promotionList.add(promotions);
|
|
|
- } else {
|
|
|
- promotionList.forEach(promotionsTemp -> {
|
|
|
- if (promotions.getId().equals(promotionsTemp.getId())){
|
|
|
- promotionsTemp.getProductList().add(promotionPrice);
|
|
|
+ // 单品优惠
|
|
|
+ if (promotions.getType() == 1) {
|
|
|
+ // 是否满足满减满赠
|
|
|
+ if (MathUtil.compare(productFee, promotions.getTouchPrice()) >= 0) {
|
|
|
+ // 满减
|
|
|
+ if (promotions.getMode() == 2) {
|
|
|
+ // 统计订单总满减金额
|
|
|
+ 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(productId);
|
|
|
+ promotionPrice.setNumber(productNum);
|
|
|
+ promotionPrice.setPrice(discountPrice);
|
|
|
+ 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.setOrderPromotionsId(promotions.getId());
|
|
|
}
|
|
|
+ // 商品价格
|
|
|
+ product.setPrice(productPrice);
|
|
|
+ // 折后单价
|
|
|
+ product.setDiscountPrice(discountPrice);
|
|
|
+ // 折扣率 = 折后单价/机构价
|
|
|
+ product.setDiscount(discountRate);
|
|
|
+ // 单个商品的金额
|
|
|
+ product.setTotalAmount(productAmount);
|
|
|
+ // 单个商品的折后金额
|
|
|
+ product.setTotalFee(productFee);
|
|
|
+ product.setShouldPayFee(productFee);
|
|
|
+ // 税费
|
|
|
+ product.setAddedValueTax(discountTax);
|
|
|
+ product.setTotalAddedValueTax(taxFee);
|
|
|
}
|
|
|
- // 统计商品总金额
|
|
|
- productTotalFee.set(MathUtil.add(productTotalFee.get(), product.getTotalFee()).doubleValue());
|
|
|
-
|
|
|
// 付供应商税费
|
|
|
if (null == product.getShopTaxRate() || product.getShopTaxRate() <= 0) {
|
|
|
product.setShopTaxRate(product.getTaxRate());
|
|
@@ -508,11 +575,10 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// 单个付供应商税费
|
|
|
product.setSingleShouldPayTotalTax(shopTax);
|
|
|
// 单个商品付供应商总税费
|
|
|
- Double shopTaxFee = MathUtil.mul(shopTax, productNum).doubleValue();
|
|
|
- product.setShouldPayTotalTax(shopTaxFee);
|
|
|
+ product.setShouldPayTotalTax(MathUtil.mul(shopTax, productNum).doubleValue());
|
|
|
// 付供应商 商品费=成本价*(购买数量 + 赠品数量)
|
|
|
- Double shopProductAmount = MathUtil.mul(costPrice, MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
- product.setShopProductAmount(shopProductAmount);
|
|
|
+ Double costAmount = MathUtil.mul(costPrice, MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
+ product.setShopProductAmount(costAmount);
|
|
|
//应付供应商(单)=成本价+供应商税费(单)
|
|
|
Double singleShopFee = MathUtil.add(product.getCostPrice(), shopTax).doubleValue();
|
|
|
product.setSingleShopFee(singleShopFee);
|
|
@@ -534,11 +600,79 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
product.setBuyAgainFlag(0);
|
|
|
// 未出库数量
|
|
|
product.setNotOutStore(productNum);
|
|
|
+ /*
|
|
|
+ * 子订单金额计算
|
|
|
+ */
|
|
|
+ // 供应商商品数量
|
|
|
+ shopProductCount.set(shopProductCount.get()+product.getNum());
|
|
|
+ // 佣金 = 应付采美
|
|
|
+ brokerage.set(MathUtil.add(brokerage.get(), product.getCmFee()).doubleValue());
|
|
|
+ // 需要支付金额 shouldPayFee +运费
|
|
|
+ needPayAmount.set(MathUtil.add(needPayAmount.get(), product.getShouldPayFee()).doubleValue());
|
|
|
+ // 统计 总金额 包括税费
|
|
|
+ shopProductFee.set(MathUtil.add(shopProductFee.get(), product.getTotalFee()).doubleValue());
|
|
|
+ // 商品总金额
|
|
|
+ shopAmount.set(MathUtil.add(shopAmount.get(), product.getTotalAmount()).doubleValue());
|
|
|
+ // 付供应商 商品费
|
|
|
+ shopProductAmount.set(MathUtil.add(shopProductAmount.get(), product.getShopProductAmount()).doubleValue());
|
|
|
+ // 付供应商税费
|
|
|
+ shopTaxFee.set(MathUtil.add(shopTaxFee.get(), product.getShouldPayTotalTax()).doubleValue());
|
|
|
|
|
|
// 加入订单商品列表
|
|
|
orderProductList.add(product);
|
|
|
productIdList.add(product.getProductId().toString());
|
|
|
}
|
|
|
+
|
|
|
+ if (null != shopPromotions) {
|
|
|
+ // 是否满足满减满赠
|
|
|
+ if (MathUtil.compare(shopProductFee.get(), shopPromotions.getTouchPrice()) >= 0) {
|
|
|
+ // 是否包含活动商品(受订单未支付自动关闭时间影响) 0 否 1 是
|
|
|
+ hasActProductFlag = true;
|
|
|
+ // 满减
|
|
|
+ if (shopPromotions.getMode() == 2) {
|
|
|
+ // 供应商满减金额
|
|
|
+ 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());
|
|
|
+ // 总价(含税) = totalFee
|
|
|
+ shopOrder.setTotalAmount(shopProductFee.get());
|
|
|
+ // 总金额 = 订单商品totalAmount
|
|
|
+ shopOrder.setProductAmount(shopAmount.get());
|
|
|
+ // 需要支付金额 shouldPayFee +运费
|
|
|
+ shopOrder.setNeedPayAmount(needPayAmount.get());
|
|
|
+ // 付供应商 商品费=成本价*(购买数量 + 赠品数量)
|
|
|
+ shopOrder.setShopProductAmount(shopProductAmount.get());
|
|
|
+ // 付给供应商税费
|
|
|
+ shopOrder.setShopTaxFee(shopTaxFee.get());
|
|
|
+ // 付供应商 = 商品费 + 运费 + 税费
|
|
|
+ shopOrder.setShouldPayShopAmount(MathUtil.add(shopProductAmount.get(), shopTaxFee.get()).doubleValue());
|
|
|
+
|
|
|
+ // 添加到子订单列表
|
|
|
+ shopOrderList.add(shopOrder);
|
|
|
+ // 统计商品总金额
|
|
|
+ productTotalFee.set(MathUtil.add(productTotalFee.get(), shopProductFee.get()).doubleValue());
|
|
|
}
|
|
|
if (orderProductList.size()==0){
|
|
|
return ResponseJson.error("订单商品数据异常!", null);
|
|
@@ -554,30 +688,31 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
mainOrder.setHasActProduct(0);
|
|
|
} else {
|
|
|
mainOrder.setHasActProduct(1);
|
|
|
- // 促销满减优惠
|
|
|
- AtomicDouble promotionFullReduction = new AtomicDouble(0);
|
|
|
// 促销活动优惠计算
|
|
|
Iterator<PromotionsVo> promotionsIterator = promotionList.iterator();
|
|
|
while (promotionsIterator.hasNext()) {
|
|
|
PromotionsVo promotions = promotionsIterator.next();
|
|
|
- // 这里计算满减满赠
|
|
|
- if (promotions.getMode() == 2 || promotions.getMode() == 3) {
|
|
|
- // 实际该促销商品总额
|
|
|
- AtomicDouble touchPrice = new AtomicDouble(0);
|
|
|
- promotions.getProductList().forEach(item -> {
|
|
|
- touchPrice.set(MathUtil.add(touchPrice.get(), MathUtil.mul(item.getNumber(), item.getPrice())).doubleValue());
|
|
|
- });
|
|
|
- //判断是否达到满减满赠要求
|
|
|
- if (MathUtil.compare(touchPrice.get(), promotions.getTouchPrice()) >= 0) {
|
|
|
- if (promotions.getMode() == 2) {
|
|
|
- // 满减
|
|
|
- promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
|
|
|
- // 统计商品总金额
|
|
|
- productTotalFee.set(MathUtil.sub(productTotalFee.get(), promotions.getReducedPrice()).doubleValue());
|
|
|
+ // 凑单优惠计算(单品与店铺已再前面分开计算了)
|
|
|
+ if (promotions.getType() == 2) {
|
|
|
+ // 这里计算满减满赠
|
|
|
+ if (promotions.getMode() == 2 || promotions.getMode() == 3) {
|
|
|
+ // 实际该促销商品总额
|
|
|
+ AtomicDouble tempProductFee = new AtomicDouble(0);
|
|
|
+ promotions.getProductList().forEach(item -> {
|
|
|
+ tempProductFee.set(MathUtil.add(tempProductFee.get(), MathUtil.mul(item.getNumber(), item.getPrice())).doubleValue());
|
|
|
+ });
|
|
|
+ //判断是否达到满减满赠要求
|
|
|
+ if (MathUtil.compare(tempProductFee.get(), promotions.getTouchPrice()) >= 0) {
|
|
|
+ if (promotions.getMode() == 2) {
|
|
|
+ // 满减
|
|
|
+ promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
|
|
|
+ // 统计商品总金额
|
|
|
+ productTotalFee.set(MathUtil.sub(productTotalFee.get(), promotions.getReducedPrice()).doubleValue());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 删除不满足条件的凑单促销
|
|
|
+ promotionsIterator.remove();
|
|
|
}
|
|
|
- } else {
|
|
|
- // 删除不满足条件的促销
|
|
|
- promotionsIterator.remove();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -590,54 +725,6 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
mainOrder.setPresentCount(presentCount.get());
|
|
|
//促销赠品数量
|
|
|
mainOrder.setPromotionalGiftsCount(promotionalGiftsCount.get());
|
|
|
- /*
|
|
|
- * 发票信息
|
|
|
- */
|
|
|
- boolean hasInvoiceFlag = false;
|
|
|
- InvoicePo invoice = new InvoicePo();
|
|
|
- mainOrder.setInvoiceFlag(orderUserBo.getInvoiceType());
|
|
|
- // 发票类型 0不开发票 1普通发票 2增值税发票
|
|
|
- if (1== orderUserBo.getInvoiceType() || 2 == orderUserBo.getInvoiceType()){
|
|
|
- JSONObject orderInvoice = orderUserBo.getOrderInvoice();
|
|
|
- Integer invoiceType = (Integer) orderInvoice.get("type");
|
|
|
- String invoiceTitle = (String) orderInvoice.get("invoiceTitle");
|
|
|
- if (StringUtils.isNotEmpty(invoiceTitle)){
|
|
|
- return ResponseJson.error("发票抬头信息不正确!", null);
|
|
|
- }
|
|
|
- String corporationTaxNum = (String) orderInvoice.get("corporationTaxNum");
|
|
|
- if (StringUtils.isNotEmpty(corporationTaxNum)){
|
|
|
- return ResponseJson.error("纳税人识别号信息不正确!", null);
|
|
|
- }
|
|
|
- invoice.setType(invoiceType);
|
|
|
- invoice.setInvoiceTitle(invoiceTitle);
|
|
|
- invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
- if (1== orderUserBo.getInvoiceType()) {
|
|
|
- // 普通发票:发票类型、发票内容(商品明细)、抬头(公司名称)、纳税人识别号[普通发票的公司]
|
|
|
- String invoiceContent = (String) orderInvoice.get("invoiceContent");
|
|
|
- Integer invoiceTitleType = (Integer) orderInvoice.get("invoiceTitleType");
|
|
|
- if (StringUtils.isNotEmpty(invoiceContent) || null == invoiceTitleType) {
|
|
|
- return ResponseJson.error("发票信息不完整!", null);
|
|
|
- }
|
|
|
- invoice.setInvoiceContent(invoiceContent);
|
|
|
- invoice.setInvoiceTitleType(invoiceTitleType);
|
|
|
- hasInvoiceFlag = true;
|
|
|
- }
|
|
|
- if (2== orderUserBo.getInvoiceType()) {
|
|
|
- // 增值税发票:发票类型、发票、抬头(公司名称)、纳税人识别号、注册地址、注册电话、开户银行、开户银行账户
|
|
|
- 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.isNotEmpty(registeredAddress) || StringUtils.isNotEmpty(registeredPhone) || StringUtils.isNotEmpty(openBank) || StringUtils.isNotEmpty(bankAccountNo)) {
|
|
|
- return ResponseJson.error("发票信息不完整!", null);
|
|
|
- }
|
|
|
- invoice.setRegisteredAddress(registeredAddress);
|
|
|
- invoice.setRegisteredPhone(registeredPhone);
|
|
|
- invoice.setOpenBank(openBank);
|
|
|
- invoice.setBankAccountNo(bankAccountNo);
|
|
|
- hasInvoiceFlag = true;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/*
|
|
|
* 计算运费
|
|
@@ -759,13 +846,13 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 保存主订单数据
|
|
|
+ * 保存主订单数据,返回订单Id
|
|
|
*/
|
|
|
submitMapper.insertMainOrder(mainOrder);
|
|
|
log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增主订单(insert[cm_order])orderId:" + mainOrder.getOrderId());
|
|
|
|
|
|
/*
|
|
|
- * 保存订单促销
|
|
|
+ * 保存订单促销,返回订单促销Id
|
|
|
*/
|
|
|
promotionList.forEach(promotions -> {
|
|
|
promotions.setOrderId(mainOrder.getOrderId());
|
|
@@ -773,80 +860,70 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增订单促销活动(insert[cm_promotions_order])id:" + promotions.getId());
|
|
|
});
|
|
|
|
|
|
- /*
|
|
|
- * 保存订单发票信息
|
|
|
- */
|
|
|
- if (hasInvoiceFlag) {
|
|
|
- // 开发票才保存
|
|
|
- invoice.setOrderId(mainOrder.getOrderId());
|
|
|
- // 一个订单只有一条发票信息,删除老的订单增值税信息
|
|
|
- submitMapper.deleteOrderInvoiceByOrderId(mainOrder.getOrderId());
|
|
|
- // 保存 订单发票信息
|
|
|
- submitMapper.insertOrderInvoice(invoice);
|
|
|
- log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单发票信息(insert[bp_order_invoice])orderId:" + mainOrder.getOrderId());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/*
|
|
|
* 整理 子订单信息
|
|
|
*/
|
|
|
- // 收集子订单供应商ID字符串
|
|
|
- String shopOrderIds = "";
|
|
|
- for (Object infoObject: orderInfo) {
|
|
|
- JSONObject shopInfo = (JSONObject) infoObject;
|
|
|
- Integer shopId = (Integer) shopInfo.get("shopId");
|
|
|
- String shopNote = (String) shopInfo.get("note");
|
|
|
- // 初始化子订单信息
|
|
|
- ShopOrderPo shopOrder = new ShopOrderPo();
|
|
|
- shopOrder.setShopId(shopId);
|
|
|
- shopOrder.setNote(shopNote);
|
|
|
+ AtomicReference<String> shopOrderIds = new AtomicReference<>();
|
|
|
+ AtomicInteger shopOrderIndex = new AtomicInteger(1);
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
shopOrder.setOrderId(mainOrder.getOrderId());
|
|
|
shopOrder.setOrderNo(mainOrder.getOrderNo());
|
|
|
- shopOrder.setClubId(mainOrder.getClubId());
|
|
|
- // 子订单设值并 保存
|
|
|
- //saveShopOrder(shopOrder, orderProductList, promotionList);
|
|
|
- // 记录子订单编号
|
|
|
- shopOrderIds = (StringUtils.isEmpty(shopOrderIds) ? ""+shopOrder.getShopOrderId() : ","+shopOrder.getShopOrderId());
|
|
|
- // 设置订单商品订单号
|
|
|
-// for (ProductBo orderProduct : orderProductList) {
|
|
|
-// if (shopId.equals(orderProduct.getShopId())) {
|
|
|
-// orderProduct.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
-// orderProduct.setShopOrderNo(shopOrder.getShopOrderNo());
|
|
|
-// orderProduct.setOrderId(mainOrder.getOrderId());
|
|
|
-// orderProduct.setOrderNo(mainOrder.getOrderNo());
|
|
|
-// if (null != orderProduct.getOrderPromotionsId()) {
|
|
|
-// promotionList.forEach(promotions -> {
|
|
|
-// if (orderProduct.getOrderPromotionsId().equals(promotions.getPromotionsId())){
|
|
|
-// orderProduct.setOrderPromotionsId(promotions.getId());
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 设置邮费子订单
|
|
|
- */
|
|
|
- if (1 == mainOrder.getFreePostFlag()) {
|
|
|
- //Integer postageOrderId = setPostageOrder(mainOrder, shopOrderIds, orderInfo.size());
|
|
|
- // 记录子订单编号
|
|
|
- //shopOrderIds = (StringUtils.isEmpty(shopOrderIds) ? ""+postageOrderId : ","+postageOrderId);
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 更新主订单的子订单Id信息,如:1000,1002
|
|
|
- */
|
|
|
- if (StringUtils.isNotEmpty(shopOrderIds)) {
|
|
|
- mainOrder.setShopOrderIds(shopOrderIds);
|
|
|
- //submitMapper.updateShopOrderIds(shopOrderIds, mainOrder.getOrderId());
|
|
|
- } else {
|
|
|
- // 设置手动回滚事务
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return ResponseJson.error("生成子订单异常!", null);
|
|
|
- }
|
|
|
+ shopOrder.setOrderTime(mainOrder.getOrderTime());
|
|
|
+ shopOrder.setOrderSubmitType(mainOrder.getOrderSubmitType());
|
|
|
+ // 生成子订单编号
|
|
|
+ StringBuilder shopOrderNo = new StringBuilder();
|
|
|
+ shopOrderNo.append(mainOrder.getOrderNo());
|
|
|
+ if (shopOrderIndex.get() < 10) {
|
|
|
+ shopOrderNo.append("0");
|
|
|
+ }
|
|
|
+ shopOrderNo.append(shopOrderIndex.get());
|
|
|
+ shopOrderIndex.incrementAndGet();
|
|
|
+ shopOrder.setShopOrderNo(shopOrderNo.toString());
|
|
|
+ // 订单能否拆分 1 为可拆分, 0为不可拆分
|
|
|
+ if (shopOrder.getItemCount() >1) {
|
|
|
+ shopOrder.setSplitFlag(1);
|
|
|
+ } else {
|
|
|
+ shopOrder.setSplitFlag(0);
|
|
|
+ }
|
|
|
+ // 设置订单促销Id
|
|
|
+ promotionList.forEach(promotions -> {
|
|
|
+ if (promotions.getPromotionsId().equals(shopOrder.getOrderPromotionsId())) {
|
|
|
+ shopOrder.setOrderPromotionsId(promotions.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*
|
|
|
+ * 保存子订单
|
|
|
+ */
|
|
|
+ submitMapper.insertShopOrder(shopOrder);
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增子订单(insert[cm_shop_order])shopOrderId::" + shopOrder.getShopOrderId());
|
|
|
+ // 收集子订单供应商ID字符串
|
|
|
+ if (StringUtils.isEmpty(shopOrderIds.get())) {
|
|
|
+ shopOrderIds.set(shopOrder.getShopOrderId().toString());
|
|
|
+ } else {
|
|
|
+ shopOrderIds.set(shopOrderIds.get() + "," + shopOrder.getShopOrderId());
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+// /*
|
|
|
+// * 设置邮费子订单
|
|
|
+// */
|
|
|
+// if (1 == mainOrder.getFreePostFlag()) {
|
|
|
+// //Integer postageOrderId = setPostageOrder(mainOrder, shopOrderIds, orderInfo.size());
|
|
|
+// // 记录子订单编号
|
|
|
+// //shopOrderIds = (StringUtils.isEmpty(shopOrderIds) ? ""+postageOrderId : ","+postageOrderId);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*
|
|
|
+// * 更新主订单的子订单Id信息,如:1000,1002
|
|
|
+// */
|
|
|
+// if (StringUtils.isNotEmpty(shopOrderIds)) {
|
|
|
+// mainOrder.setShopOrderIds(shopOrderIds);
|
|
|
+// //submitMapper.updateShopOrderIds(shopOrderIds, mainOrder.getOrderId());
|
|
|
+// } else {
|
|
|
+// // 设置手动回滚事务
|
|
|
+// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+// return ResponseJson.error("生成子订单异常!", null);
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
@@ -880,7 +957,99 @@ public class SubmitServiceImpl implements SubmitService {
|
|
|
// orderSubmitDao.insertOrderProductLadderPrice(ladderPrice);
|
|
|
// });
|
|
|
// }
|
|
|
-//
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 发票信息
|
|
|
+ */
|
|
|
+ boolean hasInvoiceFlag = false;
|
|
|
+ InvoicePo invoice = new InvoicePo();
|
|
|
+ // 发票类型 0不开发票 1普通发票 2增值税发票
|
|
|
+ if (1== orderUserBo.getInvoiceType() || 2 == orderUserBo.getInvoiceType()){
|
|
|
+ JSONObject orderInvoice = orderUserBo.getOrderInvoice();
|
|
|
+ Integer invoiceType = (Integer) orderInvoice.get("type");
|
|
|
+ String invoiceTitle = (String) orderInvoice.get("invoiceTitle");
|
|
|
+ if (StringUtils.isNotEmpty(invoiceTitle)){
|
|
|
+ return ResponseJson.error("发票抬头信息不正确!", null);
|
|
|
+ }
|
|
|
+ String corporationTaxNum = (String) orderInvoice.get("corporationTaxNum");
|
|
|
+ if (StringUtils.isNotEmpty(corporationTaxNum)){
|
|
|
+ return ResponseJson.error("纳税人识别号信息不正确!", null);
|
|
|
+ }
|
|
|
+ invoice.setType(invoiceType);
|
|
|
+ invoice.setInvoiceTitle(invoiceTitle);
|
|
|
+ invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
+ if (1== orderUserBo.getInvoiceType()) {
|
|
|
+ // 普通发票:发票类型、发票内容(商品明细)、抬头(公司名称)、纳税人识别号[普通发票的公司]
|
|
|
+ String invoiceContent = (String) orderInvoice.get("invoiceContent");
|
|
|
+ Integer invoiceTitleType = (Integer) orderInvoice.get("invoiceTitleType");
|
|
|
+ if (StringUtils.isNotEmpty(invoiceContent) || null == invoiceTitleType) {
|
|
|
+ return ResponseJson.error("发票信息不完整!", null);
|
|
|
+ }
|
|
|
+ invoice.setInvoiceContent(invoiceContent);
|
|
|
+ invoice.setInvoiceTitleType(invoiceTitleType);
|
|
|
+ hasInvoiceFlag = true;
|
|
|
+ }
|
|
|
+ if (2== orderUserBo.getInvoiceType()) {
|
|
|
+ // 增值税发票:发票类型、发票、抬头(公司名称)、纳税人识别号、注册地址、注册电话、开户银行、开户银行账户
|
|
|
+ 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.isNotEmpty(registeredAddress) || StringUtils.isNotEmpty(registeredPhone) || StringUtils.isNotEmpty(openBank) || StringUtils.isNotEmpty(bankAccountNo)) {
|
|
|
+ return ResponseJson.error("发票信息不完整!", null);
|
|
|
+ }
|
|
|
+ invoice.setRegisteredAddress(registeredAddress);
|
|
|
+ invoice.setRegisteredPhone(registeredPhone);
|
|
|
+ invoice.setOpenBank(openBank);
|
|
|
+ invoice.setBankAccountNo(bankAccountNo);
|
|
|
+ hasInvoiceFlag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * 保存订单发票信息
|
|
|
+ */
|
|
|
+ if (hasInvoiceFlag) {
|
|
|
+ // 开发票才保存
|
|
|
+ invoice.setOrderId(mainOrder.getOrderId());
|
|
|
+ // 一个订单只有一条发票信息,删除老的订单增值税信息
|
|
|
+ submitMapper.deleteOrderInvoiceByOrderId(mainOrder.getOrderId());
|
|
|
+ // 保存 订单发票信息
|
|
|
+ submitMapper.insertOrderInvoice(invoice);
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单发票信息(insert[bp_order_invoice])orderId:" + mainOrder.getOrderId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//
|
|
|
// /*
|