plf 4 anos atrás
pai
commit
ee5be6d922

+ 22 - 15
src/main/java/com/caimei/controller/OrderSubmitApi.java

@@ -4,7 +4,10 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei.model.ResponseJson;
 import com.caimei.service.OrderSubmitService;
-import io.swagger.annotations.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,12 +46,11 @@ public class OrderSubmitApi {
     @ApiOperation("商品结算")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "productIds", value = "组织商品ID串用逗号隔开。", required = true),
-            @ApiImplicitParam(name = "count", value = "立即购买商品数量,购物车count为null。"),
             @ApiImplicitParam(name = "userId", value = "机构用户id。", required = true)
     })
     @GetMapping("/confirm")
-    public ResponseJson<Map<String, Object>> orderConfirm(String productIds, Integer count, Integer userId) {
-        return orderSubmitService.orderConfirm(productIds, count, userId);
+    public ResponseJson<Map<String, Object>> orderConfirm(String productIds, Integer userId) {
+        return orderSubmitService.orderConfirm(productIds, userId);
     }
 
     /**
@@ -108,8 +110,6 @@ public class OrderSubmitApi {
         if (StringUtils.isBlank(params)) {
             return ResponseJson.error("数据异常", null);
         }
-        Integer cartType = null;
-        String orderSource = null;
         Integer clubUserId = null;
         Integer addressId = null;
         List<Map<String, Object>> orderInfo = null;
@@ -121,14 +121,6 @@ public class OrderSubmitApi {
             if (null == paramsMap) {
                 return ResponseJson.error("数据异常,参数不能为空", null);
             }
-            orderSource = paramsMap.getString("orderSource");
-            if (StringUtils.isEmpty(orderSource)) {
-                return ResponseJson.error("订单来源异常", null);
-            }
-            cartType = paramsMap.getInteger("cartType");
-            if (null == cartType) {
-                return ResponseJson.error("购买类型异常", null);
-            }
             clubUserId = paramsMap.getInteger("clubUserId");
             if (null == clubUserId) {
                 return ResponseJson.error("机构用户Id异常", null);
@@ -155,6 +147,21 @@ public class OrderSubmitApi {
         }
 
         log.info("****** 提交订单参数:【机构自己下单】:" + params);
-        return orderSubmitService.orderSubmit(cartType, orderSource, clubUserId, addressId, orderInfo, payInfo, orderInvoice);
+        return orderSubmitService.orderSubmit(clubUserId, addressId, orderInfo, payInfo, orderInvoice);
+    }
+
+    /**
+     * 获取运费
+     */
+    @ApiOperation("获取运费")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "productIds", value = "组织商品ID串用逗号隔开。", required = true),
+            @ApiImplicitParam(name = "userId", value = "机构用户id。", required = true),
+            @ApiImplicitParam(name = "totalPrice", value = "商品总金额。", required = true),
+            @ApiImplicitParam(name = "townId", value = "区id", required = true)
+    })
+    @GetMapping("/postage")
+    public ResponseJson<Map<String, Object>> orderPostage(String productIds, Double totalPrice, Integer townId, Integer userId) {
+        return orderSubmitService.orderPostage(productIds, totalPrice, townId, userId);
     }
 }

+ 25 - 0
src/main/java/com/caimei/mapper/OrderSubmitMapper.java

@@ -3,6 +3,7 @@ package com.caimei.mapper;
 import com.caimei.model.po.*;
 import com.caimei.model.vo.AddressVo;
 import com.caimei.model.vo.CartProductVo;
+import com.caimei.model.vo.CityVo;
 import com.caimei.model.vo.ShopVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -156,8 +157,32 @@ public interface OrderSubmitMapper {
 
     /**
      * 查询地址信息
+     *
      * @param addressId
      * @return
      */
     AddressVo findByAddressId(Integer addressId);
+
+    /**
+     * 查询商品
+     *
+     * @param productId
+     * @return
+     */
+    ProductPo findProductById(int productId);
+
+    /**
+     * 是否首单
+     *
+     * @param userId
+     * @return
+     */
+    Integer countUserOrder(Integer userId);
+
+    /**
+     * 查询省市
+     * @param townId
+     * @return
+     */
+    CityVo findCityByTownId(Integer townId);
 }

+ 0 - 65
src/main/java/com/caimei/mapper/PayOrderMapper.java

@@ -16,14 +16,6 @@ import java.util.List;
  */
 @Mapper
 public interface PayOrderMapper {
-    /**
-     * 查询订单信息
-     *
-     * @param orderId
-     * @return
-     */
-    OrderVo findOrder(Integer orderId);
-
     /**
      * 查询支付记录
      *
@@ -100,65 +92,8 @@ public interface PayOrderMapper {
      */
     List<OrderProductVo> findAllOrderProduct(Integer orderId);
 
-    /**
-     * 保存分账信息
-     *
-     * @param splitAccount
-     */
-    void insertSplitAccount(SplitAccountVo splitAccount);
-
     /**
      * 获取线上支付开关状态
      */
     Integer getPayOnLineSwitch();
-
-    /**
-     * 查询子商户商编
-     *
-     * @param shopId
-     * @return
-     */
-    String findCommercialCode(Long shopId);
-
-    /**
-     * 查询已支付金额
-     *
-     * @param orderProductId
-     * @return
-     */
-    BigDecimal findPaidAmount(Integer orderProductId);
-
-    /**
-     * 查询子订单
-     *
-     * @param orderId
-     * @return
-     */
-    List<ShopOrderVo> findShopOrder(Integer orderId);
-
-    /**
-     * 查询已支付运费
-     *
-     * @param orderId
-     * @param shopId
-     * @return
-     */
-    BigDecimal findShipping(@Param("orderId") Integer orderId, @Param("shopId") Integer shopId);
-
-    /**
-     * 修改子订单付款状态及付款金额
-     *
-     * @param shopOrderId 子订单id
-     * @param paidShop    已支付金额
-     * @param payStatus   付款状态
-     */
-    void updateShopOrderByPayStatus(@Param("shopOrderId") Integer shopOrderId, @Param("paidShop") BigDecimal paidShop, @Param("payStatus") String payStatus);
-
-    /**
-     * 修改主订单付款状态
-     *
-     * @param orderId
-     * @param payStatus
-     */
-    void updateOrderByPayStatus(@Param("orderId") Integer orderId, @Param("payStatus") String payStatus);
 }

+ 7 - 0
src/main/java/com/caimei/model/po/PromotionsPo.java

@@ -1,11 +1,13 @@
 package com.caimei.model.po;
 
+import com.caimei.model.vo.CartProductVo;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Description
@@ -63,4 +65,9 @@ public class PromotionsPo implements Serializable {
      * 主订单id
      */
     private Integer orderId;
+
+    /**
+     * 满赠商品
+     */
+    private List<CartProductVo> productGifts;
 }

+ 5 - 0
src/main/java/com/caimei/model/vo/CartProductVo.java

@@ -95,6 +95,11 @@ public class CartProductVo implements Serializable {
      */
     private Integer productCount;
 
+    /**
+     * 是否是赠品 2是,其他否
+     */
+    private Integer productType;
+
     /**
      * 前端选中状态
      */

+ 5 - 0
src/main/java/com/caimei/model/vo/CityVo.java

@@ -15,6 +15,11 @@ import java.util.List;
 public class CityVo implements Serializable {
     private Integer cityId;
 
+    /**
+     * 所属省ID
+     */
+    private Integer provinceId;
+
     /**
      * 名称
      */

+ 13 - 5
src/main/java/com/caimei/service/OrderSubmitService.java

@@ -16,17 +16,14 @@ public interface OrderSubmitService {
      * 商品结算
      *
      * @param productIds 商品ID串用逗号隔开。
-     * @param count      立即购买商品数量,购物车count为null。
      * @param userId     机构用户id。
      * @return
      */
-    ResponseJson<Map<String, Object>> orderConfirm(String productIds, Integer count, Integer userId);
+    ResponseJson<Map<String, Object>> orderConfirm(String productIds, Integer userId);
 
     /**
      * 提交订单
      *
-     * @param cartType
-     * @param orderSource
      * @param clubUserId
      * @param addressId
      * @param orderInfo
@@ -34,5 +31,16 @@ public interface OrderSubmitService {
      * @param orderInvoice
      * @return
      */
-    ResponseJson<Map<String, String>> orderSubmit(Integer cartType, String orderSource, Integer clubUserId, Integer addressId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo, Map<String, Object> orderInvoice);
+    ResponseJson<Map<String, String>> orderSubmit(Integer clubUserId, Integer addressId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo, Map<String, Object> orderInvoice);
+
+    /**
+     * 运费规则
+     *
+     * @param productIds
+     * @param totalPrice
+     * @param townId
+     * @param userId
+     * @return
+     */
+    ResponseJson<Map<String, Object>> orderPostage(String productIds, Double totalPrice, Integer townId, Integer userId);
 }

+ 1 - 1
src/main/java/com/caimei/service/impl/AddressServiceImpl.java

@@ -97,6 +97,6 @@ public class AddressServiceImpl implements AddressService {
     @Override
     public ResponseJson<CmUserInvoiceInfoPo> findInvoice(Integer userId) {
         CmUserInvoiceInfoPo invoice = addressMapper.findInvoice(userId);
-        return null;
+        return ResponseJson.success(invoice);
     }
 }

+ 80 - 42
src/main/java/com/caimei/service/impl/OrderSubmitServiceImpl.java

@@ -5,16 +5,14 @@ import com.caimei.mapper.ProductMapper;
 import com.caimei.mapper.ShoppingCartMapper;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.po.*;
-import com.caimei.model.vo.AddressVo;
-import com.caimei.model.vo.CartProductVo;
-import com.caimei.model.vo.LadderPriceVo;
-import com.caimei.model.vo.ShopVo;
+import com.caimei.model.vo.*;
 import com.caimei.service.OrderSubmitService;
 import com.caimei.service.ShoppingCartService;
 import com.caimei.util.MathUtil;
 import com.caimei.util.OrderNoUtils;
 import com.caimei.util.ProductUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -48,7 +46,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
     private String domain;
 
     @Override
-    public ResponseJson<Map<String, Object>> orderConfirm(String productIds, Integer count, Integer userId) {
+    public ResponseJson<Map<String, Object>> orderConfirm(String productIds, Integer userId) {
         Map<String, Object> confirmData = new HashMap<>(5);
         if (userId != null) {
             log.info("<<<<< 结算订单 >>>>>");
@@ -60,19 +58,12 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
             List<ShopVo> shopList = orderSubmitMapper.findShopByproductIds(productId);
             shopList.forEach(shop -> {
                 shopIds.add(shop.getShopId());
-                List<CartProductVo> products = new ArrayList<>();
-                if (null == count) {
-                    //购物车购买
-                    products = orderSubmitMapper.findProductListByCart(shop.getShopId(), productId);
-                } else {
-                    //直接立即购买
-                    products.add(orderSubmitMapper.findCartByProductId(productId[0]));
-                    products.get(0).setProductCount(count);
-                }
+                //购物车购买
+                List<CartProductVo> products = orderSubmitMapper.findProductListByCart(shop.getShopId(), productId);
                 BigDecimal shopTotalPrice = BigDecimal.ZERO;
                 for (CartProductVo product : products) {
                     productGifts.addAll(shoppingCartService.setProductPrice(product));
-                    shopTotalPrice = MathUtil.add(shopTotalPrice, product.getRetailPrice());
+                    shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getProductCount(), product.getRetailPrice()));
                 }
                 shop.setShopTotalPrice(shopTotalPrice);
                 shop.setProductList(products);
@@ -81,6 +72,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
             //单品满赠
             if (productGifts.size() > 0) {
                 for (CartProductVo productGift : productGifts) {
+                    productGift.setProductType(2);
                     if (shopIds.contains(productGift.getShopId())) {
                         shopList.forEach(shop -> {
                             if (productGift.getShopId().equals(shop.getShopId())) {
@@ -110,7 +102,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public ResponseJson<Map<String, String>> orderSubmit(Integer cartType, String orderSource, Integer clubUserId, Integer addressId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo, Map<String, Object> orderInvoice) {
+    public ResponseJson<Map<String, String>> orderSubmit(Integer clubUserId, Integer addressId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo, Map<String, Object> orderInvoice) {
         /*
          * 逻辑处理 start
          */
@@ -134,8 +126,6 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         BigDecimal payTotalFee = BigDecimal.ZERO;
         // 真实支付金额(订单总额减去抵扣的账户余额)
         BigDecimal payableAmount = BigDecimal.ZERO;
-        // 余额支付金额
-        BigDecimal balancePayFee = BigDecimal.ZERO;
         // 促销满减优惠
         BigDecimal promotionFullReduction = BigDecimal.ZERO;
         // 运费
@@ -181,7 +171,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         // 机构ID
         order.setClubID(user.getClubID().longValue());
         // 订单来源
-        order.setOrderSource(orderSource);
+        order.setOrderSource("6");
         order.setOrganizeID(user.getUserOrganizeID());
         order.setUpdateDate(curDateStr);
         order.setPayFlag("0");
@@ -230,8 +220,6 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
              * 整理订单商品信息
              */
             if (!CollectionUtils.isEmpty(productInfoList)) {
-                // 商品信息ids
-                List<Integer> productIds = new ArrayList<>();
                 // 遍历所有商品
                 for (Map<String, Integer> productTemp : productInfoList) {
                     Integer productId = productTemp.get("productId");
@@ -239,7 +227,6 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                     Integer presentNum = productTemp.get("presentNum");
                     Integer productType = productTemp.get("productType");
                     productType = null == productType ? 0 : productType;
-                    productIds.add(productId);
                     // 统计商品总数量
                     productCount += productNum;
                     // 赠品数
@@ -392,10 +379,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         // 订单总额(商品金额+运费)
         if (1 == freePostFlag) {
             // 机构用户 计算商品运费
-            if (cartType != 3 && null != address) {
-                Double freightFee = computedPostageFee(address.getProvinceId(), address.getCityId());
-                freight = BigDecimal.valueOf(freightFee);
-            }
+            Double freightFee = computedPostageFee(address.getProvinceId(), address.getCityId());
+            freight = BigDecimal.valueOf(freightFee);
             order.setFreight(freight);
             payTotalFee = MathUtil.add(productTotalFee, freight);
         } else {
@@ -406,18 +391,11 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         order.setPayTotalFee(payTotalFee);
         payableAmount = payTotalFee;
         // 订单状态
-        if (cartType == 3) {
-            // 协销用户
-            order.setStatus("0");
-        } else {
-            // 机构用户
-            order.setStatus("11");
-            order.setConfirmTime(curDateStr);
-        }
-        // 是否完成支付(默认不是,只有余额抵扣才算)
-        boolean isPaySuccessFlag = false;
+        order.setStatus("11");
+        order.setConfirmTime(curDateStr);
+
         // 余额支付金额
-        order.setBalancePayFee(balancePayFee);
+        order.setBalancePayFee(BigDecimal.ZERO);
         // 实际支付金额(商品金额+运费-余额抵扣)
         order.setPayableAmount(payableAmount);
         // 售后条款
@@ -586,6 +564,71 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         return ResponseJson.success(info);
     }
 
+    @Override
+    public ResponseJson<Map<String, Object>> orderPostage(String productIds, Double totalPrice, Integer townId, Integer userId) {
+        List<String> productIdList = new ArrayList<>();
+        if (productIds.contains(",")) {
+            productIdList = Arrays.asList(productIds.split(","));
+        } else {
+            productIdList.add(productIds);
+        }
+        if (productIdList.size() == 0 || null == totalPrice || null == townId || null == userId) {
+            return ResponseJson.error("参数错误", null);
+        }
+        log.info("<<<<<<<<<<<<<<<<<<<<<<<<计算运费>>>>>>>>>>>>>>>>>>>>>>>>");
+        // 默认运费到付
+        Map<String, Object> postageFeeMap = new HashMap<>(2);
+        postageFeeMap.put("freePostFlag", -1);
+        postageFeeMap.put("freight", 0);
+        //商品是否全部设置为包邮
+        boolean isFreeShipping = true;
+        // 是否包含仪器(1001:轻光电,1002:重光电)
+        for (String s : productIdList) {
+            if ("".equals(s) || "undefined".equals(s) || null == s) {
+                return ResponseJson.error("参数错误", null);
+            }
+            ProductPo product = orderSubmitMapper.findProductById(Integer.parseInt(s));
+            //商品是否设置到付
+            boolean isToPay = product.getFreePostFlag() != null && "1".equals(product.getFreePostFlag());
+            if ("2".equals(product.getCommodityType()) || isToPay) {
+                // 仪器运费到付
+                postageFeeMap.put("freePostFlag", -1);
+                postageFeeMap.put("freight", 0);
+                log.info("<<<<<<<<<<<<<<<<<<<<<<<<运费到付");
+                return ResponseJson.success("运费到付", postageFeeMap);
+            }
+            //商品是否全部设置为包邮
+            if (StringUtils.isBlank(product.getFreePostFlag()) || "2".equals(product.getFreePostFlag())) {
+                isFreeShipping = false;
+            }
+        }
+        // 是否首单(订单数)
+        Integer count = orderSubmitMapper.countUserOrder(userId);
+        if (Integer.valueOf(0).equals(count) || isFreeShipping) {
+            postageFeeMap.put("freePostFlag", 0);
+            postageFeeMap.put("freight", 0);
+            // 除含有仪器类外 首单,全国包邮
+            log.info("<<<<<<<<<<<<<<<<<<<<<<<<包邮");
+            return ResponseJson.success("包邮", postageFeeMap);
+        }
+        // 总运费计算
+        CityVo city = orderSubmitMapper.findCityByTownId(townId);
+        Double totalPostageFee = computedPostageFee(city.getProvinceId(), city.getCityId());
+        if (totalPostageFee == 0d) {
+            postageFeeMap.put("freePostFlag", 0);
+            postageFeeMap.put("freight", 0);
+            log.info("<<<<<<<<<<<<<<<<<<<<<<<<包邮");
+            return ResponseJson.success("包邮", postageFeeMap);
+        } else if (totalPostageFee != -1d) {
+            postageFeeMap.put("freePostFlag", 1);
+            postageFeeMap.put("freight", totalPostageFee);
+            log.info("<<<<<<<<<<<<<<<<<<<<<<<<运费金额:" + totalPostageFee);
+            return ResponseJson.success("运费金额", postageFeeMap);
+        }
+        log.info("<<<<<<<<<<<<<<<<<<<<<<<<运费到付");
+        return ResponseJson.success("运费到付", postageFeeMap);
+    }
+
     /**
      * 设置订单发票
      *
@@ -824,11 +867,6 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         }
         shopOrder.setShopID(shopId);
         shopOrder.setClubID(order.getClubID().intValue());
-        if (null != order.getSpID()) {
-            // 协销下单 则设置协销ID
-            shopOrder.setSpID(order.getSpID().intValue());
-            shopOrder.setMainSpID(order.getMainSpID().intValue());
-        }
         shopOrder.setOrderID(order.getOrderID());
         shopOrder.setOrderNo(order.getOrderNo());
         shopOrder.setUserID(order.getUserID().intValue());

+ 17 - 219
src/main/java/com/caimei/service/impl/PayOrderServiceImpl.java

@@ -1,12 +1,17 @@
 package com.caimei.service.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.caimei.mapper.OrderMapper;
 import com.caimei.mapper.PayOrderMapper;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.PaymentDto;
-import com.caimei.model.po.*;
-import com.caimei.model.vo.*;
+import com.caimei.model.po.CmDiscernReceiptPo;
+import com.caimei.model.po.CmReceiptOrderRelationPo;
+import com.caimei.model.po.UserPo;
+import com.caimei.model.vo.DiscernReceiptVo;
+import com.caimei.model.vo.OrderPayLinkVo;
+import com.caimei.model.vo.OrderProductVo;
+import com.caimei.model.vo.OrderVo;
 import com.caimei.service.PayOrderService;
 import com.caimei.util.MathUtil;
 import com.caimei.util.Md5Util;
@@ -37,6 +42,8 @@ import java.util.*;
 public class PayOrderServiceImpl implements PayOrderService {
     @Resource
     private PayOrderMapper payOrderMapper;
+    @Resource
+    private OrderMapper orderMapper;
 
     /**
      * 商户标识
@@ -54,18 +61,6 @@ public class PayOrderServiceImpl implements PayOrderService {
      * 用户编号
      */
     String merNo = "10001720";
-    /**
-     * 公账-专票,子商户商编
-     */
-    String publicAccountNo = "20001793";
-    /**
-     * 公账-普票,子商户商编
-     */
-    String commonInvoiceNo = "20001754";
-    /**
-     * 私账-无票,子商户商编
-     */
-    String privateAccountNo = "20001924";
 
     /**
      * 获取线上支付开关状态
@@ -81,7 +76,7 @@ public class PayOrderServiceImpl implements PayOrderService {
     @Override
     public ResponseJson<Map<String, Object>> checkoutCounter(Integer orderId) {
         Map<String, Object> map = new HashMap<>();
-        OrderVo order = payOrderMapper.findOrder(orderId);
+        OrderVo order = orderMapper.findOrder(orderId);
         if (null == order) {
             return ResponseJson.error("订单不存在", null);
         }
@@ -122,7 +117,7 @@ public class PayOrderServiceImpl implements PayOrderService {
     @Override
     public synchronized ResponseJson<JSONObject> pay(PaymentDto payment) {
         JSONObject result = null;
-        OrderVo order = payOrderMapper.findOrder(payment.getOrderId());
+        OrderVo order = orderMapper.findOrder(payment.getOrderId());
         if (null == order) {
             return ResponseJson.error("订单不存在", null);
         }
@@ -142,7 +137,6 @@ public class PayOrderServiceImpl implements PayOrderService {
         if (MathUtil.compare(MathUtil.mul(order.getPayableAmount(), 100), payment.getPayAmount()) < 0) {
             return ResponseJson.error("付款金额错误", null);
         }
-        //List<SplitAccountVo> splitBillDetail = null;
         try {
             // 时间戳
             long time = System.currentTimeMillis() / 1000;
@@ -157,11 +151,6 @@ public class PayOrderServiceImpl implements PayOrderService {
             String payType = getPayType(payment);
             String attach = order.getOrderId() + "," + payType;
             json.put("attach", attach);
-            //分账详情
-            /*splitBillDetail = splitBillDetail(order, payment);
-            String parameters = ledgerParameters(splitBillDetail, order.getOrderID());
-            log.info("分账参数: " + parameters);
-            json.put("splitBillDetail", parameters);*/
             String sign = PayUtils.buildSign(json, merKey);
             json.put("sign", sign);
             String data = PayUtils.buildDataPrivate(json, merKey);
@@ -176,74 +165,9 @@ public class PayOrderServiceImpl implements PayOrderService {
             log.info("第三方支付失败>>>>>>>msg:" + msg);
             return ResponseJson.error(msg, null);
         }
-
-        //保存分账信息
-        //saveSplitBillDetail(splitBillDetail, result);
         return ResponseJson.success(result);
     }
 
-    /**
-     * 整理第三方支付详情参数
-     */
-    private String ledgerParameters(List<SplitAccountVo> splitBillDetail, Integer orderId) {
-        List<Map<String, String>> maps = new ArrayList<>();
-        List<ShopOrderVo> shopOrderList = payOrderMapper.findShopOrder(orderId);
-        //供应商子商户总金额
-        for (ShopOrderVo shopOrder : shopOrderList) {
-            BigDecimal shopTotalAmount = BigDecimal.ZERO;
-            String subUserNo = "";
-            for (SplitAccountVo account : splitBillDetail) {
-                if ("4".equals(account.getType()) && shopOrder.getShopId().equals(account.getShopId())) {
-                    shopTotalAmount = MathUtil.add(shopTotalAmount, account.getSplitAccount());
-                    subUserNo = account.getSubUserNo();
-                }
-            }
-            addMaps(maps, shopTotalAmount, subUserNo);
-        }
-        //公账-专票总金额,私账-无票总金额,公账-普票总金额
-        BigDecimal totalAmount1 = BigDecimal.ZERO;
-        BigDecimal totalAmount2 = BigDecimal.ZERO;
-        BigDecimal totalAmount3 = BigDecimal.ZERO;
-        for (SplitAccountVo account : splitBillDetail) {
-            if ("1".equals(account.getType())) {
-                totalAmount1 = MathUtil.add(totalAmount1, account.getSplitAccount());
-            } else if ("2".equals(account.getType())) {
-                totalAmount2 = MathUtil.add(totalAmount2, account.getSplitAccount());
-            } else if ("3".equals(account.getType())) {
-                totalAmount3 = MathUtil.add(totalAmount3, account.getSplitAccount());
-            }
-        }
-        addMaps(maps, totalAmount1, publicAccountNo);
-        addMaps(maps, totalAmount2, privateAccountNo);
-        addMaps(maps, totalAmount3, commonInvoiceNo);
-        return JSON.toJSONString(maps);
-    }
-
-    private void addMaps(List<Map<String, String>> maps, BigDecimal shopTotalAmount, String subUserNo) {
-        if (MathUtil.compare(shopTotalAmount, 0) > 0) {
-            Map<String, String> map = new HashMap<>(3);
-            map.put("subUserNo", subUserNo);
-            map.put("splitBillType", "2");
-            map.put("splitBillValue", MathUtil.mul(shopTotalAmount, 100).toString());
-            maps.add(map);
-        }
-    }
-
-    /**
-     * 保存分账信息
-     */
-    private void saveSplitBillDetail(List<SplitAccountVo> splitBillDetail, JSONObject result) {
-        JSONObject data = result.getJSONObject("data");
-        String mbOrderId = data.getString("mbOrderId");
-        String orderRequestNo = data.getString("orderId");
-        for (SplitAccountVo splitAccount : splitBillDetail) {
-            splitAccount.setMbOrderId(mbOrderId);
-            splitAccount.setOrderRequestNo(orderRequestNo);
-            splitAccount.setPayStatus("0");
-            payOrderMapper.insertSplitAccount(splitAccount);
-        }
-    }
-
     /**
      * 设置第三方支付参数
      */
@@ -270,130 +194,6 @@ public class PayOrderServiceImpl implements PayOrderService {
         return json;
     }
 
-    /**
-     * 分账详情
-     */
-    private List<SplitAccountVo> splitBillDetail(OrderVo order, PaymentDto payment) {
-        List<SplitAccountVo> list = new ArrayList<>();
-        //本次支付金额,单位/元
-        BigDecimal payAmount = MathUtil.div(payment.getPayAmount(), 100);
-        //待分账总金额
-        BigDecimal splitAmount = payAmount;
-        //总手续费
-        BigDecimal procedureFee = BigDecimal.ZERO;
-        if ("UNIONPAY".equals(payment.getPayWay())) {
-            procedureFee = new BigDecimal(8);
-        } else {
-            //手续费
-            procedureFee = MathUtil.mul(payAmount, 0.0038, 2);
-            if (MathUtil.compare(procedureFee, 0) == 0) {
-                procedureFee = new BigDecimal("0.01");
-            }
-        }
-        splitAmount = MathUtil.sub(splitAmount, procedureFee);
-        List<OrderProductVo> orderProductList = payOrderMapper.findAllOrderProduct(order.getOrderId());
-        for (OrderProductVo orderProduct : orderProductList) {
-            BigDecimal costPrice = MathUtil.mul(orderProduct.getCostPrice(), orderProduct.getNum());
-            //不含税能开发票
-            if ("0".equals(orderProduct.getIncludedTax()) && !"3".equals(orderProduct.getInvoiceType())) {
-                //应付总税费
-                BigDecimal payableTax = MathUtil.mul(orderProduct.getSingleShouldPayTotalTax(), orderProduct.getNum());
-                costPrice = MathUtil.add(costPrice, payableTax);
-            }
-            //判断是否支付过
-            BigDecimal paidAmount = payOrderMapper.findPaidAmount(orderProduct.getOrderProductId());
-            if (paidAmount == null || MathUtil.compare(paidAmount, costPrice) < 0) {
-                if (paidAmount != null && MathUtil.compare(paidAmount, 0) > 0) {
-                    costPrice = MathUtil.sub(costPrice, paidAmount);
-                }
-                //待分账金额>=本次待分账金额
-                if (MathUtil.compare(splitAmount, costPrice) > -1) {
-                    splitAmount = MathUtil.sub(splitAmount, costPrice);
-                } else {
-                    costPrice = splitAmount;
-                    splitAmount = BigDecimal.ZERO;
-                }
-                String commercialCode = payOrderMapper.findCommercialCode(orderProduct.getShopId());
-                SplitAccountVo splitAccount = new SplitAccountVo();
-                splitAccount.setOrderId(order.getOrderId());
-                splitAccount.setOrderProductId(orderProduct.getOrderProductId());
-                splitAccount.setShopId(orderProduct.getShopId().intValue());
-                splitAccount.setSplitAccount(costPrice);
-                splitAccount.setProductType("1");
-                if (StringUtils.isNotBlank(commercialCode)) {
-                    //供应商拥有子商户号
-                    splitAccount.setType("4");
-                    splitAccount.setSubUserNo(commercialCode);
-                } else {
-                    if ("3".equals(orderProduct.getInvoiceType())) {
-                        //不能开票,则分账到私账-无票
-                        splitAccount.setType("2");
-                        splitAccount.setSubUserNo(privateAccountNo);
-                    } else if ("1".equals(orderProduct.getInvoiceType())) {
-                        //开增值税发票,则分账到公账-专票
-                        splitAccount.setType("1");
-                        splitAccount.setSubUserNo(publicAccountNo);
-                    } else if ("2".equals(orderProduct.getInvoiceType())) {
-                        //开普通发票,则分账到公账-普票
-                        splitAccount.setType("3");
-                        splitAccount.setSubUserNo(commonInvoiceNo);
-                    }
-                }
-                list.add(splitAccount);
-                if (MathUtil.compare(splitAmount, 0) == 0) {
-                    break;
-                }
-            }
-        }
-
-        //付供应商运费,是以供应商为单位的
-        if (MathUtil.compare(splitAmount, 0) > 0) {
-            List<ShopOrderVo> shopOrderList = payOrderMapper.findShopOrder(order.getOrderId());
-            for (ShopOrderVo shopOrder : shopOrderList) {
-                //运费
-                BigDecimal shopPostFee = shopOrder.getShopPostFee();
-                if (MathUtil.compare(shopPostFee, 0) > 0) {
-                    BigDecimal shipping = payOrderMapper.findShipping(order.getOrderId(), shopOrder.getShopId());
-                    shopPostFee = MathUtil.sub(shopPostFee, shipping);
-                    if (MathUtil.compare(splitAmount, shopPostFee) > -1) {
-                        splitAmount = MathUtil.sub(splitAmount, shipping);
-                    } else {
-                        shopPostFee = splitAmount;
-                        splitAmount = BigDecimal.ZERO;
-                    }
-                    String commercialCode = payOrderMapper.findCommercialCode(Long.valueOf(shopOrder.getShopId()));
-                    SplitAccountVo splitAccount = new SplitAccountVo();
-                    splitAccount.setOrderId(order.getOrderId());
-                    splitAccount.setShopId(shopOrder.getShopId());
-                    splitAccount.setSplitAccount(shopPostFee);
-                    splitAccount.setProductType("2");
-                    if (StringUtils.isNotBlank(commercialCode)) {
-                        //供应商拥有子商户号
-                        splitAccount.setType("4");
-                        splitAccount.setSubUserNo(commercialCode);
-                    } else {
-                        //私账
-                        splitAccount.setType("2");
-                        splitAccount.setSubUserNo(privateAccountNo);
-                    }
-                    list.add(splitAccount);
-                }
-            }
-        }
-
-        //佣金,私账
-        if (MathUtil.compare(splitAmount, 0) > 0) {
-            SplitAccountVo splitAccount = new SplitAccountVo();
-            splitAccount.setOrderId(order.getOrderId());
-            splitAccount.setSplitAccount(splitAmount);
-            splitAccount.setProductType("3");
-            splitAccount.setType("2");
-            splitAccount.setSubUserNo(privateAccountNo);
-            list.add(splitAccount);
-        }
-        return list;
-    }
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String paymentCallback(String data) throws Exception {
@@ -426,7 +226,7 @@ public class PayOrderServiceImpl implements PayOrderService {
         Integer orderId = Integer.valueOf(split[0]);
         //支付类型
         String payType = split[1];
-        OrderVo order = payOrderMapper.findOrder(orderId);
+        OrderVo order = orderMapper.findOrder(orderId);
         //支付记录
         List<DiscernReceiptVo> discernReceiptList = payOrderMapper.getDiscernReceipt(order);
         BigDecimal receiptAmount = BigDecimal.ZERO;
@@ -506,8 +306,6 @@ public class PayOrderServiceImpl implements PayOrderService {
         relation.setSplitStatus("0");
         payOrderMapper.insertOrderRelation(relation);
         log.info(">>>>>>>>>>>>>>>>>>>>>>>保存付款金额到收款记录," + amount);
-        //修改分账付款状态
-        //payOrderMapper.updateSplitAccountByPay(mbOrderId);
         return "SUCCESS";
     }
 
@@ -539,7 +337,7 @@ public class PayOrderServiceImpl implements PayOrderService {
         if (null == orderPayLink) {
             return ResponseJson.error("参数异常", null);
         }
-        OrderVo order = payOrderMapper.findOrder(orderPayLink.getOrderId().intValue());
+        OrderVo order = orderMapper.findOrder(orderPayLink.getOrderId().intValue());
         if (null == order) {
             return ResponseJson.error("订单不存在", null);
         }
@@ -586,9 +384,9 @@ public class PayOrderServiceImpl implements PayOrderService {
         int code = 0;
         if (null == orderPayLink) {
             //已重新生成链接
-            return ResponseJson.error("链接更新,请重新获取");
+            return ResponseJson.error("链接更新,请重新获取", null);
         } else {
-            OrderVo order = payOrderMapper.findOrder(orderPayLink.getOrderId().intValue());
+            OrderVo order = orderMapper.findOrder(orderPayLink.getOrderId().intValue());
             List<DiscernReceiptVo> discernReceiptList = payOrderMapper.getDiscernReceipt(order);
             if (orderPayLink.getEffectiveTime().compareTo(new Date()) < 0) {
                 //链接失效
@@ -617,7 +415,7 @@ public class PayOrderServiceImpl implements PayOrderService {
 
     @Override
     public ResponseJson<String> payWhetherSuccess(Integer orderId, Integer paySuccessCounter) {
-        OrderVo order = payOrderMapper.findOrder(orderId);
+        OrderVo order = orderMapper.findOrder(orderId);
         if (order.getPaySuccessCounter().equals(paySuccessCounter)) {
             return ResponseJson.error(-2, "支付失败", null);
         } else if (order.getPaySuccessCounter() > paySuccessCounter) {

+ 7 - 4
src/main/java/com/caimei/service/impl/ShoppingCartServiceImpl.java

@@ -66,7 +66,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
             List<CartProductVo> productList = shoppingCartMapper.findByShopCartProduct(shop.getShopId(), userId);
             for (CartProductVo product : productList) {
                 setProductPrice(product);
-                shopTotalPrice = MathUtil.add(shopTotalPrice, product.getRetailPrice());
+                shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getProductCount(), product.getRetailPrice()));
             }
             shop.setShopTotalPrice(shopTotalPrice);
             shop.setProductList(productList);
@@ -91,6 +91,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
         boolean addTaxFlag = (0 == product.getIncludedTax() && (1 == product.getInvoiceType() || 2 == product.getInvoiceType()));
         // 设置图片
         product.setMainImage(ProductUtils.getImageURL("product", product.getMainImage(), 0, domain));
+        product.setRetailPrice(product.getPrice());
         // 设置商品展示价格
         PromotionsPo activity = productMapper.findPromotionByProductId(product.getProductId());
         if (null != activity) {
@@ -106,15 +107,17 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
                     BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getRetailPrice(), product.getClubTaxPoint()), 100);
                     totalPrice = MathUtil.add(totalPrice, addedValueTax);
                 }
+                if (activity.getMode() == 3) {
+                    List<CartProductVo> gifts = shoppingCartMapper.findProductGifts(activity.getId());
+                    activity.setProductGifts(gifts);
+                }
                 if (MathUtil.compare(totalPrice, activity.getTouchPrice()) > -1) {
                     if (activity.getMode() == 2) {
                         BigDecimal retailPrice = MathUtil.sub(product.getPrice(), activity.getReducedPrice());
                         product.setRetailPrice(retailPrice);
                     } else {
-                        productGifts = shoppingCartMapper.findProductGifts(activity.getId());
+                        productGifts = activity.getProductGifts();
                     }
-                } else {
-                    product.setRetailPrice(product.getPrice());
                 }
             }
         } else if (1 == product.getLadderPriceFlag()) {

+ 2 - 1
src/main/resources/mapper/AddressMapper.xml

@@ -56,7 +56,7 @@
           addressID = #{addressId}
     </update>
 
-    <insert id="insertAddress" useGeneratedKeys="true" keyProperty="addressID" keyColumn="addressID" parameterType="com.caimei.model.vo.AddressVo">
+    <insert id="insertAddress" useGeneratedKeys="true" keyProperty="addressId" keyColumn="addressID" parameterType="com.caimei.model.vo.AddressVo">
         INSERT INTO address (
           userID, shouHuoRen, townID, address,
           mobile, defaultFlag
@@ -89,6 +89,7 @@
     <select id="findAllCity" resultType="com.caimei.model.vo.CityVo">
         SELECT
           cityID AS cityId,
+          provinceID AS provinceId,
           name
         FROM
           city

+ 51 - 2
src/main/resources/mapper/OrderSubmitMapper.xml

@@ -3,6 +3,29 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.OrderSubmitMapper">
+    <sql id="Product_Column_List">
+        p.productID, p.brandID,p.bigTypeID,p.smallTypeID, p.tinyTypeID,p.productCategory, p.preferredFlag, p.selfTypeID, p.shopID, p.`name`, p.aliasName, p.searchKey, p.productRemarks,
+        p.normalPrice, p.price, p.highestUserLevelPrice, lowestUserLevelPrice, p.lowestUserLevelID,
+        p.price0, p.price0Grade, p.price0Text, price0TextFlag, price1, p.price1Grade, p.price1Text,
+        p.price1TextFlag, p.price8, p.price8Grade, p.price8Text, p.price8Text as beautyActFlag, p.price8TextFlag, p.ladderPriceFlag,
+        p.price2, p.price3, p.price4, p.price5, p.price6, p.price7, p.fee, p.stock, p.hasSkuFlag, p.mainImage,
+        p.propertiesInfo, p.addTime, p.updateTime, p.sellNumber, p.weekSellNumber, p.beforeValidFlag,
+        p.validFlag, p.favoriteTimes, p.commentScore, p.commentTimes, p.selfRecommendFlag, p.sysRecommendFlag,
+        p.sortIndex, p.featuredFlag, p.featuredSortIndex, p.productCode, p.rate1, p.rate2, p.unit, p.synToERPFlag,
+        p.allAreaFlag, p.provinceIDs, p.serviceNumber, p.maxBuyNumber, p.virtualFlag, p.minBuyNumber,
+        p.packageCount, p.byFlag, p.normalProductFlag, p.wholeSaleProductFlag, p.promotionProductFlag,
+        p.groupBuyProductFlag, p.step, p.speCommisionFlag, p.speCommision, p.videourl, p.props, p.providers,
+        p.serviceCommissionRatio, p.reCommissionRatio, p.pushToERPName, p.prodBeans, p.useBeansFlag,
+        p.privateFlag, p.invisibleServiceProviderIDs, p.displayOnCRMFlag, p.needServiceFlag, p.actFlag, p.actStatus,
+        p.actSort, p.actPrice0, p.actPrice1, p.actPrice2, p.actPrice3, p.actPrice4, p.actPrice5, p.actPrice6,
+        p.actPrice7, p.actType, p.actCreateTime, p.beginTime, p.endTime, p.shopIndexModuleID, p.onlineTime,
+        p.downlineTime, p.freePostFlag, p.crmBigTypeId, p.crmSmallTypeId, p.costPrice, p.costProportional,
+        p.costCheckFlag, p.precisehKey, p.docBoost, p.cmbeanFlag, p.cmbeanPrice, p.cmbeanSort, p.actBuyGiftNum,
+        p.actFullGiftAmount, p.actFullReduceAmount, p.actReduceAmount, p.visibility, p.surplusTime,
+        p.priceType, p.tags, p.recommendType, p.machineType, p.taxPoint, p.supplierTaxPoint, p.includedTax,
+        p.invoiceType,p.commodityType
+    </sql>
+
     <select id="findShopByproductIds" resultType="com.caimei.model.vo.ShopVo">
         SELECT
           s.shopID AS shopId,
@@ -14,7 +37,7 @@
           LEFT JOIN shop s ON p.shopID = s.shopID
           LEFT JOIN cm_mall_cart cmc ON cop.id = cmc.productID
         WHERE
-          p.productID IN
+          cop.id IN
         <foreach item="productId" index="index" collection="productIds" open="(" separator="," close=")">
             #{productId}
         </foreach>
@@ -40,7 +63,7 @@
           LEFT JOIN product p ON cop.productId = p.productID
           LEFT JOIN cm_mall_cart cmc ON cop.id = cmc.productID
         WHERE
-          p.productID IN
+          cop.id IN
         <foreach item="productId" index="index" collection="productIds" open="(" separator="," close=")">
             #{productId}
         </foreach>
@@ -1774,4 +1797,30 @@
                  LEFT JOIN province p ON p.provinceID = c.provinceID
         WHERE a.addressID = #{addressId}
     </select>
+
+    <select id="findProductById" resultType="com.caimei.model.po.ProductPo">
+        select
+            <include refid="Product_Column_List" />
+        FROM
+        cm_organize_product cop
+        LEFT JOIN product p ON cop.productId = p.productID
+        where cop.id = #{productId}
+    </select>
+
+    <select id="countUserOrder" resultType="java.lang.Integer">
+        SELECT COUNT(*) FROM cm_order
+        WHERE userID = #{userId}
+        AND delFlag=0 AND STATUS != 6
+    </select>
+
+    <select id="findCityByTownId" resultType="com.caimei.model.vo.CityVo">
+        SELECT
+          cityID AS cityId,
+          provinceID AS provinceId,
+          name
+        FROM city
+        WHERE cityID =(
+            SELECT cityID from town where townID = #{townId}
+        )
+    </select>
 </mapper>

+ 0 - 76
src/main/resources/mapper/PayOrderMapper.xml

@@ -3,16 +3,6 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.PayOrderMapper">
-    <select id="findOrder" resultType="com.caimei.model.vo.OrderVo">
-        SELECT
-          *
-        FROM
-          cm_order
-        WHERE
-          orderID = #{orderID}
-          AND delFlag = '0'
-    </select>
-
     <select id="getDiscernReceipt" resultType="com.caimei.model.vo.DiscernReceiptVo">
         SELECT
           cdr.*,
@@ -372,70 +362,4 @@
     <select id="getPayOnLineSwitch" resultType="java.lang.Integer">
         select status from cm_pay_online_switch where id=1
     </select>
-
-    <insert id="insertSplitAccount" keyColumn="id" keyProperty="id" parameterType="com.caimei.model.vo.SplitAccountVo" useGeneratedKeys="true">
-        INSERT INTO `cm_split_account` (
-          `orderId`, `productId`, `orderProductId`,
-          `shopId`, `type`, `subUserNo`, `splitAccount`,
-          `mbOrderId`, `orderRequestNo`,
-          `payStatus`, `productType`, splitTime
-        )
-        VALUES
-          (
-            #{orderId}, #{productId}, #{orderProductId},
-            #{shopId}, #{type}, #{subUserNo}, #{splitAccount},
-            #{mbOrderId}, #{orderRequestNo},
-            #{payStatus}, #{productType}, NOW()
-          );
-    </insert>
-
-    <select id="findCommercialCode" resultType="string">
-        SELECT commercialCode FROM shop WHERE shopID = #{shopId}
-    </select>
-
-    <select id="findPaidAmount" resultType="java.math.BigDecimal">
-        SELECT
-          SUM(splitAccount)
-        FROM
-          cm_split_account
-        WHERE
-          orderProductId = #{orderProductId}
-          AND payStatus = 1
-          AND productType = 1
-    </select>
-
-    <select id="findShopOrder" resultType="com.caimei.model.vo.ShopOrderVo">
-        SELECT * FROM cm_shop_order WHERE orderID = #{orderId}
-    </select>
-
-    <select id="findShipping" resultType="java.math.BigDecimal">
-        SELECT
-          SUM(splitAccount)
-        FROM
-          cm_split_account
-        WHERE
-          orderId = #{orderId}
-          AND shopId = #{shopId}
-          AND productType = 2
-          AND payStatus = 1
-    </select>
-
-    <update id="updateShopOrderByPayStatus">
-        UPDATE
-          cm_shop_order
-        SET
-          payStatus = #{payStatus},
-          payedShopAmount = #{paidShop}
-        WHERE
-          shopOrderID = #{shopOrderId}
-    </update>
-
-    <update id="updateOrderByPayStatus">
-        UPDATE
-          cm_order
-        SET
-          payStatus = #{payStatus}
-        WHERE
-          orderID = #{orderId}
-    </update>
 </mapper>