|
@@ -9,9 +9,11 @@ import com.caimei.model.enumerate.ReceivablesType;
|
|
|
import com.caimei.model.po.*;
|
|
|
import com.caimei.model.vo.*;
|
|
|
import com.caimei.service.OrderService;
|
|
|
+import com.caimei.service.OrderSubmitService;
|
|
|
import com.caimei.utils.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -40,416 +42,13 @@ public class OrderServiceImpl implements OrderService {
|
|
|
@Value("${caimei.oldapi}")
|
|
|
private String domain;
|
|
|
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public ResponseJson orderSubmit(String cmAccount, String data) {
|
|
|
- // 获取组织信息
|
|
|
- CmApiOrganizePo organizePo = organizeMapper.getOrganizeByCmAccount(cmAccount);
|
|
|
- if (null == organizePo) {
|
|
|
- return ResponseJson.error("参数异常,用户不存在");
|
|
|
- }
|
|
|
- // 获得用户Id
|
|
|
- Integer userId = organizePo.getUserId();
|
|
|
- JSONObject orderInfo = null;
|
|
|
- try {
|
|
|
- // 使用组织对应的公钥解密,获得订单数据
|
|
|
- orderInfo = KeyUtils.decryptDataPublic(data, organizePo.getPublicKey());
|
|
|
- // 私钥验签
|
|
|
- String preSign = orderInfo.getString("sign");
|
|
|
- orderInfo.remove("sign");
|
|
|
- String sufSign = KeyUtils.buildSign(orderInfo, organizePo.getPrivateKey());
|
|
|
- if (!preSign.equals(sufSign)) {
|
|
|
- return ResponseJson.error("验签失败");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return ResponseJson.error("解密失败");
|
|
|
- }
|
|
|
- String apiOrganizeOrderId;
|
|
|
- Map<String, Object> addressInfo;
|
|
|
- Map<String, Object> productInfo;
|
|
|
- BigDecimal orderShouldPayFee;
|
|
|
- Map<String, Object> invoiceInfo;
|
|
|
- String notifyUrl;
|
|
|
- try {
|
|
|
- addressInfo = orderInfo.getJSONObject("addressInfo");
|
|
|
- if (null == addressInfo) {
|
|
|
- return ResponseJson.error("地址数据异常");
|
|
|
- }
|
|
|
- // 组织订单Id,由组织自行生成,必须唯一
|
|
|
- apiOrganizeOrderId = orderInfo.getString("orderId");
|
|
|
- // 验证组织订单Id是否唯一
|
|
|
- Integer countByOrderId = orderMapper.getCountByOrderId(userId, apiOrganizeOrderId);
|
|
|
- if (null != countByOrderId && countByOrderId > 0) {
|
|
|
- return ResponseJson.error("订单Id已存在,请勿重复提交");
|
|
|
- }
|
|
|
- productInfo = orderInfo.getJSONObject("productInfo");
|
|
|
- if (null == productInfo) {
|
|
|
- return ResponseJson.error("订单商品数据异常");
|
|
|
- }
|
|
|
- orderShouldPayFee = orderInfo.getBigDecimal("orderShouldPayFee");
|
|
|
- if (null == orderShouldPayFee) {
|
|
|
- return ResponseJson.error("订单金额数据异常");
|
|
|
- }
|
|
|
- invoiceInfo = orderInfo.getJSONObject("invoiceInfo");
|
|
|
- if (null == invoiceInfo) {
|
|
|
- return ResponseJson.error("订单发票数据异常");
|
|
|
- }
|
|
|
- notifyUrl = orderInfo.getString("notifyUrl");
|
|
|
- if (StringUtils.isNotEmpty(notifyUrl) && !notifyUrl.equals(organizePo.getNotifyUrl())) {
|
|
|
- //更新回调地址
|
|
|
- orderMapper.updateNotifyUrl(organizePo.getOrganizeId(), notifyUrl);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- return ResponseJson.error("数据异常");
|
|
|
- }
|
|
|
- log.info("******************** 提交订单逻辑处理 start *******************");
|
|
|
- //机构用户
|
|
|
- UserPo user = orderMapper.getUserByUserId(userId);
|
|
|
- if (null == user) {
|
|
|
- return ResponseJson.error("用户信息异常");
|
|
|
- }
|
|
|
- // 商品总数量
|
|
|
- Integer productCount = 0;
|
|
|
- // 赠品数量
|
|
|
- Integer presentCount = 0;
|
|
|
- //促销赠品数量
|
|
|
- Integer promotionalGiftsCount = 0;
|
|
|
- // 商品总金额 (商品单价乘以数量,再加上税费[默认0])
|
|
|
- BigDecimal productTotalFee = BigDecimal.ZERO;
|
|
|
- // 小计金额(商品折后单价乘以数量,再加上税费[默认0])
|
|
|
- BigDecimal orderTotalFee = BigDecimal.ZERO;
|
|
|
- // 订单总额(小计金额减去经理折扣后,再加上运费[默认0])
|
|
|
- BigDecimal payTotalFee = BigDecimal.ZERO;
|
|
|
- // 真实支付金额(订单总额减去抵扣的账户余额)
|
|
|
- BigDecimal payableAmount = BigDecimal.ZERO;
|
|
|
- /*
|
|
|
- * 发票信息获取
|
|
|
- */
|
|
|
- boolean invoiceFlag = false;
|
|
|
- BpOrderInvoicePo invoice = new BpOrderInvoicePo();
|
|
|
- Integer invoiceType = (Integer) invoiceInfo.get("type");
|
|
|
- if (null == invoiceType) {
|
|
|
- return ResponseJson.error("发票类型不能为空");
|
|
|
- } else {
|
|
|
- invoice.setType(invoiceType.longValue());
|
|
|
- if (0 != invoiceType) {
|
|
|
- // 发票类型 0不开发票 1普通发票 2增值税发票
|
|
|
- invoiceFlag = true;
|
|
|
- if (setInvoiceParam(invoiceInfo, invoice, invoiceType)) {
|
|
|
- return ResponseJson.error("发票信息不完整");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 获取地址信息
|
|
|
- String provinceName = (String) addressInfo.get("provinceName");
|
|
|
- String cityName = (String) addressInfo.get("cityName");
|
|
|
- String townName = (String) addressInfo.get("townName");
|
|
|
- String receiveMan = (String) addressInfo.get("receiveMan");
|
|
|
- String mobile = (String) addressInfo.get("mobile");
|
|
|
- String addressDetail = (String) addressInfo.get("addressDetail");
|
|
|
- if (StringUtils.isEmpty(provinceName) || StringUtils.isEmpty(cityName) || StringUtils.isEmpty(townName) || StringUtils.isEmpty(receiveMan) || StringUtils.isEmpty(mobile)) {
|
|
|
- return ResponseJson.error("地址信息不完整");
|
|
|
- }
|
|
|
- Integer provinceId = orderMapper.getProvinceId(provinceName);
|
|
|
- Integer cityId = orderMapper.getCityId(cityName);
|
|
|
- Integer townId = orderMapper.getTownId(townName);
|
|
|
- if (null == provinceId || null == cityId || null == townId) {
|
|
|
- return ResponseJson.error("地址信息异常");
|
|
|
- }
|
|
|
- /*
|
|
|
- * 初始化主订单参数
|
|
|
- */
|
|
|
- CmOrderPo order = new CmOrderPo();
|
|
|
- String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
|
|
|
- // 订单号
|
|
|
- String orderNo = OrderNoUtils.getOrderNo("D");
|
|
|
- order.setOrderNo(orderNo);
|
|
|
- order.setApiOrganizeOrderId(apiOrganizeOrderId);
|
|
|
- // 运营人员下单
|
|
|
- order.setBuyUserID(user.getUserID());
|
|
|
- order.setOrderType(1);
|
|
|
- order.setOrderSubmitType(2);
|
|
|
- order.setConfirmFlag("2");
|
|
|
- order.setUserID(user.getUserID().longValue());
|
|
|
- // 机构ID
|
|
|
- order.setClubID(user.getClubID().longValue());
|
|
|
- // 订单来源
|
|
|
- order.setOrderSource("7");
|
|
|
- order.setOrganizeID(0);
|
|
|
- order.setUpdateDate(curDateStr);
|
|
|
- order.setPayFlag("0");
|
|
|
- order.setCooFreeFlag("0");
|
|
|
- order.setCooFreeAmount(BigDecimal.ZERO);
|
|
|
- order.setCooFreeRate(0);
|
|
|
- order.setOnlinePayFlag("0");
|
|
|
- order.setPreferential(BigDecimal.ZERO);
|
|
|
- order.setDiscountFee(BigDecimal.ZERO);
|
|
|
- // 订单提交时间
|
|
|
- order.setOrderTime(curDateStr);
|
|
|
- // 默认订单可以拆分
|
|
|
- order.setSplitFlag("1");
|
|
|
- // 发票类型
|
|
|
- order.setInvoiceFlag(invoiceType.toString());
|
|
|
- order.setReceiptStatus("1");
|
|
|
- order.setPayStatus("1");
|
|
|
- order.setZeroCostFlag(0);
|
|
|
- order.setSendOutStatus("1");
|
|
|
- order.setRefundType("0");
|
|
|
- // 是否包含活动商品(受订单未支付自动关闭时间影响) 0 否 1 是
|
|
|
- order.setHasActProduct("0");
|
|
|
- // 订单状态 0 有效 其它无效
|
|
|
- order.setDelFlag("0");
|
|
|
- // 是否确认付款供应商
|
|
|
- order.setAffirmPaymentFlag("0");
|
|
|
- /*
|
|
|
- 订单商品
|
|
|
- */
|
|
|
- List<CmOrderProductPo> orderProductList = new ArrayList<>();
|
|
|
- // 收集供应商ID列表
|
|
|
- List<Integer> shopIdList = new ArrayList<>();
|
|
|
- for (Map.Entry<String, Object> product : productInfo.entrySet()) {
|
|
|
- String productId = product.getKey();
|
|
|
- Integer productNum = (Integer)product.getValue();
|
|
|
- // 统计商品数量
|
|
|
- productCount += productNum;
|
|
|
- // 获取商品信息
|
|
|
- CmApiOrganizeProductPo organizeProduct = productMapper.getProductByProductId(productId);
|
|
|
- if (productNum < organizeProduct.getMinBuyNumber()) {
|
|
|
- return ResponseJson.error("商品购买数量不能少于最小起订量");
|
|
|
- }
|
|
|
- if (null == organizeProduct) {
|
|
|
- return ResponseJson.error("订单商品数据异常");
|
|
|
- }
|
|
|
- if (null == productNum || productNum == 0) {
|
|
|
- return ResponseJson.error("商品购买数量异常");
|
|
|
- }
|
|
|
- // 获取商品购买价格(活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
|
|
|
- BigDecimal productPrice = organizeProduct.getPrice();
|
|
|
- // 成本价
|
|
|
- BigDecimal costPrice = BigDecimal.ZERO;
|
|
|
- // 机构税费(单)
|
|
|
- BigDecimal addedValueTax = new BigDecimal(0);
|
|
|
- int priceType = 0;
|
|
|
- // 活动状态
|
|
|
- organizeProduct.setActStatus(0);
|
|
|
- if (1 == organizeProduct.getLadderPriceFlag()) {
|
|
|
- // 启用了阶梯价格
|
|
|
- List<LadderPriceVo> ladderPriceList = productMapper.getLadderPriceByProductId(organizeProduct.getId());
|
|
|
- // 判断阶梯价格的购买数量校验
|
|
|
- long minBuyNumber = null != ladderPriceList.get(0) ? ladderPriceList.get(0).getBuyNum() : 0L;
|
|
|
- if (productNum < minBuyNumber) {
|
|
|
- return ResponseJson.error("商品购买量低于最小起订量");
|
|
|
- }
|
|
|
- //根据商品购买数量获取商品对应阶梯价格
|
|
|
- for (LadderPriceVo ladderPrice : ladderPriceList) {
|
|
|
- if (productNum >= ladderPrice.getBuyNum()) {
|
|
|
- productPrice = ladderPrice.getBuyPrice();
|
|
|
- }
|
|
|
- }
|
|
|
- organizeProduct.setActStatus(2);
|
|
|
- priceType = 2;
|
|
|
- }
|
|
|
- //不含税可开票商品计算税费
|
|
|
- boolean addTaxFlag = 0 == organizeProduct.getIncludedTax() && (1 == organizeProduct.getInvoiceType() || 2 == organizeProduct.getInvoiceType());
|
|
|
- if (addTaxFlag) {
|
|
|
- addedValueTax = MathUtil.div(MathUtil.mul(productPrice, organizeProduct.getClubTaxPoint()), BigDecimal.valueOf(100));
|
|
|
- productPrice = MathUtil.add(productPrice, addedValueTax);
|
|
|
- }
|
|
|
- if (MathUtil.compare(productPrice, BigDecimal.ZERO) == 0) {
|
|
|
- return ResponseJson.error("商品购买价格不能为0");
|
|
|
- }
|
|
|
- // 单个商品的金额
|
|
|
- BigDecimal productFee = MathUtil.mul(productPrice, productNum);
|
|
|
- // 统计商品总金额
|
|
|
- productTotalFee = MathUtil.add(productTotalFee, productFee);
|
|
|
- // 判断是否选中固定成本价
|
|
|
- if (MathUtil.compare(organizeProduct.getCostPrice(), 0) > 0 && 1 == organizeProduct.getCostType()) {
|
|
|
- costPrice = organizeProduct.getCostPrice();
|
|
|
- }
|
|
|
- // 判断是否选中比例成本价
|
|
|
- if (MathUtil.compare(organizeProduct.getCostProportional(), 0) > 0 && 2 == organizeProduct.getCostType()) {
|
|
|
- // 通过售价*比例得到成本价
|
|
|
- costPrice = BigDecimal.valueOf(MathUtil.div(MathUtil.mul(productPrice, organizeProduct.getCostProportional()), 100).floatValue());
|
|
|
- }
|
|
|
- organizeProduct.setCostPrice(costPrice);
|
|
|
- /*
|
|
|
- * 整理订单商品数据
|
|
|
- */
|
|
|
- CmOrderProductPo orderProduct = setOrderProduct(productNum, organizeProduct, productPrice, priceType, 0, addedValueTax);
|
|
|
- // 加入订单商品列表
|
|
|
- orderProductList.add(orderProduct);
|
|
|
- // 保存供应商id
|
|
|
- if (!shopIdList.contains(orderProduct.getShopID().intValue())) {
|
|
|
- shopIdList.add(orderProduct.getShopID().intValue());
|
|
|
- }
|
|
|
- }
|
|
|
- // 设置是否是二手订单
|
|
|
- order.setSecondHandOrderFlag("0");
|
|
|
- order.setPromotionFullReduction(BigDecimal.ZERO);
|
|
|
- // 商品总数量
|
|
|
- order.setProductCount(productCount);
|
|
|
- // 赠品数量
|
|
|
- order.setPresentCount(0);
|
|
|
- //促销赠品数量
|
|
|
- order.setPromotionalGiftsCount(0);
|
|
|
- // 0包邮 -1到付 1 有运费
|
|
|
- order.setFreePostFlag("-1");
|
|
|
- order.setFreight(BigDecimal.ZERO);
|
|
|
- // 商品总额
|
|
|
- order.setProductTotalFee(productTotalFee);
|
|
|
- // 订单总额(商品金额+运费)
|
|
|
- payTotalFee = productTotalFee;
|
|
|
- orderTotalFee = productTotalFee;
|
|
|
- order.setOrderTotalFee(orderTotalFee);
|
|
|
- order.setPayTotalFee(payTotalFee);
|
|
|
- payableAmount = payTotalFee;
|
|
|
-
|
|
|
- // 订单状态
|
|
|
- order.setStatus("11");
|
|
|
- order.setConfirmTime(curDateStr);
|
|
|
-
|
|
|
- // 余额支付金额
|
|
|
- order.setBalancePayFee(BigDecimal.ZERO);
|
|
|
- // 实际支付金额(商品金额+运费-余额抵扣)
|
|
|
- order.setPayableAmount(payableAmount);
|
|
|
- // 售后条款
|
|
|
- order.setClauseID(1L);
|
|
|
- order.setClauseName("无条款");
|
|
|
- // 是否返佣订单
|
|
|
- order.setRebateFlag("0");
|
|
|
- // 判断前端传入orderShouldPayFee订单应付金额,和后台计算应付金额对比
|
|
|
- double v = MathUtil.sub(payableAmount, orderShouldPayFee).doubleValue();
|
|
|
- log.info(">>>>>payableAmount:" + payableAmount + " ,orderShouldPayFee:" + orderShouldPayFee);
|
|
|
- // 考虑前端计算不精确
|
|
|
- if (v < -0.1d || v > 0.1d) {
|
|
|
- // 设置手动回滚事务
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return ResponseJson.error("订单付款金额异常");
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 保存主订单数据
|
|
|
- */
|
|
|
- orderMapper.insertOrder(order);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>新增主订单(insert[cm_order])orderId:" + order.getOrderID());
|
|
|
-
|
|
|
- /*
|
|
|
- * 设置订单商品订单号
|
|
|
- */
|
|
|
- for (CmOrderProductPo orderProduct : orderProductList) {
|
|
|
- orderProduct.setOrderID(order.getOrderID());
|
|
|
- orderProduct.setOrderNo(order.getOrderNo());
|
|
|
- }
|
|
|
- /*
|
|
|
- * 整理 子订单信息
|
|
|
- */
|
|
|
- // 收集子订单供应商ID字符串
|
|
|
- String shopOrderIds = "";
|
|
|
- for (Integer shopId : shopIdList) {
|
|
|
- // 初始化子订单信息
|
|
|
- CmShopOrderPo shopOrder = saveShopOrder(order, orderProductList, shopId, "");
|
|
|
- // 保存子订单号
|
|
|
- shopOrderIds += (("".equals(shopOrderIds) ? "" : ",") + shopOrder.getShopOrderID());
|
|
|
- // 设置订单商品子订单号
|
|
|
- for (CmOrderProductPo orderProduct : orderProductList) {
|
|
|
- if (shopId.longValue() == orderProduct.getShopID()) {
|
|
|
- orderProduct.setShopOrderID(shopOrder.getShopOrderID());
|
|
|
- orderProduct.setShopOrderNo(shopOrder.getShopOrderNo());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- /*
|
|
|
- * 保存订单商品
|
|
|
- */
|
|
|
- List<OrderProductLadderPricePo> orderProductLadderPriceList = new ArrayList<>();
|
|
|
- for (CmOrderProductPo orderProduct : orderProductList) {
|
|
|
- // 保存订单商品数据
|
|
|
- orderMapper.insertOrderProduct(orderProduct);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>保存订单商品(insert[cm_order_product])OrderProductID:" + orderProduct.getOrderProductID());
|
|
|
- if ("1".equals(orderProduct.getLadderPriceFlag())) {
|
|
|
- //使用阶梯价格的订单商品保存下单时的阶梯价格列表
|
|
|
- List<LadderPriceVo> ladderPriceList = productMapper.findLadderPriceByProductId(orderProduct.getProductID());
|
|
|
- ladderPriceList.forEach(ladderPriceVo -> {
|
|
|
- OrderProductLadderPricePo orderProductLadderPrice = new OrderProductLadderPricePo();
|
|
|
- orderProductLadderPrice.setOrderProductId(orderProduct.getOrderProductID());
|
|
|
- orderProductLadderPrice.setBuyNum(ladderPriceVo.getBuyNum());
|
|
|
- orderProductLadderPrice.setBuyPrice(ladderPriceVo.getBuyPrice());
|
|
|
- orderProductLadderPrice.setCreateDate(new Date());
|
|
|
- orderProductLadderPrice.setLadderNum(ladderPriceVo.getLadderNum());
|
|
|
- orderProductLadderPriceList.add(orderProductLadderPrice);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(orderProductLadderPriceList)) {
|
|
|
- orderProductLadderPriceList.forEach(ladderPrice -> {
|
|
|
- orderMapper.insertOrderProductLadderPrice(ladderPrice);
|
|
|
- });
|
|
|
- }
|
|
|
- /*
|
|
|
- * 设置邮费子订单
|
|
|
- */
|
|
|
- if ("1".equals(order.getFreePostFlag())) {
|
|
|
- shopOrderIds = setPostFeeShopOrder(order, shopOrderIds, orderInfo.size());
|
|
|
- }
|
|
|
-
|
|
|
- // 更新主订单信息, 子订单ID:1000,1002
|
|
|
- order.setShopOrderIDs(shopOrderIds);
|
|
|
- orderMapper.updateOrder(order);
|
|
|
-
|
|
|
- /*
|
|
|
- * 保存 订单用户地址
|
|
|
- */
|
|
|
- //保存地址信息
|
|
|
- BpOrderUserInfoPo userInfo = new BpOrderUserInfoPo();
|
|
|
- userInfo.setOrderId(order.getOrderID());
|
|
|
- userInfo.setClubId(user.getClubID().longValue());
|
|
|
- userInfo.setUserId(user.getUserID().longValue());
|
|
|
- userInfo.setName(user.getName() == null ? user.getUserName() : user.getName());
|
|
|
- userInfo.setShouHuoRen(receiveMan);
|
|
|
- userInfo.setMobile(mobile);
|
|
|
- userInfo.setPostalCode(null);
|
|
|
- userInfo.setPostalCode(null);
|
|
|
- userInfo.setTownId(townId);
|
|
|
- userInfo.setProvince(provinceName);
|
|
|
- userInfo.setCity(cityName);
|
|
|
- userInfo.setTown(townName);
|
|
|
- userInfo.setAddress(addressDetail);
|
|
|
- orderMapper.insertUserInfo(userInfo);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>保存订单用户地址(insert[bp_order_userinfo])orderId:" + order.getOrderID());
|
|
|
-
|
|
|
+ private OrderSubmitService orderSubmitService;
|
|
|
|
|
|
- /*
|
|
|
- * 保存 订单发票信息
|
|
|
- */
|
|
|
- if (invoiceFlag) {
|
|
|
- // 开发票才保存
|
|
|
- invoice.setOrderId(order.getOrderID());
|
|
|
- // 查询是否存在老的增值税信息
|
|
|
- BpOrderInvoicePo userInvoice = orderMapper.getOrderInvoice(order.getOrderID());
|
|
|
- if (null != userInvoice) {
|
|
|
- // 更新 发票信息
|
|
|
- orderMapper.updateOrderInvoice(invoice);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>更新发票信息(update[bp_order_invoice])orderId:" + order.getOrderID());
|
|
|
- } else {
|
|
|
- // 保存 发票信息
|
|
|
- orderMapper.insertOrderInvoice(invoice);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>新增发票信息(insert[bp_order_invoice])orderId:" + order.getOrderID());
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("******************** 提交订单逻辑处理 end *******************");
|
|
|
- /*
|
|
|
- * 构造返回参数
|
|
|
- */
|
|
|
- Map<String, String> info = new HashMap<>(5);
|
|
|
- //组织订单id
|
|
|
- info.put("orderId", apiOrganizeOrderId);
|
|
|
- //真实需要付款金额
|
|
|
- info.put("payableAmount", String.valueOf(order.getPayableAmount()));
|
|
|
- return ResponseJson.success(info);
|
|
|
+ @Autowired
|
|
|
+ public void setOrderSubmitService(OrderSubmitService orderSubmitService) {
|
|
|
+ this.orderSubmitService = orderSubmitService;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public ResponseJson<Map<String,Object>> orderDetail(String cmAccount, String data) {
|
|
|
// 获取组织信息
|
|
@@ -601,8 +200,15 @@ public class OrderServiceImpl implements OrderService {
|
|
|
return ResponseJson.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 余额抵扣
|
|
|
+ * @param cmAccount
|
|
|
+ * @param data
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public ResponseJson payCallBack(String cmAccount, String data) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public ResponseJson<Map<String, Object>> balanceDeduction(String cmAccount, String data) {
|
|
|
// 获取组织信息
|
|
|
CmApiOrganizePo organizePo = organizeMapper.getOrganizeByCmAccount(cmAccount);
|
|
|
if (null == organizePo) {
|
|
@@ -610,6 +216,12 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
// 获取用户id
|
|
|
Integer userId = organizePo.getUserId();
|
|
|
+ UserPo user = orderMapper.getUserByUserId(userId);
|
|
|
+ BigDecimal userMoney = user.getUserMoney();
|
|
|
+ BigDecimal ableUserMoney = user.getAbleUserMoney();
|
|
|
+ if (MathUtil.compare(ableUserMoney, BigDecimal.ZERO) == 0) {
|
|
|
+ return ResponseJson.error("用户可用余额为0", null);
|
|
|
+ }
|
|
|
JSONObject orderInfo = null;
|
|
|
try {
|
|
|
// 使用组织对应的公钥解密,获得订单数据
|
|
@@ -625,474 +237,109 @@ public class OrderServiceImpl implements OrderService {
|
|
|
e.printStackTrace();
|
|
|
return ResponseJson.error("解密失败", null);
|
|
|
}
|
|
|
- String orderId = (String) orderInfo.get("orderId");
|
|
|
- String result = (String) orderInfo.get("result");
|
|
|
- Double amount = orderInfo.getDouble("amount");
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>订单支付完成通知回调:orderId:" + orderId + ",amount:" + amount + ",result:" + result);
|
|
|
- return ResponseJson.success("SUCCESS");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置订单发票
|
|
|
- *
|
|
|
- * @param orderInvoice
|
|
|
- * @param invoice
|
|
|
- * @param invoiceType
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean setInvoiceParam(Map<String, Object> orderInvoice, BpOrderInvoicePo invoice, Integer invoiceType) {
|
|
|
- String invoiceTitle = (String) (null != orderInvoice.get("invoiceTitle") ? orderInvoice.get("invoiceTitle") : "");
|
|
|
- invoice.setInvoiceTitle(invoiceTitle);
|
|
|
- if (1 == invoiceType) {
|
|
|
- // 普通发票:发票类型、发票内容(商品明细)、抬头(公司名称)、纳税人识别号[普通发票的公司]
|
|
|
- String invoiceContent = (String) (null != orderInvoice.get("invoiceContent") ? orderInvoice.get("invoiceContent") : "");
|
|
|
- String invoiceTitleType = (null != orderInvoice.get("invoiceTitleType") ? orderInvoice.get("invoiceTitleType") : "").toString();
|
|
|
- if ("".equals(invoiceTitle) || "".equals(invoiceContent) || "".equals(invoiceTitleType)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- if ("1".equals(invoiceTitleType)) {
|
|
|
- // 企业
|
|
|
- String corporationTaxNum = (String) (null != orderInvoice.get("corporationTaxNum") ? orderInvoice.get("corporationTaxNum") : "");
|
|
|
- if ("".equals(corporationTaxNum)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
- }
|
|
|
-
|
|
|
- invoice.setInvoiceContent(invoiceContent);
|
|
|
- } else if (2 == invoiceType) {
|
|
|
- // 增值税发票:发票类型、发票、抬头(公司名称)、纳税人识别号、注册地址、注册电话、开户银行、开户银行账户
|
|
|
- String corporationTaxNum = (String) (null != orderInvoice.get("corporationTaxNum") ? orderInvoice.get("corporationTaxNum") : "");
|
|
|
- String registeredAddress = (String) (null != orderInvoice.get("registeredAddress") ? orderInvoice.get("registeredAddress") : "");
|
|
|
- String registeredPhone = (String) (null != orderInvoice.get("registeredPhone") ? orderInvoice.get("registeredPhone") : "");
|
|
|
- String openBank = (String) (null != orderInvoice.get("openBank") ? orderInvoice.get("openBank") : "");
|
|
|
- String bankAccountNo = (String) (null != orderInvoice.get("bankAccountNo") ? orderInvoice.get("bankAccountNo") : "");
|
|
|
- boolean flag = "".equals(invoiceTitle) || "".equals(corporationTaxNum) || "".equals(registeredAddress) || "".equals(registeredPhone) || "".equals(openBank) || "".equals(bankAccountNo);
|
|
|
- if (flag) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- invoice.setCorporationTaxNum(corporationTaxNum);
|
|
|
- invoice.setRegisteredAddress(registeredAddress);
|
|
|
- invoice.setRegisteredPhone(registeredPhone);
|
|
|
- invoice.setOpenBank(openBank);
|
|
|
- invoice.setBankAccountNo(bankAccountNo);
|
|
|
+ String apiOrganizeOrderId = (String) orderInfo.get("orderId");
|
|
|
+ if (StringUtils.isEmpty(apiOrganizeOrderId)) {
|
|
|
+ return ResponseJson.error("参数异常,订单Id不能为空",null);
|
|
|
}
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 整理订单商品数据
|
|
|
- *
|
|
|
- * @param productNum
|
|
|
- * @param product
|
|
|
- * @param productPrice
|
|
|
- * @param priceType 0正常商品 1促销商品 2阶梯价 3复购价
|
|
|
- * @param productType
|
|
|
- * @return
|
|
|
- */
|
|
|
- private CmOrderProductPo setOrderProduct(Integer productNum, CmApiOrganizeProductPo product, BigDecimal productPrice, Integer priceType, Integer productType, BigDecimal addedValueTax) {
|
|
|
- CmOrderProductPo orderProduct = new CmOrderProductPo();
|
|
|
- orderProduct.setShopID(product.getShopId().longValue());
|
|
|
- orderProduct.setProductID(product.getProductId());
|
|
|
-// orderProduct.setOrganizeProductID(product.getId());
|
|
|
- // 预留在保存保存子订单的时候添加
|
|
|
- orderProduct.setProductNo(null);
|
|
|
- orderProduct.setNum(productNum);
|
|
|
- orderProduct.setPresentNum(0);
|
|
|
- orderProduct.setProductUnit(product.getUnit());
|
|
|
- if (MathUtil.compare(product.getNormalPrice(), 0) > 0) {
|
|
|
- orderProduct.setNormalPrice(product.getNormalPrice());
|
|
|
- } else {
|
|
|
- orderProduct.setNormalPrice(BigDecimal.ZERO);
|
|
|
+ OrderVo order = orderMapper.getOrderInfo(userId, apiOrganizeOrderId);
|
|
|
+ if (null == order) {
|
|
|
+ return ResponseJson.error("该订单不存在",null);
|
|
|
}
|
|
|
- orderProduct.setCostPrice(product.getCostPrice());
|
|
|
- orderProduct.setPrice0(product.getPrice());
|
|
|
- orderProduct.setPrice1(product.getPrice());
|
|
|
- orderProduct.setTotalAmount(MathUtil.mul(product.getPrice(), productNum));
|
|
|
-
|
|
|
- orderProduct.setDiscount(new BigDecimal(100));
|
|
|
- // 经理折扣(优惠金额)
|
|
|
- orderProduct.setDiscountFee(new BigDecimal(0));
|
|
|
- //机构税率
|
|
|
- orderProduct.setTaxRate(product.getClubTaxPoint() == null ? new BigDecimal(0) : product.getClubTaxPoint());
|
|
|
- //供应商税率
|
|
|
- orderProduct.setSupplierTaxRate(BigDecimal.valueOf(0));
|
|
|
- orderProduct.setIncludedTax(product.getIncludedTax().toString());
|
|
|
- orderProduct.setInvoiceType(product.getInvoiceType().toString());
|
|
|
- BigDecimal singleShouldPayTotalTax = new BigDecimal(0);
|
|
|
- if (productType == 2) {
|
|
|
- //促销赠品置机构税率和供应商税率为0
|
|
|
- orderProduct.setTaxRate(BigDecimal.ZERO);
|
|
|
- orderProduct.setSupplierTaxRate(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- //不含税可开发票商品设置税费
|
|
|
- if (0 == product.getIncludedTax() && (1 == product.getInvoiceType() || 2 == product.getInvoiceType())) {
|
|
|
- //供应商税费(单)=成本价 * 供应商税率
|
|
|
- if (product.getShopTaxPoint() == null) {
|
|
|
- orderProduct.setSupplierTaxRate(product.getClubTaxPoint());
|
|
|
- } else {
|
|
|
- orderProduct.setSupplierTaxRate(product.getShopTaxPoint());
|
|
|
+ getDiscernReceipt(order);
|
|
|
+ //本次余额抵扣金额
|
|
|
+ BigDecimal balancePayFee = BigDecimal.ZERO;
|
|
|
+ if (MathUtil.compare(ableUserMoney, 0) > 0) {
|
|
|
+ if (MathUtil.compare(ableUserMoney, order.getPendingPayments()) < 0) {
|
|
|
+ if (!"0".equals(order.getStatus())) {
|
|
|
+ //待确认状态,不修改订单状态
|
|
|
+ if ("1".equals(order.getSendOutStatus())) {
|
|
|
+ order.setStatus("21");
|
|
|
+ } else if ("2".equals(order.getSendOutStatus())) {
|
|
|
+ order.setStatus("22");
|
|
|
+ } else {
|
|
|
+ order.setStatus("23");
|
|
|
+ }
|
|
|
}
|
|
|
- singleShouldPayTotalTax = MathUtil.div(MathUtil.mul(product.getCostPrice(), orderProduct.getSupplierTaxRate()), BigDecimal.valueOf(100));
|
|
|
- } else if (1 == product.getIncludedTax()) {
|
|
|
- //含税商品设置供应商税率
|
|
|
- if (product.getShopTaxPoint() == null) {
|
|
|
- orderProduct.setSupplierTaxRate(product.getClubTaxPoint());
|
|
|
- } else {
|
|
|
- orderProduct.setSupplierTaxRate(product.getShopTaxPoint());
|
|
|
+ order.setReceiptStatus("2");
|
|
|
+ balancePayFee = ableUserMoney;
|
|
|
+ } else {
|
|
|
+ if (!"0".equals(order.getStatus())) {
|
|
|
+ if ("1".equals(order.getSendOutStatus())) {
|
|
|
+ order.setStatus("31");
|
|
|
+ } else if ("2".equals(order.getSendOutStatus())) {
|
|
|
+ order.setStatus("32");
|
|
|
+ } else {
|
|
|
+ order.setStatus("33");
|
|
|
+ }
|
|
|
}
|
|
|
- } else if ((0 == product.getIncludedTax() && 3 == product.getInvoiceType()) || 2 == product.getIncludedTax()) {
|
|
|
- //不含税不可开票商品和未知商品,税率置为0
|
|
|
- orderProduct.setTaxRate(BigDecimal.ZERO);
|
|
|
- orderProduct.setSupplierTaxRate(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- orderProduct.setAddedValueTax(addedValueTax);
|
|
|
- //机构税费(总)=机构税费(单) * 商品数量
|
|
|
- orderProduct.setTotalAddedValueTax(MathUtil.mul(addedValueTax, productNum));
|
|
|
- orderProduct.setSingleShouldPayTotalTax(singleShouldPayTotalTax);
|
|
|
- //供应商税费(总)=供应商税费(单) * 商品数量
|
|
|
- orderProduct.setShouldPayTotalTax(MathUtil.mul(singleShouldPayTotalTax, productNum));
|
|
|
- orderProduct.setTotalFee(MathUtil.mul(productPrice, productNum));
|
|
|
- orderProduct.setShouldPayFee(MathUtil.mul(productPrice, productNum));
|
|
|
-
|
|
|
- // 商品费=成本价快照*(购买数量 + 赠品数量)
|
|
|
- orderProduct.setShopProductAmount(MathUtil.mul(product.getCostPrice(), BigDecimal.valueOf(productNum)));
|
|
|
- //不含税可开票商品,单价/折后单价=售价-税费
|
|
|
- if (priceType == 0 || priceType == 1) {
|
|
|
- //正常价格和促销价格
|
|
|
- orderProduct.setPrice(product.getPrice());
|
|
|
- orderProduct.setDiscountPrice(product.getPrice());
|
|
|
- } else if (priceType == 2) {
|
|
|
- //阶梯价
|
|
|
- BigDecimal price1 = productPrice;
|
|
|
- //不含税可开票商品,单价/折后单价=售价-税费
|
|
|
- if (0 == product.getIncludedTax() && (1 == product.getInvoiceType() || 2 == product.getInvoiceType())) {
|
|
|
- price1 = MathUtil.sub(productPrice, orderProduct.getAddedValueTax());
|
|
|
- }
|
|
|
- orderProduct.setPrice(price1);
|
|
|
- orderProduct.setDiscountPrice(price1);
|
|
|
- }
|
|
|
- //应付供应商(单)=成本价+供应商税费(单)
|
|
|
- BigDecimal singleShopFee = MathUtil.add(product.getCostPrice(), singleShouldPayTotalTax);
|
|
|
- orderProduct.setSingleShopFee(singleShopFee);
|
|
|
- // 应付供应商(总)=应付供应商(单) * 商品数量
|
|
|
- orderProduct.setShopFee(MathUtil.mul(singleShopFee, BigDecimal.valueOf(productNum)));
|
|
|
- orderProduct.setOtherFee(new BigDecimal(0));
|
|
|
- orderProduct.setSingleOtherFee(new BigDecimal(0));
|
|
|
-
|
|
|
- //应付采美(单)=单价+机构税费(单)-(成本(单)+供应商税费(单))
|
|
|
- BigDecimal singleCmFee = MathUtil.sub(MathUtil.add(product.getPrice(), orderProduct.getAddedValueTax()), MathUtil.add(product.getCostPrice(), singleShouldPayTotalTax));
|
|
|
- orderProduct.setSingleCmFee(singleCmFee);
|
|
|
- // 应付采美(总)=应付采美(单)*商品数量
|
|
|
- BigDecimal cmFee = MathUtil.mul(singleCmFee, BigDecimal.valueOf(productNum));
|
|
|
- orderProduct.setCmFee(cmFee);
|
|
|
-
|
|
|
- orderProduct.setTotalBeans(new BigDecimal(0));
|
|
|
- orderProduct.setUseBalanceAmount(0d);
|
|
|
- // 优惠金额
|
|
|
- orderProduct.setPreferential(new BigDecimal(0));
|
|
|
- orderProduct.setUseBalanceAmount(0d);
|
|
|
- // 订单商品供应商确认标志 0否 1是
|
|
|
- orderProduct.setConfirmProductFlag("0");
|
|
|
-
|
|
|
- orderProduct.setShopName(product.getShopName());
|
|
|
- orderProduct.setName(product.getName());
|
|
|
- orderProduct.setPayStatus("0");
|
|
|
- orderProduct.setBuyAgainFlag("0");
|
|
|
- // 未出库数量
|
|
|
- orderProduct.setNotOutStore(productNum);
|
|
|
- // 是否已评论 1 是 0 未评论
|
|
|
- orderProduct.setCommentFlag("0");
|
|
|
- orderProduct.setActPreferential(new BigDecimal(0));
|
|
|
- orderProduct.setActType(null);
|
|
|
-
|
|
|
- orderProduct.setIsActProduct(product.getActStatus().toString());
|
|
|
- orderProduct.setLadderPriceFlag(product.getActStatus() == 2 ? "1" : "0");
|
|
|
- orderProduct.setProductImage(ProductUtils.getImageURL("product", product.getMainImage(), 0, domain));
|
|
|
- orderProduct.setProductType(productType.toString());
|
|
|
- //促销赠品
|
|
|
- if (productType == 2) {
|
|
|
- orderProduct.setPrice0(BigDecimal.ZERO);
|
|
|
- orderProduct.setPrice1(BigDecimal.ZERO);
|
|
|
- orderProduct.setTotalAmount(BigDecimal.ZERO);
|
|
|
- orderProduct.setTotalFee(BigDecimal.ZERO);
|
|
|
- orderProduct.setDiscountPrice(BigDecimal.ZERO);
|
|
|
- orderProduct.setTotalAddedValueTax(BigDecimal.ZERO);
|
|
|
- orderProduct.setShouldPayTotalTax(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- return orderProduct;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 计算总运费
|
|
|
- *
|
|
|
- * @param provinceId
|
|
|
- * @param cityId
|
|
|
- * @return totalPostageFee
|
|
|
- */
|
|
|
- public Double computedPostageFee(Integer provinceId, Integer cityId) {
|
|
|
- if (202 == cityId) {
|
|
|
- // 深圳市内运费10元
|
|
|
- return 10d;
|
|
|
- } else if (19 == provinceId) {
|
|
|
- // 广东省内深圳市外运费15元
|
|
|
- return 15d;
|
|
|
+ order.setReceiptStatus("3");
|
|
|
+ balancePayFee = order.getPendingPayments();
|
|
|
+ }
|
|
|
+ order.setBalancePayFee(MathUtil.add(order.getBalancePayFee(), balancePayFee));
|
|
|
+ order.setPayableAmount(MathUtil.sub(order.getPayableAmount(), balancePayFee));
|
|
|
+ orderMapper.updateOrder(order);
|
|
|
+ //剩余待付金额
|
|
|
+ order.setPendingPayments(MathUtil.sub(order.getPendingPayments(), balancePayFee));
|
|
|
+ //修改账户余额
|
|
|
+ if (!"0".equals(order.getStatus())) {
|
|
|
+ user.setUserMoney(MathUtil.sub(userMoney, balancePayFee));
|
|
|
+ //保存收款记录
|
|
|
+ orderSubmitService.saveDiscernReceipt(balancePayFee, order.getOrderID().intValue());
|
|
|
+ }
|
|
|
+ user.setAbleUserMoney(MathUtil.sub(ableUserMoney, balancePayFee));
|
|
|
+ organizeMapper.updateMoney(user.getUserMoney(), user.getAbleUserMoney(), user.getUserID());
|
|
|
+ //保存余额收支记录
|
|
|
+ orderSubmitService.saveBalanceRecord(balancePayFee, order.getOrderID().intValue(), user.getUserID());
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>(2);
|
|
|
+ map.put("balancePayFee", balancePayFee);
|
|
|
+ map.put("orderId", apiOrganizeOrderId);
|
|
|
+ map.put("payableAmount", order.getPayableAmount());
|
|
|
+ if (MathUtil.compare(order.getPayableAmount(),BigDecimal.ZERO) >0) {
|
|
|
+ // 余额抵扣,部分付款
|
|
|
+ map.put("code", "1");
|
|
|
+ map.put("msg", "抵扣成功部分支付");
|
|
|
} else {
|
|
|
- return -1d;
|
|
|
+ // 余额抵扣,完成付款
|
|
|
+ map.put("code", "2");
|
|
|
+ map.put("msg", "抵扣成功完成支付");
|
|
|
}
|
|
|
+ return ResponseJson.success(map);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 保存子订单,并返回子订单ids
|
|
|
- *
|
|
|
- * @param order
|
|
|
- * @param orderProductList
|
|
|
- * @param shopId
|
|
|
- * @param shopNote
|
|
|
- * @return
|
|
|
- */
|
|
|
- private CmShopOrderPo saveShopOrder(CmOrderPo order, List<CmOrderProductPo> orderProductList, Integer shopId, String shopNote) {
|
|
|
- /*
|
|
|
- * 初始化子订单信息
|
|
|
- */
|
|
|
- CmShopOrderPo shopOrder = new CmShopOrderPo();
|
|
|
- // 子订单编号
|
|
|
- String shopOrderNo = "";
|
|
|
- String maxShopOrderNo = orderMapper.findMaxShopOrderNo(order.getOrderID());
|
|
|
- if (StringUtils.isNotBlank(maxShopOrderNo)) {
|
|
|
- shopOrderNo = maxShopOrderNo;
|
|
|
- shopOrder.setShopOrderNo(OrderNoUtils.getShopOrderNo(order.getOrderNo(), Integer.parseInt(shopOrderNo.substring(shopOrderNo.length() - 2, shopOrderNo.length())) + 1));
|
|
|
- } else {
|
|
|
- shopOrder.setShopOrderNo(OrderNoUtils.getShopOrderNo(order.getOrderNo(), 1));
|
|
|
+ @Override
|
|
|
+ public ResponseJson payCallBack(String cmAccount, String data) {
|
|
|
+ // 获取组织信息
|
|
|
+ CmApiOrganizePo organizePo = organizeMapper.getOrganizeByCmAccount(cmAccount);
|
|
|
+ if (null == organizePo) {
|
|
|
+ return ResponseJson.error("参数异常,用户不存在", null);
|
|
|
}
|
|
|
- shopOrder.setShopID(shopId);
|
|
|
- shopOrder.setClubID(order.getClubID().intValue());
|
|
|
- shopOrder.setOrderID(order.getOrderID());
|
|
|
- shopOrder.setOrderNo(order.getOrderNo());
|
|
|
- shopOrder.setUserID(order.getUserID().intValue());
|
|
|
- shopOrder.setOrganizeID(order.getOrganizeID());
|
|
|
- /*
|
|
|
- * 统计子订单金额信息
|
|
|
- */
|
|
|
- // 订单总金额
|
|
|
- BigDecimal totalAmount = new BigDecimal(0);
|
|
|
- // 商品总金额
|
|
|
- BigDecimal productAmount = new BigDecimal(0);
|
|
|
- // 需要支付金额
|
|
|
- BigDecimal needPayAmount = new BigDecimal(0);
|
|
|
- // 优惠金额
|
|
|
- BigDecimal preferential = new BigDecimal(0);
|
|
|
- // 佣金
|
|
|
- BigDecimal brokerage = new BigDecimal(0);
|
|
|
- // 商品费
|
|
|
- BigDecimal shopProductAmount = new BigDecimal(0);
|
|
|
- // 供应商税费
|
|
|
- BigDecimal shopTaxFee = new BigDecimal(0);
|
|
|
- // 总购买数
|
|
|
- Integer buyNum = 0;
|
|
|
- // 计算子订单信息
|
|
|
- for (CmOrderProductPo orderProduct : orderProductList) {
|
|
|
- if (shopId.longValue() == orderProduct.getShopID()) {
|
|
|
- // 商品总金额
|
|
|
- productAmount = MathUtil.add(productAmount, orderProduct.getTotalAmount());
|
|
|
- // 订单总金额 包括税费
|
|
|
- totalAmount = MathUtil.add(totalAmount, orderProduct.getTotalFee());
|
|
|
- // 应付金额
|
|
|
- needPayAmount = MathUtil.add(needPayAmount, orderProduct.getShouldPayFee());
|
|
|
- // 总购买数
|
|
|
- buyNum += orderProduct.getNum();
|
|
|
- preferential = MathUtil.add(preferential, orderProduct.getPreferential());
|
|
|
- brokerage = MathUtil.add(brokerage, orderProduct.getCmFee());
|
|
|
- if (null != orderProduct.getShopProductAmount()) {
|
|
|
- shopProductAmount = MathUtil.add(shopProductAmount, orderProduct.getShopProductAmount());
|
|
|
- }
|
|
|
- if (null != orderProduct.getShouldPayTotalTax()) {
|
|
|
- shopTaxFee = MathUtil.add(shopTaxFee, orderProduct.getShouldPayTotalTax());
|
|
|
- }
|
|
|
+ // 获取用户id
|
|
|
+ Integer userId = organizePo.getUserId();
|
|
|
+ JSONObject orderInfo = null;
|
|
|
+ try {
|
|
|
+ // 使用组织对应的公钥解密,获得订单数据
|
|
|
+ orderInfo = KeyUtils.decryptDataPublic(data, organizePo.getPublicKey());
|
|
|
+ // 私钥验签
|
|
|
+ String preSign = orderInfo.getString("sign");
|
|
|
+ orderInfo.remove("sign");
|
|
|
+ String sufSign = KeyUtils.buildSign(orderInfo, organizePo.getPrivateKey());
|
|
|
+ if (!preSign.equals(sufSign)) {
|
|
|
+ return ResponseJson.error("验签失败", null);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseJson.error("解密失败", null);
|
|
|
}
|
|
|
- shopOrder.setPromotionFullReduction(BigDecimal.ZERO);
|
|
|
- // freePostFlag: 0包邮 -1到付 1 有运费
|
|
|
- // fee: 运费:-1到付,0包邮,其他为具体运费(v5.0版本已废弃,运费已使用商品形式存储)
|
|
|
- if ("1".equals(order.getFreePostFlag())) {
|
|
|
- shopOrder.setFee(0d);
|
|
|
- } else {
|
|
|
- shopOrder.setFee(Double.parseDouble(order.getFreePostFlag()));
|
|
|
- }
|
|
|
- shopOrder.setNote(shopNote);
|
|
|
- shopOrder.setOrderTime(order.getOrderTime());
|
|
|
- shopOrder.setDiscountFee(BigDecimal.ZERO);
|
|
|
- shopOrder.setCanRefundFlag(1);
|
|
|
- shopOrder.setCanRefundAmount(needPayAmount.doubleValue());
|
|
|
- shopOrder.setAccountAmount(BigDecimal.ZERO);
|
|
|
- // 佣金 采美应收
|
|
|
- shopOrder.setBrokerage(brokerage);
|
|
|
- shopOrder.setBuyStatus("1");
|
|
|
- shopOrder.setPresentNum(0);
|
|
|
- shopOrder.setUseBeanFlag(0);
|
|
|
- shopOrder.setUseBeanAmount(0);
|
|
|
- shopOrder.setUseBalanceFlag(0);
|
|
|
- shopOrder.setRefundStatus(0);
|
|
|
- shopOrder.setRefundsAmount(BigDecimal.ZERO);
|
|
|
- shopOrder.setPayStatus("1");
|
|
|
- shopOrder.setZeroCostFlag(0);
|
|
|
- shopOrder.setSendOutStatus("1");
|
|
|
- shopOrder.setPayFlag("0");
|
|
|
- // 订单状态标识,1:非退货退款订单、2:退货退款中、3退货退款完成
|
|
|
- shopOrder.setOrderStatusFlag("1");
|
|
|
- shopOrder.setDelFlag("0");
|
|
|
- shopOrder.setOrderBeanAmount(0);
|
|
|
- // 购买商品数
|
|
|
- shopOrder.setItemCount(buyNum);
|
|
|
- // 普通订单 1 协销订单0 与cm_order一样
|
|
|
- shopOrder.setOrderType(0);
|
|
|
- shopOrder.setStatus(1);
|
|
|
- shopOrder.setOrderSubmitType(order.getOrderSubmitType());
|
|
|
- shopOrder.setTotalAmount(totalAmount);
|
|
|
- shopOrder.setProductAmount(productAmount);
|
|
|
- shopOrder.setNeedPayAmount(needPayAmount);
|
|
|
- shopOrder.setPreferential(preferential);
|
|
|
- shopOrder.setShopProductAmount(shopProductAmount);
|
|
|
- // 付给供应商运费
|
|
|
- shopOrder.setShopPostFee(BigDecimal.ZERO);
|
|
|
- // 付给供应商税费
|
|
|
- shopOrder.setShopTaxFee(shopTaxFee);
|
|
|
- // 已付款金额
|
|
|
- shopOrder.setPayedShopAmount(BigDecimal.ZERO);
|
|
|
- // 付第三方
|
|
|
- shopOrder.setShopOtherFee(BigDecimal.ZERO);
|
|
|
- // 付供应商 = 商品费 + 运费 + 税费
|
|
|
- shopOrder.setShouldPayShopAmount(MathUtil.add(shopProductAmount, shopTaxFee));
|
|
|
- // 订单能否拆分 1 为可拆分, 0为不可拆分
|
|
|
- if (buyNum > 1) {
|
|
|
- shopOrder.setSplitFlag("1");
|
|
|
- } else {
|
|
|
- shopOrder.setSplitFlag("0");
|
|
|
- }
|
|
|
- /*
|
|
|
- * 保存子订单信息到数据库
|
|
|
- */
|
|
|
- orderMapper.insertShopOrder(shopOrder);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>新增子订单(insert[cm_shop_order])shopOrderId:" + shopOrder.getShopOrderID());
|
|
|
- return shopOrder;
|
|
|
+ String orderId = (String) orderInfo.get("orderId");
|
|
|
+ String result = (String) orderInfo.get("result");
|
|
|
+ Double amount = orderInfo.getDouble("amount");
|
|
|
+ log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>订单支付完成通知回调:orderId:" + orderId + ",amount:" + amount + ",result:" + result);
|
|
|
+ return ResponseJson.success("SUCCESS");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 保存运费子订单,并返回子订单ids
|
|
|
- *
|
|
|
- * @param order
|
|
|
- * @param num
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String setPostFeeShopOrder(CmOrderPo order, String shopOrderIds, int num) {
|
|
|
- ProductPo product = productMapper.findPostFeeProduct();
|
|
|
- CmShopOrderPo newShopOrder = new CmShopOrderPo();
|
|
|
- String shopOrderNo = OrderNoUtils.getShopOrderNo(order.getOrderNo(), num + 1);
|
|
|
- newShopOrder.setShopOrderNo(shopOrderNo);
|
|
|
- newShopOrder.setOrderNo(order.getOrderNo());
|
|
|
- newShopOrder.setOrderID(order.getOrderID());
|
|
|
- newShopOrder.setUserID(order.getUserID().intValue());
|
|
|
- newShopOrder.setOrderType(order.getOrderType());
|
|
|
- newShopOrder.setOrderSubmitType(order.getOrderSubmitType());
|
|
|
- newShopOrder.setPresentNum(0);
|
|
|
- newShopOrder.setItemCount(1);
|
|
|
- //运费商品供应商ID默认998
|
|
|
- newShopOrder.setShopID(product.getShopID());
|
|
|
- newShopOrder.setFee(order.getFreight().doubleValue());
|
|
|
- newShopOrder.setProductAmount(order.getFreight());
|
|
|
- newShopOrder.setTotalAmount(order.getFreight());
|
|
|
- newShopOrder.setNeedPayAmount(order.getFreight());
|
|
|
- newShopOrder.setDiscountAmount(BigDecimal.ZERO);
|
|
|
- newShopOrder.setPayFlag("0");
|
|
|
- newShopOrder.setOrderTime(order.getOrderTime());
|
|
|
- newShopOrder.setPayStatus("3");
|
|
|
- newShopOrder.setSendOutStatus("3");
|
|
|
- newShopOrder.setTotalAddedValueTax(BigDecimal.ZERO);
|
|
|
- newShopOrder.setCanRefundAmount(0D);
|
|
|
- newShopOrder.setRefundAmount(0D);
|
|
|
- newShopOrder.setRefundStatus(0);
|
|
|
- newShopOrder.setClubID(order.getClubID().intValue());
|
|
|
- if (null != order.getSpID()) {
|
|
|
- newShopOrder.setSpID(order.getSpID().intValue());
|
|
|
- }
|
|
|
- if (null != order.getMainSpID()) {
|
|
|
- newShopOrder.setMainSpID(order.getMainSpID().intValue());
|
|
|
- }
|
|
|
- newShopOrder.setAutoOverTimeMills(0L);
|
|
|
- newShopOrder.setAutoReceiveTimeMills(0L);
|
|
|
- newShopOrder.setOrderBeanAmount(0);
|
|
|
- newShopOrder.setUseBeanFlag(0);
|
|
|
- newShopOrder.setUseBeanAmount(0);
|
|
|
- newShopOrder.setAccountAmount(BigDecimal.ZERO);
|
|
|
- newShopOrder.setCanRefundFlag(1);
|
|
|
- newShopOrder.setBuyStatus("1");
|
|
|
- newShopOrder.setOutStoreNum(0);
|
|
|
- newShopOrder.setDelFlag("0");
|
|
|
- newShopOrder.setPayFlag("0");
|
|
|
- // 订单默认可拆分
|
|
|
- newShopOrder.setSplitFlag("1");
|
|
|
- /*
|
|
|
- * 保存子订单信息到数据库
|
|
|
- */
|
|
|
- orderMapper.insertShopOrder(newShopOrder);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>新增子订单(运费商品)(insert[cm_shop_order])shopOrderId:" + newShopOrder.getShopOrderID());
|
|
|
|
|
|
- /*
|
|
|
- * 插入订单 运费商品
|
|
|
- */
|
|
|
- CmOrderProductPo feeOrderProduct = new CmOrderProductPo();
|
|
|
- feeOrderProduct.setProductType("0");
|
|
|
- feeOrderProduct.setOrderNo(order.getOrderNo());
|
|
|
- feeOrderProduct.setOrderID(order.getOrderID());
|
|
|
- feeOrderProduct.setShopOrderID(newShopOrder.getShopOrderID());
|
|
|
- feeOrderProduct.setShopOrderNo(newShopOrder.getShopOrderNo());
|
|
|
- feeOrderProduct.setShopID(product.getShopID().longValue());
|
|
|
- feeOrderProduct.setProductID(999);
|
|
|
- feeOrderProduct.setNum(1);
|
|
|
- feeOrderProduct.setPresentNum(0);
|
|
|
- feeOrderProduct.setOutStoreType("0");
|
|
|
- feeOrderProduct.setProps(product.getProps());
|
|
|
- feeOrderProduct.setProductNo(product.getProductCode());
|
|
|
- feeOrderProduct.setPrice(order.getFreight());
|
|
|
- feeOrderProduct.setNormalPrice(order.getFreight());
|
|
|
- feeOrderProduct.setPrice0(order.getFreight());
|
|
|
- feeOrderProduct.setPrice1(order.getFreight());
|
|
|
- feeOrderProduct.setTotalAmount(order.getFreight());
|
|
|
- feeOrderProduct.setTotalFee(order.getFreight());
|
|
|
- feeOrderProduct.setShouldPayFee(order.getFreight());
|
|
|
- feeOrderProduct.setDiscount(new BigDecimal(100));
|
|
|
- feeOrderProduct.setDiscountPrice(order.getFreight());
|
|
|
- feeOrderProduct.setTaxRate(new BigDecimal(100));
|
|
|
- feeOrderProduct.setAddedValueTax(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setTotalAddedValueTax(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setShopFee(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setOtherFee(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setCmFee(order.getFreight());
|
|
|
- feeOrderProduct.setSingleShopFee(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setSingleOtherFee(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setSingleCmFee(order.getFreight());
|
|
|
- feeOrderProduct.setTotalBeans(BigDecimal.ZERO);
|
|
|
- feeOrderProduct.setUseBalanceAmount(0D);
|
|
|
- feeOrderProduct.setUseBeanAmount(0);
|
|
|
- feeOrderProduct.setNotOutStore(0);
|
|
|
- feeOrderProduct.setCmbeanPrice(0);
|
|
|
- feeOrderProduct.setBuyAgainFlag("0");
|
|
|
- feeOrderProduct.setShopName(product.getShopName());
|
|
|
- feeOrderProduct.setName(product.getName());
|
|
|
- feeOrderProduct.setIncludedTax(product.getIncludedTax());
|
|
|
- feeOrderProduct.setInvoiceType(product.getInvoiceType());
|
|
|
- // 保存订单商品数据
|
|
|
- orderMapper.insertOrderProduct(feeOrderProduct);
|
|
|
- log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>保存订单运费商品(insert[cm_order_product])orderId:" + feeOrderProduct.getOrderProductID());
|
|
|
|
|
|
- shopOrderIds += (("".equals(shopOrderIds) ? "" : ",") + newShopOrder.getShopOrderID());
|
|
|
- return shopOrderIds;
|
|
|
- }
|
|
|
|
|
|
|
|
|
private List<DiscernReceiptVo> getDiscernReceipt(OrderVo order) {
|