|
@@ -2464,6 +2464,995 @@ public class SubmitServiceImpl implements SubmitService {
|
|
return ResponseJson.success();
|
|
return ResponseJson.success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 生成订单 --- 供应商帮机构下单
|
|
|
|
+ *
|
|
|
|
+ * @param submitDto
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<Map<String, Object>> shopGenerateOrder(SubmitDto submitDto) {
|
|
|
|
+ log.info("submitDto===" + submitDto);
|
|
|
|
+
|
|
|
|
+ // 用户组织Id
|
|
|
|
+ JSONArray orderInfo = null;
|
|
|
|
+ JSONObject payInfo = null;
|
|
|
|
+ JSONObject orderInvoice = null;
|
|
|
|
+ try {
|
|
|
|
+ orderInfo = parseArray(submitDto.getOrderInfo());
|
|
|
|
+ payInfo = parseObject(submitDto.getPayInfo());
|
|
|
|
+ orderInvoice = parseObject(submitDto.getOrderInvoice());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("订单参数解析异常try-catch:", e);
|
|
|
|
+ return ResponseJson.error("订单参数解析异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (null == orderInfo || orderInfo.isEmpty()) {
|
|
|
|
+ return ResponseJson.error("订单商品数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (null == payInfo || payInfo.isEmpty()) {
|
|
|
|
+ return ResponseJson.error("订单金额数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (null == orderInvoice || orderInvoice.isEmpty()) {
|
|
|
|
+ return ResponseJson.error("发票信息数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ // 打印参数
|
|
|
|
+ log.info("******************** 【供应商给机构下单】提交订单参数:" + submitDto);
|
|
|
|
+ // 机构用户
|
|
|
|
+ OrderParamBo orderParamBo = new OrderParamBo();
|
|
|
|
+ //订单来源
|
|
|
|
+ orderParamBo.setOrderSource(submitDto.getOrderSource());
|
|
|
|
+ //订单商品
|
|
|
|
+ orderParamBo.setOrderInfo(orderInfo);
|
|
|
|
+ //订单应付总额
|
|
|
|
+ String orderShouldPayFee = (String) payInfo.get("orderShouldPayFee");
|
|
|
|
+ orderParamBo.setOrderShouldPayFee(Double.parseDouble(orderShouldPayFee));
|
|
|
|
+ // 发票类型 0不开发票 1普通发票 2增值税发票
|
|
|
|
+ Integer invoiceType = (Integer) orderInvoice.get("type");
|
|
|
|
+ if (null == invoiceType) {
|
|
|
|
+ return ResponseJson.error("发票类型不能为空!", null);
|
|
|
|
+ }
|
|
|
|
+ orderParamBo.setInvoiceType(invoiceType);
|
|
|
|
+ // 联合丽格*/
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ orderParamBo.setOrderInvoice(invoice);
|
|
|
|
+ }
|
|
|
|
+ // 返佣订单标识 0非返佣订单,1返佣订单,2普通订单含有返佣服务费
|
|
|
|
+ Integer rebateFlag = (Integer) payInfo.get("rebateFlag");
|
|
|
|
+ // rebateflag=2时,有rebateFee
|
|
|
|
+ if (null != rebateFlag && 2 == rebateFlag) {
|
|
|
|
+ String re = (String) payInfo.get("rebateFee");
|
|
|
|
+ Double rebateFee = Double.parseDouble(re);
|
|
|
|
+ orderParamBo.setRebateFee(rebateFee);
|
|
|
|
+ }
|
|
|
|
+ orderParamBo.setRebateFlag(rebateFlag);
|
|
|
|
+ // 售后条款id
|
|
|
|
+ Integer clauseId = (Integer) payInfo.get("clauseId");
|
|
|
|
+ Integer isColdChina = (Integer) payInfo.get("isColdChina");
|
|
|
|
+ orderParamBo.setClauseId(clauseId);
|
|
|
|
+ // 购买类型:(1自主下单,2直接购买 3协销下单)
|
|
|
|
+ orderParamBo.setCartType(submitDto.getCartType());
|
|
|
|
+ // 下单人
|
|
|
|
+ Integer buyUserId = null;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * todo 协销下单, 联合丽格供应商帮机构下的那没有协销信息 协销取固定官方协销
|
|
|
|
+ */
|
|
|
|
+ Integer spUserId = submitMapper.getServiceProviderUserId(1342);
|
|
|
|
+ if (null != spUserId && spUserId > 0) {
|
|
|
|
+ buyUserId = spUserId;
|
|
|
|
+ } else {
|
|
|
|
+ return ResponseJson.error("协销用户异常!", null);
|
|
|
|
+ }
|
|
|
|
+ orderParamBo.setBuyUserId(buyUserId);
|
|
|
|
+ orderParamBo.setServiceProviderId(submitDto.getServiceProviderId());
|
|
|
|
+ orderParamBo.setAddressId(submitDto.getAddressId());
|
|
|
|
+ orderParamBo.setClubCouponId(submitDto.getClubCouponId());
|
|
|
|
+ orderParamBo.setOrderSeen(submitDto.getOrderSeen());
|
|
|
|
+ orderParamBo.setOrderMiniType(submitDto.getOrderMiniType());
|
|
|
|
+ orderParamBo.setIsColdChain(isColdChina);
|
|
|
|
+ /*
|
|
|
|
+ * 保存订单
|
|
|
|
+ */
|
|
|
|
+ return saveShopOrder(orderParamBo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ResponseJson<Map<String, Object>> saveShopOrder(OrderParamBo orderParamBo) {
|
|
|
|
+ // 用户组织Id: 联合丽格
|
|
|
|
+ Integer organizeId = 4;
|
|
|
|
+ log.info("******************** 提交订单逻辑处理 start *******************");
|
|
|
|
+ /**
|
|
|
|
+ * 初始化主订单
|
|
|
|
+ */
|
|
|
|
+ OrderPo mainOrder = new OrderPo();
|
|
|
|
+ // 订单可见度
|
|
|
|
+ mainOrder.setOrderSeen(orderParamBo.getOrderSeen());
|
|
|
|
+ // 订单来源
|
|
|
|
+ mainOrder.setOrderSource(orderParamBo.getOrderSource());
|
|
|
|
+ // 生成订单号 联合丽格订单
|
|
|
|
+ orderParamBo.setOrderSource(9);
|
|
|
|
+ String orderNo = CodeUtil.generateOrderNo(orderParamBo.getOrderSource());
|
|
|
|
+ mainOrder.setOrderNo(orderNo);
|
|
|
|
+ // 用户Id、机构Id 为空; 下单人id 为供应商用户id
|
|
|
|
+ mainOrder.setUserId(null);
|
|
|
|
+ mainOrder.setClubId(null);
|
|
|
|
+ mainOrder.setBuyUserId(orderParamBo.getBuyUserId());
|
|
|
|
+ // 订单提交时间
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
|
|
|
|
+ mainOrder.setOrderTime(curDateStr);
|
|
|
|
+ mainOrder.setUpdateDate(curDateStr);
|
|
|
|
+ // 订单状态 0 有效 其它无效
|
|
|
|
+ mainOrder.setDelFlag(0);
|
|
|
|
+ //协销下单 协销id固定
|
|
|
|
+ mainOrder.setSpId(orderParamBo.getServiceProviderId());
|
|
|
|
+ // 协销订单
|
|
|
|
+ mainOrder.setOrderType(0);
|
|
|
|
+ // 3:协销帮会所下单
|
|
|
|
+ mainOrder.setOrderSubmitType(3);
|
|
|
|
+ // 订单未确认
|
|
|
|
+ mainOrder.setConfirmFlag(0);
|
|
|
|
+ // 联合丽格订单
|
|
|
|
+ mainOrder.setOrderType(3);
|
|
|
|
+ // 抵扣采美豆数量
|
|
|
|
+ mainOrder.setUserBeans(0);
|
|
|
|
+ // 默认可以线上支付:0可以 1不可以
|
|
|
|
+ mainOrder.setOnlinePayFlag(0);
|
|
|
|
+ // 默认订单可以拆分:1可拆分 0不可拆分
|
|
|
|
+ mainOrder.setSplitFlag(1);
|
|
|
|
+ // 默认订单未支付:未支付0 已支付1
|
|
|
|
+ mainOrder.setPayFlag(0);
|
|
|
|
+ // 默认待向买家收款:1待收款、2部分收款、3已收款
|
|
|
|
+ mainOrder.setReceiptStatus(1);
|
|
|
|
+ // 默认未付款供应商:1待付款、2部分付款、3已付款
|
|
|
|
+ mainOrder.setPayStatus(1);
|
|
|
|
+ // 默认有成本
|
|
|
|
+ mainOrder.setZeroCostFlag(0);
|
|
|
|
+ // 发货状态:1待发货、2部分发货、3已发货
|
|
|
|
+ mainOrder.setSendOutStatus(1);
|
|
|
|
+ // 退货退款类型:0未发生退款、1部分退、2全部退
|
|
|
|
+ mainOrder.setRefundType(0);
|
|
|
|
+ // 未确认付款供应商
|
|
|
|
+ mainOrder.setAffirmPaymentFlag(0);
|
|
|
|
+ // 是否开发票
|
|
|
|
+ mainOrder.setInvoiceFlag(orderParamBo.getInvoiceType());
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 整理订单商品信息
|
|
|
|
+ */
|
|
|
|
+ // 商品总数量
|
|
|
|
+ AtomicInteger productCount = new AtomicInteger(0);
|
|
|
|
+ // 赠品数量
|
|
|
|
+ AtomicInteger presentCount = new AtomicInteger(0);
|
|
|
|
+ // 促销赠品数量
|
|
|
|
+ AtomicInteger promotionalGiftsCount = new AtomicInteger(0);
|
|
|
|
+ // 促销满减优惠
|
|
|
|
+ AtomicDouble promotionFullReduction = new AtomicDouble(0);
|
|
|
|
+ // 超级会员优惠
|
|
|
|
+ AtomicDouble svipFullReduction = new AtomicDouble(0);
|
|
|
|
+ // 商品总金额 (商品单价乘以数量,再加上税费)
|
|
|
|
+ AtomicDouble productTotalFee = new AtomicDouble(0);
|
|
|
|
+ // 订单总额(小计金额减去经理折扣后,再加上运费[默认0])
|
|
|
|
+ AtomicDouble payTotalFee = new AtomicDouble(0);
|
|
|
|
+ // 真实支付金额(订单总额减去抵扣的账户余额)
|
|
|
|
+ AtomicDouble payableAmount = new AtomicDouble(0);
|
|
|
|
+ // 余额支付金额
|
|
|
|
+ AtomicDouble balancePayFee = new AtomicDouble(0);
|
|
|
|
+ // 总运费
|
|
|
|
+ AtomicDouble postageFee = new AtomicDouble(0);
|
|
|
|
+ // 统计销量用
|
|
|
|
+ JSONArray salesInfo = new JSONArray();
|
|
|
|
+
|
|
|
|
+ // 二手订单标记(二手订单不能同正常商品下单,只能单个商品立即购买下单)
|
|
|
|
+ boolean secondHandOrderFlag = false;
|
|
|
|
+ // 是否包含活动商品
|
|
|
|
+ boolean hasActProductFlag = false;
|
|
|
|
+ // 是否能线上支付
|
|
|
|
+ AtomicBoolean onlinePay = new AtomicBoolean(true);
|
|
|
|
+ // 用余额线下
|
|
|
|
+ if (null != orderParamBo.getBalancePayFlag() && 1 == orderParamBo.getBalancePayFlag()) {
|
|
|
|
+ onlinePay.set(false);
|
|
|
|
+ }
|
|
|
|
+ //促销活动ids
|
|
|
|
+ List<Integer> promotionsIds = new ArrayList<>();
|
|
|
|
+ // 促销活动信息
|
|
|
|
+ List<PromotionsVo> promotionList = new ArrayList<>();
|
|
|
|
+ // 订单商品列表
|
|
|
|
+ List<OrderProductPo> orderProductList = new ArrayList<>();
|
|
|
|
+ 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();
|
|
|
|
+ for (Object infoObject : orderInfo) {
|
|
|
|
+ JSONObject shopInfo = (JSONObject) infoObject;
|
|
|
|
+ Integer shopId = (Integer) shopInfo.get("shopId");
|
|
|
|
+ String shopNote = (String) shopInfo.get("note");
|
|
|
|
+ String postageString = (String) shopInfo.get("postage");
|
|
|
|
+ Integer postageFlag = (Integer) shopInfo.get("postageFlag");
|
|
|
|
+ Integer isColdChinaShop = (Integer) shopInfo.get("isColdChina");
|
|
|
|
+ if (null == shopId) {
|
|
|
|
+ return ResponseJson.error("供应商数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ JSONArray productArr = (JSONArray) shopInfo.get("productInfo");
|
|
|
|
+ if (null == productArr) {
|
|
|
|
+ return ResponseJson.error("订单商品数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (1252 == shopId) {
|
|
|
|
+ secondHandOrderFlag = true;
|
|
|
|
+ }
|
|
|
|
+ // 运费方式为空: 赠品 包邮
|
|
|
|
+ postageFlag = null == postageFlag ? 0 : postageFlag;
|
|
|
|
+ log.info("postageFlag*****************" + postageFlag);
|
|
|
|
+ // 运费
|
|
|
|
+ Double postage = 0d;
|
|
|
|
+ // 在 运费类型为有运费时 运费生效
|
|
|
|
+ if (null != postageFlag && 1 == postageFlag) {
|
|
|
|
+ postage = Double.parseDouble(postageString);
|
|
|
|
+ }
|
|
|
|
+ // 供应商名称
|
|
|
|
+ String shopName = baseMapper.getShopNameById(shopId);
|
|
|
|
+ /*
|
|
|
|
+ * 初始化子订单
|
|
|
|
+ */
|
|
|
|
+ OrderShopPo shopOrder = new OrderShopPo();
|
|
|
|
+ shopOrder.setPromotionFullReduction(0d);
|
|
|
|
+ shopOrder.setShopId(shopId);
|
|
|
|
+ shopOrder.setShopName(shopName);
|
|
|
|
+ shopOrder.setNote(shopNote);
|
|
|
|
+ // 是否勾选冷链运输费
|
|
|
|
+ shopOrder.setIsColdChina(isColdChinaShop);
|
|
|
|
+ // 供应商帮机构下单没有用户id和机构id 为空
|
|
|
|
+ shopOrder.setUserId(null);
|
|
|
|
+ shopOrder.setClubId(null);
|
|
|
|
+ if (3 == orderParamBo.getCartType()) {
|
|
|
|
+ /**
|
|
|
|
+ * todo 协销订单,在添加保存时子订单的协销Id 暂时保持固定id
|
|
|
|
+ */
|
|
|
|
+ shopOrder.setSpId(1342);
|
|
|
|
+ }
|
|
|
|
+ // 商品总数量
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ // 遍历所有商品
|
|
|
|
+ for (Object productObject : productArr) {
|
|
|
|
+ JSONObject productTemp = (JSONObject) productObject;
|
|
|
|
+ Integer skuId = (Integer) productTemp.get("skuId");
|
|
|
|
+ Integer productNum = (Integer) productTemp.get("productNum");
|
|
|
|
+ Integer presentNum = (Integer) productTemp.get("presentNum");
|
|
|
|
+ Integer productType = (Integer) productTemp.get("productType");
|
|
|
|
+ Double price = (Double) productTemp.get("price");
|
|
|
|
+ productType = (null == productType) ? 0 : productType;
|
|
|
|
+ if (null == skuId) {
|
|
|
|
+ return ResponseJson.error("订单商品数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (null == productNum || productNum == 0) {
|
|
|
|
+ return ResponseJson.error("商品购买数量异常!", null);
|
|
|
|
+ }
|
|
|
|
+ // 统计商品总数量
|
|
|
|
+ productCount.updateAndGet(v -> v + productNum);
|
|
|
|
+ // 赠品数
|
|
|
|
+ presentCount.updateAndGet(v -> v + presentNum);
|
|
|
|
+ // 获取数据库商品信息
|
|
|
|
+ OrderProductPo dbProduct = submitMapper.getProductOrganizeDetails(skuId);
|
|
|
|
+
|
|
|
|
+ OrderProductPo product = new OrderProductPo();
|
|
|
|
+ BeanUtils.copyProperties(dbProduct, product);
|
|
|
|
+ log.info("splitcode-----------------------》" + product.getSplitCode());
|
|
|
|
+ if (null == product) {
|
|
|
|
+ return ResponseJson.error("订单商品不存在!", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 是否二手商品
|
|
|
|
+ if (null != product.getProductCategory() && 2 == product.getProductCategory()) {
|
|
|
|
+ secondHandOrderFlag = true;
|
|
|
|
+ }
|
|
|
|
+ // 是否添加税费,不含税商品 开票需添加税费
|
|
|
|
+ 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);
|
|
|
|
+ product.setImage(image);
|
|
|
|
+ product.setShopName(shopName);
|
|
|
|
+ product.setNum(productNum);
|
|
|
|
+ product.setPresentNum(presentNum);
|
|
|
|
+ product.setProductType(productType);
|
|
|
|
+ product.setSvipPriceFlag(0);
|
|
|
|
+ product.setSvipReduction(0d);
|
|
|
|
+ // 组织信息
|
|
|
|
+ product.setOrganizeId(organizeId);
|
|
|
|
+
|
|
|
|
+ // 超级会员优惠商品详情
|
|
|
|
+ SvipProductPo svipProductPo = submitMapper.getSvipProductDetails(product.getSkuId());
|
|
|
|
+ // 是否以超级会员优惠价格购买
|
|
|
|
+ boolean svipPriceFlag = null != svipProductPo && 1 == svipProductPo.getSvipProductFlag() && orderParamBo.getSvipUserFlag();
|
|
|
|
+
|
|
|
|
+ // 不是赠品,获取商品购买价格(超级会员优惠商品价格>>>活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
|
|
|
|
+ Double productPrice = price;
|
|
|
|
+ Double itemPrice = price;
|
|
|
|
+ Double discountPrice = price;
|
|
|
|
+ // 商品税费
|
|
|
|
+ Double productTax = 0d;
|
|
|
|
+ Double discountTax = 0d;
|
|
|
|
+
|
|
|
|
+ // 计算单价
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ log.info("productTax===" + productTax);
|
|
|
|
+ // 商品价格
|
|
|
|
+ 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();
|
|
|
|
+ // 折后税后单价
|
|
|
|
+ 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();
|
|
|
|
+ // 商品售价还原
|
|
|
|
+ productPrice = itemPrice;
|
|
|
|
+ product.setPrice(productPrice);
|
|
|
|
+ // 折后单价
|
|
|
|
+ product.setDiscountPrice(discountTaxPrice);
|
|
|
|
+ // 折扣率 = 折后单价/机构价
|
|
|
|
+ product.setDiscount(discountRate);
|
|
|
|
+
|
|
|
|
+ // 单个商品的金额
|
|
|
|
+ product.setTotalAmount(productAmount);
|
|
|
|
+ // 单个商品的折后金额
|
|
|
|
+ product.setTotalFee(productFee);
|
|
|
|
+ product.setShouldPayFee(productFee);
|
|
|
|
+ product.setRealProductFee(realProductFee);
|
|
|
|
+ // 税费
|
|
|
|
+ product.setAddedValueTax(discountTax);
|
|
|
|
+ product.setTotalAddedValueTax(taxFee);
|
|
|
|
+ // 销量
|
|
|
|
+ JSONObject salesObject = new JSONObject();
|
|
|
|
+ salesObject.put("productId", product.getProductId());
|
|
|
|
+ salesObject.put("productCount", product.getNum());
|
|
|
|
+ salesInfo.add(salesObject);
|
|
|
|
+
|
|
|
|
+ // 成本价
|
|
|
|
+ Double costPrice = null;
|
|
|
|
+ /**
|
|
|
|
+ * 判断是否选中固定成本价
|
|
|
|
+ * 固定成本、比例成本都需要计算税费
|
|
|
|
+ */
|
|
|
|
+ if (null != product.getCostPrice() && 1 == product.getCostCheckFlag() && product.getCostPrice() >= 0d) {
|
|
|
|
+ // 通过售价*比例得到成本价
|
|
|
|
+ double costTax = 0d;
|
|
|
|
+ if (taxFlag) {
|
|
|
|
+ costTax = MathUtil.div(MathUtil.mul(product.getCostPrice(), product.getTaxRate()), 100, 2).doubleValue();
|
|
|
|
+ }
|
|
|
|
+ costPrice = MathUtil.add(product.getCostPrice(), costTax).doubleValue();
|
|
|
|
+ }
|
|
|
|
+ // 判断是否选中比例成本价
|
|
|
|
+ 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(product.getDiscountPrice(), 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(MathUtil.div(costPrice, MathUtil.div(MathUtil.add(product.getTaxRate(), 100), 100)), 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 = MathUtil.mul(costPrice, MathUtil.add(productNum, presentNum)).doubleValue();
|
|
|
|
+ product.setShopProductAmount(costAmount);
|
|
|
|
+ log.info("product.getShopProductAmount()***" + product.getShopProductAmount());
|
|
|
|
+ //应付供应商(单)=成本价+供应商税费(单)
|
|
|
|
+ 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);
|
|
|
|
+ /*
|
|
|
|
+ * 子订单金额计算
|
|
|
|
+ */
|
|
|
|
+ // 供应商商品数量
|
|
|
|
+ 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());
|
|
|
|
+ // 统计子订单内可参与店铺促销的商品总金额
|
|
|
|
+ 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());
|
|
|
|
+ // 成本 | 佣金比例 商城sku 成本 | 配置比例
|
|
|
|
+ CmOrganizeSkuPo organizeSkuInfo = submitMapper.getOrganizeSkuInfo(skuId, organizeId);
|
|
|
|
+ if (StringUtils.isNotEmpty(organizeSkuInfo.getCostCheckFlag()) && "1".equals(organizeSkuInfo.getCostCheckFlag())) {
|
|
|
|
+ // 固定成本
|
|
|
|
+ if (taxFlag) {
|
|
|
|
+ organizeSkuInfo.setOrganizeCostPrice(MathUtil.add(organizeSkuInfo.getOrganizeCostPrice(), MathUtil.div(MathUtil.mul(organizeSkuInfo.getOrganizeCostPrice(), product.getTaxRate()), 100)).doubleValue());
|
|
|
|
+ organizeSkuInfo.setCmCostPrice(MathUtil.add(organizeSkuInfo.getCmCostPrice(), MathUtil.div(MathUtil.mul(organizeSkuInfo.getCmCostPrice(), product.getTaxRate()), 100)).doubleValue());
|
|
|
|
+ }
|
|
|
|
+ product.setOrganizeCostPrice(organizeSkuInfo.getOrganizeCostPrice());
|
|
|
|
+ product.setCmCostPrice(organizeSkuInfo.getCmCostPrice());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(organizeSkuInfo.getCostCheckFlag()) && "2".equals(organizeSkuInfo.getCostCheckFlag())) {
|
|
|
|
+ // 比例成本
|
|
|
|
+ product.setOrganizeCostPrice(MathUtil.div(MathUtil.mul(product.getPrice(), organizeSkuInfo.getOrganizePercent()), 100).doubleValue());
|
|
|
|
+ product.setCmCostPrice(MathUtil.div(MathUtil.mul(product.getPrice(), organizeSkuInfo.getCmPercent()), 100).doubleValue());
|
|
|
|
+
|
|
|
|
+ product.setCmPercent(organizeSkuInfo.getCmPercent());
|
|
|
|
+ product.setOrganizePercent(organizeSkuInfo.getOrganizePercent());
|
|
|
|
+ product.setShopPercent(organizeSkuInfo.getShopPercent());
|
|
|
|
+ }
|
|
|
|
+ // 加入订单商品列表
|
|
|
|
+ // 商品价格设置为 折后价格
|
|
|
|
+ // product.setPrice(product.getDiscountPrice());
|
|
|
|
+ orderProductList.add(product);
|
|
|
|
+ productIdList.add(product.getProductId().toString());
|
|
|
|
+ skuIdList.add(product.getSkuId().toString());
|
|
|
|
+ }
|
|
|
|
+ // 设置运费
|
|
|
|
+ if (1 == postageFlag && 0 == mainOrder.getUserBeans()) {
|
|
|
|
+ shopOrder.setShopPostFee(postage);
|
|
|
|
+ }
|
|
|
|
+ // 需要支付金额 shouldPayFee +运费
|
|
|
|
+ needPayAmount.set(MathUtil.add(needPayAmount.get(), postage).doubleValue());
|
|
|
|
+ log.info("postage=-***====" + postage);
|
|
|
|
+ // 统计总运费
|
|
|
|
+ postageFee.set(MathUtil.add(postageFee.get(), postage).doubleValue());
|
|
|
|
+ log.info("统计总运费+--+-+-" + postageFee.get());
|
|
|
|
+ Integer count = submitMapper.findSplitResult(productIdList);
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ //有商品无分帐号,走线下
|
|
|
|
+ onlinePay.set(false);
|
|
|
|
+ }
|
|
|
|
+ // 佣金 采美应收
|
|
|
|
+ shopOrder.setBrokerage(brokerage.get());
|
|
|
|
+ // 可退款金额 = 余额抵扣金额
|
|
|
|
+ shopOrder.setCanRefundAmount(needPayAmount.get());
|
|
|
|
+ // 购买商品数
|
|
|
|
+ shopOrder.setItemCount(shopProductCount.get());
|
|
|
|
+ // 超级会员优惠金额
|
|
|
|
+ shopOrder.setSvipShopReduction(svipShopReduction.get());
|
|
|
|
+ // 总价(含税) = totalFee + 运费
|
|
|
|
+ shopOrder.setTotalAmount(MathUtil.add(shopProductFee.get(), postage).doubleValue());
|
|
|
|
+ // 总金额 = 订单商品totalAmount
|
|
|
|
+ shopOrder.setProductAmount(shopAmount.get());
|
|
|
|
+ // 需要支付金额 shouldPayFee +运费
|
|
|
|
+ shopOrder.setNeedPayAmount(needPayAmount.get());
|
|
|
|
+ // 付供应商 商品费=成本价*(购买数量 + 赠品数量)
|
|
|
|
+ shopOrder.setShopProductAmount(shopProductAmount.get());
|
|
|
|
+ // 付给供应商税费
|
|
|
|
+ shopOrder.setShopTaxFee(shopTaxFee.get());
|
|
|
|
+ // 付供应商 = 商品费 + 运费
|
|
|
|
+ // 版本不加 税费
|
|
|
|
+ shopOrder.setShouldPayShopAmount(MathUtil.add(shopProductAmount.get(), postageFee.get()).doubleValue());
|
|
|
|
+ // 付给供应商运费
|
|
|
|
+ // shopOrder.setShopPostFee(0d);
|
|
|
|
+ // 已付供应商金额
|
|
|
|
+ shopOrder.setPayedShopAmount(0d);
|
|
|
|
+ // (付款供应商)付款状态:1待付款、2部分付款、3已付款
|
|
|
|
+ shopOrder.setPayStatus(1);
|
|
|
|
+ // 协销订单
|
|
|
|
+ shopOrder.setOrderType(0);
|
|
|
|
+ // 余额支付标识,0不使用,1使用
|
|
|
|
+ log.info("balance.get()=====" + balance.get());
|
|
|
|
+ // 不使用余额支付
|
|
|
|
+ shopOrder.setUseBalanceFlag(0);
|
|
|
|
+ // 余额抵扣金额
|
|
|
|
+ shopOrder.setAccountAmount(0d);
|
|
|
|
+ log.info("shopOrder.getAccountAmount()====" + shopOrder.getAccountAmount());
|
|
|
|
+ // 运费标记
|
|
|
|
+ shopOrder.setShopPostFlag(postageFlag);
|
|
|
|
+ // 添加到子订单列表
|
|
|
|
+ shopOrderList.add(shopOrder);
|
|
|
|
+ // 统计商品总金额
|
|
|
|
+ productTotalFee.set(MathUtil.add(productTotalFee.get(), shopProductFee.get()).doubleValue());
|
|
|
|
+ }
|
|
|
|
+ if (orderProductList.isEmpty()) {
|
|
|
|
+ return ResponseJson.error("订单商品数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ // 设置是否是二手订单
|
|
|
|
+ mainOrder.setSecondHandOrderFlag(0);
|
|
|
|
+ // 商品总数量
|
|
|
|
+ mainOrder.setProductCount(productCount.get());
|
|
|
|
+ // 赠品数量
|
|
|
|
+ mainOrder.setPresentCount(presentCount.get());
|
|
|
|
+ //促销赠品数量
|
|
|
|
+ mainOrder.setPromotionalGiftsCount(promotionalGiftsCount.get());
|
|
|
|
+ /**
|
|
|
|
+ * 处理优惠券
|
|
|
|
+ */
|
|
|
|
+ Double couponAmount = 0d;
|
|
|
|
+ mainOrder.setCouponAmount(couponAmount);
|
|
|
|
+ // 订单总额 = 商品费 + 运费
|
|
|
|
+ log.info("总运费" + postageFee.get());
|
|
|
|
+ payTotalFee.set(MathUtil.add(productTotalFee.get(), postageFee.get()).doubleValue());
|
|
|
|
+ log.info("payTotalFee.get()=------=-=-====" + payTotalFee.get());
|
|
|
|
+ // 订单总额 -= 优惠券金额
|
|
|
|
+ payTotalFee.set(MathUtil.sub(payTotalFee.get(), couponAmount).doubleValue());
|
|
|
|
+ // 超级会员优惠
|
|
|
|
+ mainOrder.setSvipFullReduction(svipFullReduction.get());
|
|
|
|
+ // 商品总额
|
|
|
|
+ mainOrder.setProductTotalFee(productTotalFee.get());
|
|
|
|
+ mainOrder.setOrderTotalFee(productTotalFee.get());
|
|
|
|
+ // 订单总额(商品金额+运费)-- 冷链运输费
|
|
|
|
+ mainOrder.setPayTotalFee(payTotalFee.get());
|
|
|
|
+ // 订单状态 协销 状态为 待确认
|
|
|
|
+ mainOrder.setStatus(0);
|
|
|
|
+ // 余额支付金额
|
|
|
|
+ mainOrder.setBalancePayFee(balancePayFee.get());
|
|
|
|
+ // 实际支付金额(商品金额+运费-余额抵扣)
|
|
|
|
+ mainOrder.setPayableAmount(payableAmount.get());
|
|
|
|
+
|
|
|
|
+ // 是否返佣订单
|
|
|
|
+ Integer rebateFlag = (null == orderParamBo.getRebateFlag() ? 0 : orderParamBo.getRebateFlag());
|
|
|
|
+ mainOrder.setRebateFlag(rebateFlag);
|
|
|
|
+ if (2 == rebateFlag) {
|
|
|
|
+ mainOrder.setRebateFee(orderParamBo.getRebateFee());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("订单总额" + payTotalFee.get());
|
|
|
|
+ // 判断前端传入orderShouldPayFee订单应付金额,和后台计算应付金额对比
|
|
|
|
+ log.info("【提交订单】>>>>>后台计算payableAmount:" + payableAmount.get() + " ,前端传入orderShouldPayFee:" + orderParamBo.getOrderShouldPayFee());
|
|
|
|
+ int compare = MathUtil.compare(orderParamBo.getOrderShouldPayFee(), payableAmount.get());
|
|
|
|
+ if (compare != 0) {
|
|
|
|
+ // 设置手动回滚事务
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("订单付款金额不正确!", null);
|
|
|
|
+ }
|
|
|
|
+ // 售后条款
|
|
|
|
+ Integer clauseId = orderParamBo.getClauseId();
|
|
|
|
+ String clauseName = null;
|
|
|
|
+ if (null != clauseId && clauseId > 0) {
|
|
|
|
+ clauseName = submitMapper.getClauseNameById(clauseId);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(clauseName)) {
|
|
|
|
+ mainOrder.setClauseId(clauseId);
|
|
|
|
+ mainOrder.setClauseName(clauseName);
|
|
|
|
+ } else {
|
|
|
|
+ mainOrder.setClauseId(1);
|
|
|
|
+ mainOrder.setClauseName("无条款");
|
|
|
|
+ }
|
|
|
|
+ // 设置组织Id
|
|
|
|
+ mainOrder.setOrganizeId(organizeId);
|
|
|
|
+ if (null == mainOrder.getUserId()) {
|
|
|
|
+ // 设置手动回滚事务
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("用户Id为空!", null);
|
|
|
|
+ }
|
|
|
|
+ // 根据用户 Id 查询机构 Id
|
|
|
|
+ Integer clubId = submitMapper.getClubId(mainOrder.getUserId());
|
|
|
|
+ mainOrder.setClubId(clubId);
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存主订单数据,返回订单Id
|
|
|
|
+ */
|
|
|
|
+ submitMapper.insertMainOrder(mainOrder);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增主订单(insert[cm_order])orderId:" + mainOrder.getOrderId());
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 线上单分摊优惠
|
|
|
|
+ */
|
|
|
|
+ if (presentCount.get() > 0) {
|
|
|
|
+ //有赠品不能线上,赠品成本无法分账
|
|
|
|
+ onlinePay.set(false);
|
|
|
|
+ }
|
|
|
|
+ if (onlinePay.get()) {
|
|
|
|
+// //在店铺满减算完之后重新根据商品的splitCode排shopOrderList
|
|
|
|
+ List<OrderShopPo> shops = submitMapper.findShops(productIdList);
|
|
|
|
+// //子订单分多子订单,满减分摊到原子订单分开的子订单,无满减重算佣金/应付
|
|
|
|
+// //重组订单
|
|
|
|
+// shopOrderList = findSplitShopOrder(orderProductList, shopOrderList, shops, orderParamBo);
|
|
|
|
+ for (OrderShopPo shop : shops) {
|
|
|
|
+ shopOrderList.forEach(s -> {
|
|
|
|
+ if (s.getShopId().equals(shop.getShopId())) {
|
|
|
|
+ s.setSplitCode(shop.getSplitCode());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // 按分摊前的佣金排序
|
|
|
|
+ shopOrderList.sort((o1, o2) -> o2.getOldBrokerage().compareTo(o1.getOldBrokerage()));
|
|
|
|
+ // 前面子订单的分摊优惠总和
|
|
|
|
+ /**
|
|
|
|
+ * todo 当前版本为子订单下单,且优惠仅存在供应商优惠,优惠金额应从供应商成本扣除,暂时去除均摊优惠逻辑
|
|
|
|
+ */
|
|
|
|
+ //无优惠金额
|
|
|
|
+ shopOrderList.forEach(so -> {
|
|
|
|
+// //不包含优惠的真实支付金额=子订单应付?
|
|
|
|
+// double realPay = so.getNeedPayAmount();
|
|
|
|
+// so.setRealPay(realPay);
|
|
|
|
+// so.setEachDiscount(0d);
|
|
|
|
+ double bro = so.getBrokerage();
|
|
|
|
+// so.setRealPay(realPay);
|
|
|
|
+// so.setEachDiscount(0d);
|
|
|
|
+ //成本>实付不能线上
|
|
|
|
+ if (bro < 0) {
|
|
|
|
+ onlinePay.set(false);
|
|
|
|
+ } else {
|
|
|
|
+ double WXCharge = MathUtil.mul(so.getRealPay(), 0.0065, 2).doubleValue();
|
|
|
|
+ double QuickCharge = MathUtil.mul(so.getRealPay(), 0.006, 2).doubleValue();
|
|
|
|
+ double AliCharge = MathUtil.mul(so.getRealPay(), 0.0025, 2).doubleValue();
|
|
|
|
+ double B2CCharge = MathUtil.mul(so.getRealPay(), 0.002, 2).doubleValue();
|
|
|
|
+ //佣金和手续费比较,佣金>手续费则可以走当前支付渠道
|
|
|
|
+ //支持子订单佣金小于最小手续费时,也能进行线上支付,此时不限制支付方式(佣金大于最大手续费或小于最小手续费支持全渠道付款)
|
|
|
|
+ String payWays = "";
|
|
|
|
+ payWays += bro >= WXCharge ? "1" : "";
|
|
|
|
+ payWays += bro >= AliCharge ? ",2" : "";
|
|
|
|
+ payWays += bro >= B2CCharge ? ",3" : "";
|
|
|
|
+ payWays += bro >= 10 ? ",4" : "";
|
|
|
|
+ payWays += bro >= QuickCharge ? ",5" : "";
|
|
|
|
+ //小于所有的情况下线下补手续费,开放所有渠道
|
|
|
|
+ if ("".equals(payWays)) {
|
|
|
|
+ payWays = "1,2,3,4,5";
|
|
|
|
+ }
|
|
|
|
+ so.setOnlinePayWays(payWays);
|
|
|
|
+ }
|
|
|
|
+ log.info("线上重排子订单--------------------------" + so);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ * 整理 子订单信息cm_shop_order
|
|
|
|
+ */
|
|
|
|
+ AtomicReference<String> shopOrderIds = new AtomicReference<>();
|
|
|
|
+ AtomicInteger shopOrderIndex = new AtomicInteger(1);
|
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
|
+ shopOrder.setOrderId(mainOrder.getOrderId());
|
|
|
|
+ shopOrder.setOrderNo(mainOrder.getOrderNo());
|
|
|
|
+ shopOrder.setOrderTime(mainOrder.getOrderTime());
|
|
|
|
+ shopOrder.setOrderSubmitType(mainOrder.getOrderSubmitType());
|
|
|
|
+ // 子订单状态
|
|
|
|
+ if (0 == mainOrder.getStatus()) {
|
|
|
|
+ shopOrder.setShopStatus(0);
|
|
|
|
+ } else {
|
|
|
|
+ shopOrder.setShopStatus(1);
|
|
|
|
+ // 普通订单 订单默认已确认
|
|
|
|
+ shopOrder.setConfirmTime(curDateStr);
|
|
|
|
+ }
|
|
|
|
+ // 生成子订单编号
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 设置组织Id
|
|
|
|
+ shopOrder.setOrganizeId(organizeId);
|
|
|
|
+ // 分帐号
|
|
|
|
+ if (0 != organizeId) {
|
|
|
|
+ // 联合丽格
|
|
|
|
+ shopOrder.setRealPay(shopOrder.getNeedPayAmount());
|
|
|
|
+ }
|
|
|
|
+ shopOrder.setClubId(clubId);
|
|
|
|
+ /*
|
|
|
|
+ * 保存子订单
|
|
|
|
+ */
|
|
|
|
+ log.info("shopOrderStatus======" + shopOrder.getShopStatus());
|
|
|
|
+ submitMapper.insertShopOrder(shopOrder);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增子订单(insert[cm_shop_order])shopOrderId:" + shopOrder.getShopOrderId() + ",orderId:" + mainOrder.getOrderId());
|
|
|
|
+ // 收集子订单Id字符串
|
|
|
|
+ if (StringUtils.isEmpty(shopOrderIds.get())) {
|
|
|
|
+ shopOrderIds.set(shopOrder.getShopOrderId().toString());
|
|
|
|
+ } else {
|
|
|
|
+ shopOrderIds.set(shopOrderIds.get() + "," + shopOrder.getShopOrderId());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 订单商品分子订单cm_order_product
|
|
|
|
+ */
|
|
|
|
+ for (OrderProductPo orderProduct : orderProductList) {
|
|
|
|
+ // 设置商品订单Id
|
|
|
|
+ orderProduct.setOrderId(mainOrder.getOrderId());
|
|
|
|
+ orderProduct.setOrderNo(mainOrder.getOrderNo());
|
|
|
|
+ // 设置商品子订单Id
|
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
|
+ //能线上的一定有分账号,按分账号分子订单
|
|
|
|
+ if (onlinePay.get()) {
|
|
|
|
+ //可以线上的情况下,子订单的商户号和商品的一致分到一个子订单
|
|
|
|
+ if (orderProduct.getShopId().equals(shopOrder.getShopId()) && orderProduct.getSplitCode().equals(shopOrder.getSplitCode())) {
|
|
|
|
+ orderProduct.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
|
+ orderProduct.setShopOrderNo(shopOrder.getShopOrderNo());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (orderProduct.getShopId().equals(shopOrder.getShopId())) {
|
|
|
|
+ orderProduct.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
|
+ orderProduct.setShopOrderNo(shopOrder.getShopOrderNo());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 设置订单商品促销Id
|
|
|
|
+ promotionList.forEach(promotions -> {
|
|
|
|
+ if (promotions.getPromotionsId().equals(orderProduct.getOrderPromotionsId())) {
|
|
|
|
+ orderProduct.setOrderPromotionsId(promotions.getId());
|
|
|
|
+ orderProduct.setActProduct(1);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ orderProduct.setOrganizeId(organizeId);
|
|
|
|
+ /*
|
|
|
|
+ * 保存 订单商品
|
|
|
|
+ */
|
|
|
|
+ submitMapper.insertOrderProduct(orderProduct);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单商品(insert[cm_order_product])OrderProductId:" + orderProduct.getOrderProductId() + ",orderId:" + mainOrder.getOrderId());
|
|
|
|
+ /*
|
|
|
|
+ * 保存 订单阶梯价格
|
|
|
|
+ */
|
|
|
|
+ if (orderProduct.getLadderPriceFlag() == 1) {
|
|
|
|
+ // 使用阶梯价格的订单商品保存下单时的阶梯价格列表
|
|
|
|
+ List<LadderPriceVo> ladderPrices = orderProduct.getLadderPrices();
|
|
|
|
+ if (null != ladderPrices && ladderPrices.size() > 0) {
|
|
|
|
+ ladderPrices.forEach(ladderPriceVo -> {
|
|
|
|
+ ladderPriceVo.setOrderProductId(orderProduct.getOrderProductId());
|
|
|
|
+ ladderPriceVo.setCreateDate(date);
|
|
|
|
+ submitMapper.insertLadderPrices(ladderPriceVo);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单阶梯价格(insert[order_product_ladder_price])id:" + ladderPriceVo.getId() + ",orderId:" + mainOrder.getOrderId());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ * 机构用户 写入价格库
|
|
|
|
+ */
|
|
|
|
+ if (3 != orderParamBo.getCartType() && 1 != orderProduct.getSvipPriceFlag() && 0 == organizeId) {
|
|
|
|
+ // 写入复购价格库
|
|
|
|
+ productService.savePurchasePrice(mainOrder, orderProduct, secondHandOrderFlag, "【提交订单】");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新主订单的子订单Id信息,如:1000,1002
|
|
|
|
+ */
|
|
|
|
+ if (StringUtils.isNotEmpty(shopOrderIds.get())) {
|
|
|
|
+ mainOrder.setShopOrderIds(shopOrderIds.get());
|
|
|
|
+ submitMapper.updateShopOrderIds(shopOrderIds.get(), mainOrder.getOrderId());
|
|
|
|
+ } else {
|
|
|
|
+ // 设置手动回滚事务
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("生成子订单异常!", null);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 更新主订单线上支付按钮
|
|
|
|
+ * onlinePayFlag:0可以 1不可以
|
|
|
|
+ */
|
|
|
|
+ Integer onlinePayFlag = onlinePay.get() ? 0 : 1;
|
|
|
|
+ // 组织 是否线上判定
|
|
|
|
+ boolean item = true;
|
|
|
|
+ if (0 != organizeId) {
|
|
|
|
+ // 子订单分帐号
|
|
|
|
+ for (OrderShopPo shopOrder : shopOrderList) {
|
|
|
|
+ if (StringUtils.isEmpty(shopOrder.getSplitCode()) || StringUtils.isBlank(shopOrder.getSplitCode())) {
|
|
|
|
+ item = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (item) {
|
|
|
|
+ onlinePayFlag = 0;
|
|
|
|
+ } else {
|
|
|
|
+ onlinePayFlag = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ submitMapper.updateOnlinePayFlag(onlinePayFlag, mainOrder.getOrderId());
|
|
|
|
+ // 更新子订单线上支付
|
|
|
|
+ if (0 != organizeId && item) {
|
|
|
|
+ String onlinePayWays = "1,2,3,4,5";
|
|
|
|
+ submitMapper.updateOnlinePayWays(onlinePayWays, mainOrder.getOrderId());
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ * todo 保存 订单收货用户信息 下单时没有用户信息
|
|
|
|
+ */
|
|
|
|
+ AddressVo address = submitMapper.getAddressDetailById(orderParamBo.getAddressId());
|
|
|
|
+ if (null != address) {
|
|
|
|
+ String userName = baseMapper.getUserNameByUserId(mainOrder.getUserId());
|
|
|
|
+ //保存地址信息
|
|
|
|
+ OrderUserInfoPo userInfo = new OrderUserInfoPo();
|
|
|
|
+ userInfo.setOrderId(mainOrder.getOrderId());
|
|
|
|
+ userInfo.setClubId(mainOrder.getClubId());
|
|
|
|
+ userInfo.setUserId(mainOrder.getUserId());
|
|
|
|
+ userInfo.setName(userName);
|
|
|
|
+ userInfo.setReceiver(address.getReceiver());
|
|
|
|
+ userInfo.setMobile(address.getMobile());
|
|
|
|
+ userInfo.setTownId(address.getTownId());
|
|
|
|
+ userInfo.setProvince(address.getProvince());
|
|
|
|
+ userInfo.setCity(address.getCity());
|
|
|
|
+ userInfo.setTown(address.getTown());
|
|
|
|
+ userInfo.setAddress(address.getAddress());
|
|
|
|
+ // 保存 订单收货用户信息
|
|
|
|
+ submitMapper.insertOrderUserInfo(userInfo);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单用户地址(insert[bp_order_userinfo])orderId:" + mainOrder.getOrderId());
|
|
|
|
+ } else {
|
|
|
|
+ //设置手动回滚事务
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("订单地址异常!", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 保存发票信息
|
|
|
|
+ */
|
|
|
|
+ if (1 == orderParamBo.getInvoiceType() || 2 == orderParamBo.getInvoiceType()) {
|
|
|
|
+ /*
|
|
|
|
+ * 更新订单增值税发票
|
|
|
|
+ */
|
|
|
|
+ InvoicePo orderInvoice = submitMapper.getOrderInvoice(mainOrder.getOrderId());
|
|
|
|
+ if (null != orderInvoice && null != orderInvoice.getId()) {
|
|
|
|
+ // 更新
|
|
|
|
+ BeanUtils.copyProperties(orderParamBo.getOrderInvoice(), orderInvoice);
|
|
|
|
+ orderInvoice.setOrderId(mainOrder.getOrderId());
|
|
|
|
+ submitMapper.updateOrderInvoice(orderInvoice);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>更新订单发票信息(update[bp_order_invoice])orderId:" + mainOrder.getOrderId());
|
|
|
|
+ } else {
|
|
|
|
+ // 新增
|
|
|
|
+ orderInvoice = new InvoicePo();
|
|
|
|
+ BeanUtils.copyProperties(orderParamBo.getOrderInvoice(), orderInvoice);
|
|
|
|
+ orderInvoice.setOrderId(mainOrder.getOrderId());
|
|
|
|
+ // 保存 订单发票信息
|
|
|
|
+ submitMapper.insertOrderInvoice(orderInvoice);
|
|
|
|
+ log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存订单发票信息(insert[bp_order_invoice])orderId:" + mainOrder.getOrderId());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ log.info("******************** 供应商给机构下单 -- 提交订单逻辑处理 end *******************");
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ * 构造返回参数
|
|
|
|
+ */
|
|
|
|
+ Map<String, Object> info = new HashMap<>();
|
|
|
|
+ info.put("orderId", mainOrder.getOrderId());
|
|
|
|
+ info.put("orderNo", mainOrder.getOrderNo());
|
|
|
|
+ info.put("orderMark", "#" + mainOrder.getOrderId() + "#");
|
|
|
|
+ //应付订单金额
|
|
|
|
+ info.put("payTotalFee", mainOrder.getPayTotalFee());
|
|
|
|
+ //线上线下按钮onlinePayFlag:0线上,1线下
|
|
|
|
+ info.put("onlinePayFlag", onlinePayFlag);
|
|
|
|
+ //真实需要付款金额
|
|
|
|
+ info.put("payableAmount", mainOrder.getPayableAmount());
|
|
|
|
+ //2提交成功(未支付)
|
|
|
|
+ info.put("code", 2);
|
|
|
|
+ info.put("msg", "提交成功但未支付!");
|
|
|
|
+ // 统计销量
|
|
|
|
+ remoteCallService.productSaleUpdate(salesInfo.toString());
|
|
|
|
+ // 返回结果
|
|
|
|
+ return ResponseJson.success("操作成功!", info);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|