Browse Source

确认订单

chao 3 years ago
parent
commit
66c227a5ac

+ 115 - 4
src/main/java/com/caimei365/order/components/ProductService.java

@@ -1,6 +1,7 @@
 package com.caimei365.order.components;
 
 import com.caimei365.order.mapper.BaseMapper;
+import com.caimei365.order.model.po.*;
 import com.caimei365.order.model.vo.*;
 import com.caimei365.order.utils.MathUtil;
 import com.caimei365.order.utils.ImageUtil;
@@ -12,10 +13,8 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.IntStream;
 
 /**
@@ -222,4 +221,116 @@ public class ProductService {
         }
     }
 
+    /**
+     * 更新复购价格库
+     * @param order         主订单
+     * @param orderProduct  订单商品
+     * @param secondFlag    是否二手商品
+     * @param note          日志备注
+     */
+    public void savePurchasePrice(OrderPo order, OrderProductPo orderProduct, boolean secondFlag, String note) {
+        // 非二手订单, 非活动商品,非阶梯价商品,非运费商品,非赠品 才可以写入复购价
+        boolean purchaseFlag = ((!secondFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
+        boolean historyFlag = false;
+        // 不是二手订单才可以写入价格库
+        if (purchaseFlag) {
+            Date date = new Date();
+            String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+            // 机构价大于成本价   ---成本价已经在整理订单商品时计算好(固定或比例)
+            boolean costFlag = MathUtil.compare(orderProduct.getPrice(), orderProduct.getCostPrice()) > 0;
+            //  查询当前商品复购价信息
+            PurchasePricePo purchase = baseMapper.getPurchasePricePo(order.getUserId(), orderProduct.getProductId());
+            // 已有复购价
+            if (null != purchase) {
+                // 复购价大于机构价(降价)
+                boolean priceFlag1 = MathUtil.compare(purchase.getCurrentPrice(), orderProduct.getPrice()) > 0;
+                // 成本价大于复购价(亏本)
+                boolean priceFlag2 = MathUtil.compare(orderProduct.getCostPrice(), purchase.getCurrentPrice()) > 0;
+                if (priceFlag2 || (priceFlag1 && costFlag)) {
+                    // 更新价格库复购价
+                    purchase.setCurrentPrice(orderProduct.getPrice());
+                    purchase.setTaxRate(orderProduct.getTaxRate());
+                    purchase.setUpdateTime(curDateStr);
+                    // 更新复购价格库
+                    baseMapper.updatePurchasePrice(purchase);
+                    historyFlag = true;
+                    log.info(note + ">>>>>>>>>>>更新复购价格库(update[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + order.getOrderId());
+                }
+            } else {
+                // 没有复购价
+                if (costFlag) {
+                    // 新增复购价到价格库
+                    purchase = new PurchasePricePo();
+                    purchase.setUserId(order.getUserId());
+                    purchase.setClubId(order.getClubId());
+                    purchase.setOrderId(order.getOrderId());
+                    purchase.setProductId(orderProduct.getProductId());
+                    purchase.setShopId(orderProduct.getShopId());
+                    purchase.setShopName(orderProduct.getShopName());
+                    purchase.setCurrentPrice(orderProduct.getPrice());
+                    purchase.setTaxRate(orderProduct.getTaxRate());
+                    purchase.setCreateTime(curDateStr);
+                    purchase.setUpdateTime(curDateStr);
+                    purchase.setDelFlag(0);
+                    // 新增复购价格库
+                    baseMapper.insertPurchasePrice(purchase);
+                    historyFlag = true;
+                    log.info(note + ">>>>>>>>>>>新增复购价格库(insert[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + order.getOrderId());
+                }
+            }
+            if (historyFlag) {
+                // 历史复购价记录
+                PurchaseHistoryPo purchaseHistory = new PurchaseHistoryPo();
+                purchaseHistory.setUserId(order.getUserId());
+                purchaseHistory.setClubId(order.getClubId());
+                purchaseHistory.setOrderId(order.getOrderId());
+                purchaseHistory.setProductId(orderProduct.getProductId());
+                purchaseHistory.setCurrentCostPrice(orderProduct.getCostPrice());
+                purchaseHistory.setPrice(orderProduct.getPrice());
+                purchaseHistory.setCreateTime(curDateStr);
+                purchaseHistory.setDelFlag(0);
+                baseMapper.insertPurchaseHistory(purchaseHistory);
+                log.info(note + ">>>>>>>>>>>新增历史复购价记录(insert[repeat_purchase_price_history])ProductId:" + orderProduct.getProductId() + ",orderId:" + order.getOrderId());
+            }
+        }
+    }
+
+    /**
+     * 保存余额抵扣到收款记录
+     * @param balancePayFee 余额抵扣
+     * @param orderId       主订单Id
+     * @param note          日志备注
+     */
+    public void saveDiscernReceipt(Double balancePayFee, Integer orderId, String note) {
+        Date date = new Date();
+        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+        // 识别款项表
+        DiscernReceiptPo discernReceipt = new DiscernReceiptPo();
+        discernReceipt.setPayWay(3);
+        discernReceipt.setPayType(16);
+        discernReceipt.setReceiptType(1);
+        discernReceipt.setReceiptStatus(3);
+        discernReceipt.setReceiptAmount(balancePayFee);
+        discernReceipt.setConfirmType(4);
+        discernReceipt.setReceiptDate(curDateStr);
+        discernReceipt.setConfirmDate(curDateStr);
+        discernReceipt.setReviewDate(curDateStr);
+        discernReceipt.setUpdateDate(curDateStr);
+        discernReceipt.setDelFlag(0);
+        // 保存 收款记录
+        baseMapper.insertDiscernReceipt(discernReceipt);
+        log.info(note + ">>>>>>>>>>>保存识别款项(insert[cm_discern_receipt])id:" + discernReceipt.getId() + ",orderId:" + orderId);
+        // 收款项和订单关系表
+        OrderReceiptRelationPo relation = new OrderReceiptRelationPo();
+        relation.setReceiptId(discernReceipt.getId());
+        relation.setOrderId(orderId);
+        relation.setAssociateAmount(balancePayFee);
+        relation.setRelationType(2);
+        relation.setDelFlag(0);
+        // 保存 收款项和订单关系
+        baseMapper.insertOrderReceiptRelation(relation);
+        log.info(note + ">>>>>>>>>>>收款项和订单关系(insert[cm_receipt_order_relation])id:" + relation.getId() + ",orderId:" + orderId);
+    }
+
+
 }

+ 45 - 0
src/main/java/com/caimei365/order/controller/OrderClubApi.java

@@ -0,0 +1,45 @@
+package com.caimei365.order.controller;
+
+import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.dto.CartDto;
+import com.caimei365.order.model.dto.OrderDto;
+import com.caimei365.order.service.OrderClubService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 机构订单API
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Api(tags="机构订单API")
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/order/club")
+public class OrderClubApi {
+    private final OrderClubService orderClubService;
+
+    /**
+     * 机构确认订单
+     *
+     * @param orderDto {
+     *                orderId      订单ID
+     * }
+     */
+    @ApiOperation("更新购物车(旧:/order/affirmOrder)")
+    @PostMapping("/confirm")
+    public ResponseJson<Void> orderClubService(OrderDto orderDto){
+        if (null == orderDto.getOrderId()) {
+            return ResponseJson.error("订单Id不能为空!", null);
+        }
+        return orderClubService.orderClubService(orderDto.getOrderId());
+    }
+
+
+
+}

+ 19 - 0
src/main/java/com/caimei365/order/controller/OrderSellerApi.java

@@ -0,0 +1,19 @@
+package com.caimei365.order.controller;
+
+import io.swagger.annotations.Api;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 协销订单API
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Api(tags="协销订单API")
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/order/seller")
+public class OrderSellerApi {
+}

+ 2 - 0
src/main/java/com/caimei365/order/controller/SubmitApi.java

@@ -4,6 +4,7 @@ import com.caimei365.order.model.ResponseJson;
 import com.caimei365.order.model.dto.SubmitDto;
 import com.caimei365.order.service.SubmitService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -75,6 +76,7 @@ public class SubmitApi {
      * @return {code: -1=(用户账户异常,数据异常,操作异常等),1提交成功(支付完成),2提交成功(未支付),
      *              code为1和2时:data{orderNo:订单号,orderID:订单ID,payTotalFee:订单金额,orderMark:订单标识}
      */
+    @ApiOperation("提交订单(旧:/order/submit)")
     @PostMapping("/generate")
     public ResponseJson<Map<String, Object>> generateOrder(SubmitDto submitDto){
         if(null == submitDto.getOrderSource()){

+ 30 - 0
src/main/java/com/caimei365/order/mapper/BaseMapper.java

@@ -1,5 +1,9 @@
 package com.caimei365.order.mapper;
 
+import com.caimei365.order.model.po.DiscernReceiptPo;
+import com.caimei365.order.model.po.OrderReceiptRelationPo;
+import com.caimei365.order.model.po.PurchaseHistoryPo;
+import com.caimei365.order.model.po.PurchasePricePo;
 import com.caimei365.order.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -99,4 +103,30 @@ public interface BaseMapper {
      * 新增用户增值税发票
      */
     void insertUserInvoiceByUserId(InvoiceVo userInvoice);
+    /**
+     * 查询当前商品复购价信息
+     * @param userId    机构用户Id
+     * @param productId 商品Id
+     */
+    PurchasePricePo getPurchasePricePo(Integer userId, Integer productId);
+    /**
+     * 更新复购价格库
+     */
+    void updatePurchasePrice(PurchasePricePo purchase);
+    /**
+     * 新增复购价格库
+     */
+    void insertPurchasePrice(PurchasePricePo purchase);
+    /**
+     * 新增历史复购价记录
+     */
+    void insertPurchaseHistory(PurchaseHistoryPo purchaseHistory);
+    /**
+     * 保存 收款记录
+     */
+    void insertDiscernReceipt(DiscernReceiptPo discernReceipt);
+    /**
+     * 保存 收款项和订单关系
+     */
+    void insertOrderReceiptRelation(OrderReceiptRelationPo relation);
 }

+ 47 - 0
src/main/java/com/caimei365/order/mapper/OrderClubMapper.java

@@ -0,0 +1,47 @@
+package com.caimei365.order.mapper;
+
+import com.caimei365.order.model.po.OrderPo;
+import com.caimei365.order.model.po.OrderProductPo;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Mapper
+public interface OrderClubMapper {
+    /**
+     * 根据订单Id查询订单
+     * @param orderId 订单Id
+     */
+    OrderPo getMainOrderByOrderId(Integer orderId);
+    /**
+     * 根据订单Id查询订单商品列表
+     * @param orderId 订单Id
+     */
+    List<OrderProductPo> getOrderProductList(Integer orderId);
+    /**
+     * 设置二手仪器已售
+     * @param productId 商品Id
+     */
+    void updateSecondStatus(Integer productId);
+    /**
+     * 根据用户Id获取用户余额
+     * @param userId 用户Id
+     */
+    Double getUserMoneyByUserId(Integer userId);
+    /**
+     * 根据用户Id更新用户余额
+     * @param userId 用户Id
+     */
+    void updateUserMoneyByUserId(double updateMoney, Integer userId);
+    /**
+     * 更新订单状态
+     * @param order 主订单
+     */
+    void updateOrderStatus(OrderPo order);
+}

+ 13 - 0
src/main/java/com/caimei365/order/mapper/OrderSellerMapper.java

@@ -0,0 +1,13 @@
+package com.caimei365.order.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Mapper
+public interface OrderSellerMapper {
+}

+ 0 - 26
src/main/java/com/caimei365/order/mapper/SubmitMapper.java

@@ -101,14 +101,6 @@ public interface SubmitMapper {
      * 保存余额到余额收支记录
      */
     void insertBalanceRecord(BalanceRecordPo balanceRecord);
-    /**
-     * 保存 收款记录
-     */
-    void insertDiscernReceipt(DiscernReceiptPo discernReceipt);
-    /**
-     * 保存 收款项和订单关系
-     */
-    void insertOrderReceiptRelation(OrderReceiptRelationPo relation);
     /**
      * 保存 采美豆使用记录
      */
@@ -119,22 +111,4 @@ public interface SubmitMapper {
      * @param userId 机构用户Id
      */
     void updateUserBeans(Integer userId, int userBeans);
-    /**
-     * 查询当前商品复购价信息
-     * @param userId    机构用户Id
-     * @param productId 商品Id
-     */
-    PurchasePricePo getPurchasePricePo(Integer userId, Integer productId);
-    /**
-     * 新增复购价格库
-     */
-    void insertPurchasePrice(PurchasePricePo purchase);
-    /**
-     * 更新复购价格库
-     */
-    void updatePurchasePrice(PurchasePricePo purchase);
-    /**
-     * 新增历史复购价记录
-     */
-    void insertPurchaseHistory(PurchaseHistoryPo purchaseHistory);
 }

+ 20 - 0
src/main/java/com/caimei365/order/model/dto/OrderDto.java

@@ -0,0 +1,20 @@
+package com.caimei365.order.model.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Data
+public class OrderDto {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 订单Id
+     */
+    @ApiModelProperty("订单Id")
+    private Integer orderId;
+}

+ 17 - 0
src/main/java/com/caimei365/order/service/OrderClubService.java

@@ -0,0 +1,17 @@
+package com.caimei365.order.service;
+
+import com.caimei365.order.model.ResponseJson;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+public interface OrderClubService {
+    /**
+     * 机构确认订单
+     * @param orderId 订单Id
+     */
+    ResponseJson<Void> orderClubService(Integer orderId);
+}

+ 10 - 0
src/main/java/com/caimei365/order/service/OrderSellerService.java

@@ -0,0 +1,10 @@
+package com.caimei365.order.service;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+public interface OrderSellerService {
+}

+ 89 - 0
src/main/java/com/caimei365/order/service/impl/OrderClubServiceImpl.java

@@ -0,0 +1,89 @@
+package com.caimei365.order.service.impl;
+
+import com.caimei365.order.components.ProductService;
+import com.caimei365.order.mapper.OrderClubMapper;
+import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.po.OrderPo;
+import com.caimei365.order.model.po.OrderProductPo;
+import com.caimei365.order.service.OrderClubService;
+import com.caimei365.order.utils.MathUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Slf4j
+@Service
+public class OrderClubServiceImpl implements OrderClubService {
+    @Resource
+    private OrderClubMapper orderClubMapper;
+    @Resource
+    private ProductService productService;
+    /**
+     * 机构确认订单
+     *
+     * @param orderId 订单Id
+     */
+    @Override
+    public ResponseJson<Void> orderClubService(Integer orderId) {
+        OrderPo order = orderClubMapper.getMainOrderByOrderId(orderId);
+        if (null == order || 0 != order.getStatus()) {
+            // 非待确认订单
+            return ResponseJson.error("订单异常!", null);
+        }
+        Date date = new Date();
+        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+        String note = "【确认订单】";
+        List<OrderProductPo> orderProducts = orderClubMapper.getOrderProductList(orderId);
+        orderProducts.forEach(product -> {
+            // 是否二手商品
+            boolean secondFlag = false;
+            if (null != product.getProductCategory() && 2 == product.getProductCategory()) {
+                secondFlag = true;
+            }
+            // 更新复购价格库
+            productService.savePurchasePrice(order, product, secondFlag, note);
+            // 二手商品确认商品如果是二手仪器则需要把该二手商品置为已售
+            if (secondFlag) {
+                orderClubMapper.updateSecondStatus(product.getProductId());
+            }
+        });
+
+        if (null != order.getBalancePayFee() && MathUtil.compare(order.getBalancePayFee(), 0) > 0) {
+            double userMoney = orderClubMapper.getUserMoneyByUserId(orderId);
+            double updateMoney = MathUtil.sub(userMoney, order.getBalancePayFee()).doubleValue();
+            // 扣除用户余额
+            orderClubMapper.updateUserMoneyByUserId(updateMoney, orderId);
+            log.info(note + ">>>>>>>>>>>更新用户余额(update[user])userId:" + orderId + ",orderId:" + order.getOrderId());
+            // 保存余额到收款记录
+            productService.saveDiscernReceipt(order.getBalancePayFee(), orderId, note);
+        }
+        if (null == order.getBalancePayFee() || order.getBalancePayFee() == 0d) {
+            order.setStatus(11);
+            order.setReceiptStatus(1);
+        } else if (null != order.getBalancePayFee() && MathUtil.compare(order.getBalancePayFee(), order.getPayTotalFee()) < 0) {
+            order.setStatus(21);
+            order.setReceiptStatus(2);
+        } else {
+            order.setStatus(31);
+            order.setReceiptStatus(3);
+        }
+        order.setUpdateDate(curDateStr);
+        order.setConfirmTime(curDateStr);
+        //确认订单状态
+        order.setConfirmFlag(2);
+        // 更新订单状态
+        orderClubMapper.updateOrderStatus(order);
+
+        return ResponseJson.success("确认订单成功!", null);
+    }
+}

+ 16 - 0
src/main/java/com/caimei365/order/service/impl/OrderSellerServiceImpl.java

@@ -0,0 +1,16 @@
+package com.caimei365.order.service.impl;
+
+import com.caimei365.order.service.OrderSellerService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/19
+ */
+@Slf4j
+@Service
+public class OrderSellerServiceImpl implements OrderSellerService {
+}

+ 5 - 90
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -983,68 +983,8 @@ public class SubmitServiceImpl implements SubmitService {
              * 机构用户 写入价格库
              */
             if (3 != orderParamBo.getCartType()) {
-                // 非二手订单, 非活动商品,非阶梯价商品,非运费商品,非赠品 才可以写入复购价
-                boolean purchaseFlag = ((!secondHandOrderFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
-                boolean historyFlag = false;
-                // 不是二手订单才可以写入价格库
-                if (purchaseFlag) {
-                    // 机构价大于成本价   ---成本价已经在整理订单商品时计算好(固定或比例)
-                    boolean costFlag = MathUtil.compare(orderProduct.getPrice(), orderProduct.getCostPrice()) > 0;
-                    //  查询当前商品复购价信息
-                    PurchasePricePo purchase = submitMapper.getPurchasePricePo(mainOrder.getUserId(), orderProduct.getProductId());
-                    // 已有复购价
-                    if (null != purchase) {
-                        // 复购价大于机构价(降价)
-                        boolean priceFlag1 = MathUtil.compare(purchase.getCurrentPrice(), orderProduct.getPrice()) > 0;
-                        // 成本价大于复购价(亏本)
-                        boolean priceFlag2 = MathUtil.compare(orderProduct.getCostPrice(), purchase.getCurrentPrice()) > 0;
-                        if (priceFlag2 || (priceFlag1 && costFlag)) {
-                            // 更新价格库复购价
-                            purchase.setCurrentPrice(orderProduct.getPrice());
-                            purchase.setTaxRate(orderProduct.getTaxRate());
-                            purchase.setUpdateTime(mainOrder.getOrderTime());
-                            // 更新复购价格库
-                            submitMapper.updatePurchasePrice(purchase);
-                            historyFlag = true;
-                            log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>更新复购价格库(update[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + mainOrder.getOrderId());
-                        }
-                    } else {
-                        // 没有复购价
-                        if (costFlag) {
-                            // 新增复购价到价格库
-                            purchase = new PurchasePricePo();
-                            purchase.setUserId(mainOrder.getUserId());
-                            purchase.setClubId(mainOrder.getClubId());
-                            purchase.setOrderId(mainOrder.getOrderId());
-                            purchase.setProductId(orderProduct.getProductId());
-                            purchase.setShopId(orderProduct.getShopId());
-                            purchase.setShopName(orderProduct.getShopName());
-                            purchase.setCurrentPrice(orderProduct.getPrice());
-                            purchase.setTaxRate(orderProduct.getTaxRate());
-                            purchase.setCreateTime(mainOrder.getOrderTime());
-                            purchase.setUpdateTime(mainOrder.getOrderTime());
-                            purchase.setDelFlag(0);
-                            // 新增复购价格库
-                            submitMapper.insertPurchasePrice(purchase);
-                            historyFlag = true;
-                            log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增复购价格库(insert[repeat_purchase_price])ProductId:" + orderProduct.getProductId() + ",orderId:" + mainOrder.getOrderId());
-                        }
-                    }
-                    if (historyFlag) {
-                        // 历史复购价记录
-                        PurchaseHistoryPo purchaseHistory = new PurchaseHistoryPo();
-                        purchaseHistory.setUserId(mainOrder.getUserId());
-                        purchaseHistory.setClubId(mainOrder.getClubId());
-                        purchaseHistory.setOrderId(mainOrder.getOrderId());
-                        purchaseHistory.setProductId(orderProduct.getProductId());
-                        purchaseHistory.setCurrentCostPrice(orderProduct.getCostPrice());
-                        purchaseHistory.setPrice(orderProduct.getPrice());
-                        purchaseHistory.setCreateTime(mainOrder.getOrderTime());
-                        purchaseHistory.setDelFlag(0);
-                        submitMapper.insertPurchaseHistory(purchaseHistory);
-                        log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增历史复购价记录(insert[repeat_purchase_price_history])ProductId:" + orderProduct.getProductId() + ",orderId:" + mainOrder.getOrderId());
-                    }
-                }
+                // 写入复购价格库
+                productService.savePurchasePrice(mainOrder, orderProduct, secondHandOrderFlag, "【提交订单】");
             }
         }
 
@@ -1191,34 +1131,10 @@ public class SubmitServiceImpl implements SubmitService {
             submitMapper.insertBalanceRecord(balanceRecord);
             log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>新增用户余额收支记录(insert[cm_user_balance_record])orderId:" + mainOrder.getOrderId());
 
-            //保存余额到收款记录(自主订单)
+            // 保存余额抵扣到收款记录(自主订单)
             if (3 != orderParamBo.getCartType()) {
-                // 识别款项表
-                DiscernReceiptPo discernReceipt = new DiscernReceiptPo();
-                discernReceipt.setPayWay(3);
-                discernReceipt.setPayType(16);
-                discernReceipt.setReceiptType(1);
-                discernReceipt.setReceiptStatus(3);
-                discernReceipt.setReceiptAmount(balancePayFee.get());
-                discernReceipt.setConfirmType(4);
-                discernReceipt.setReceiptDate(curDateStr);
-                discernReceipt.setConfirmDate(curDateStr);
-                discernReceipt.setReviewDate(curDateStr);
-                discernReceipt.setUpdateDate(curDateStr);
-                discernReceipt.setDelFlag(0);
-                // 保存 收款记录
-                submitMapper.insertDiscernReceipt(discernReceipt);
-                log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>保存识别款项(insert[cm_discern_receipt])id:" + discernReceipt.getId() + ",orderId:" + mainOrder.getOrderId());
-                // 收款项和订单关系表
-                OrderReceiptRelationPo relation = new OrderReceiptRelationPo();
-                relation.setReceiptId(discernReceipt.getId());
-                relation.setOrderId(mainOrder.getOrderId());
-                relation.setAssociateAmount(balancePayFee.get());
-                relation.setRelationType(2);
-                relation.setDelFlag(0);
-                // 保存 收款项和订单关系
-                submitMapper.insertOrderReceiptRelation(relation);
-                log.info("【提交订单】>>>>>>>>>>>>>>>>>>>>>>>>>>收款项和订单关系(insert[cm_receipt_order_relation])id:" + relation.getId() + ",orderId:" + mainOrder.getOrderId());
+                Integer orderId = mainOrder.getOrderId();
+                productService.saveDiscernReceipt(balancePayFee.get(), orderId, "【提交订单】");
             }
         }
 
@@ -1324,5 +1240,4 @@ public class SubmitServiceImpl implements SubmitService {
         }
     }
 
-
 }

+ 40 - 0
src/main/resources/mapper/BaseMapper.xml

@@ -5,6 +5,16 @@
         INSERT INTO cm_user_invoiceinfo (userId, invoiceTitle, corporationTaxNum, registeredAddress, registeredPhone, bankAccountNo, openBank)
         VALUES(#{userId}, #{invoiceTitle}, #{corporationTaxNum},#{registeredAddress}, #{registeredPhone},#{bankAccountNo}, #{openBank})
     </insert>
+    <insert id="insertPurchasePrice" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.PurchasePricePo" useGeneratedKeys="true">
+        INSERT INTO repeat_purchase_price (userId, clubId, orderId, productId, shopId, shopName,
+        taxRate, currentPrice, createTime, updateTime, delFlag)
+        VALUES (#{userId}, #{clubId}, #{orderId}, #{productId}, #{shopId}, #{shopName},
+        #{taxRate}, #{currentPrice}, #{createTime}, #{updateTime}, #{delFlag})
+    </insert>
+    <insert id="insertPurchaseHistory" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.PurchaseHistoryPo" useGeneratedKeys="true">
+        INSERT INTO repeat_purchase_price_history (userId, clubId, orderId, productId, price, currentCostPrice, createTime, delFlag)
+        VALUES (#{userId}, #{clubId}, #{orderId}, #{productId}, #{price}, #{currentCostPrice}, #{createTime}, #{delFlag})
+    </insert>
     <update id="updateUserInvoiceByUserId" parameterType="com.caimei365.order.model.vo.InvoiceVo">
         UPDATE cm_user_invoiceinfo
         SET
@@ -16,6 +26,11 @@
             openBank = #{openBank}
         WHERE userId = #{userId}
     </update>
+    <update id="updatePurchasePrice">
+        UPDATE repeat_purchase_price SET
+        currentPrice = #{currentPrice}, taxRate = #{taxRate}, updateTime = #{updateTime}
+        WHERE id = #{id}
+    </update>
     <select id="getUserIdByClubId" resultType="java.lang.Integer">
         select userID from user where clubID = #{clubId}
     </select>
@@ -151,6 +166,31 @@
     <select id="getTownIdByAddressId" resultType="java.lang.Integer">
         SELECT townID FROM address WHERE addressID = #{addressId}
     </select>
+    <select id="getPurchasePricePo" resultType="com.caimei365.order.model.po.PurchasePricePo">
+        SELECT
+        id,
+        userId,
+        clubId,
+        orderId,
+        productId,
+        shopId,
+        shopName,
+        taxRate,
+        currentPrice,
+        createTime
+        FROM repeat_purchase_price
+        WHERE userId = #{userId} AND productId = #{productId} AND delFlag='0'
+    </select>
+    <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
+        INSERT INTO cm_discern_receipt (payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
+        receiptDate, confirmDate, reviewDate, updateDate, delFlag)
+        VALUES (#{payWay}, #{payType}, #{receiptType}, #{receiptStatus}, #{receiptAmount}, #{confirmType},
+        #{receiptDate}, #{confirmDate}, #{reviewDate}, #{updateDate}, #{delFlag})
+    </insert>
+    <insert id="insertOrderReceiptRelation" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
+        INSERT INTO cm_receipt_order_relation (relationType, receiptId, associateAmount, orderId, delFlag)
+        VALUES (#{relationType}, #{receiptId}, #{associateAmount}, #{orderId}, #{delFlag})
+    </insert>
     <!--    <select id="getAddressDetailById" resultType="com.caimei365.order.model.vo.AddressVo">-->
 <!--        SELECT-->
 <!--            a.addressID AS addressId,-->

+ 120 - 0
src/main/resources/mapper/OrderClubMapper.xml

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei365.order.mapper.OrderClubMapper">
+    <update id="updateSecondStatus">
+        UPDATE cm_second_hand_detail SET sold = 1
+        WHERE productID = #{productID} AND secondHandType=1
+    </update>
+    <update id="updateUserMoneyByUserId">
+        UPDATE USER SET userMoney = #{userMoney}
+        WHERE userID = #{userId}
+    </update>
+    <update id="updateOrderStatus">
+        UPDATE cm_order SET
+        status = #{status},
+        receiptStatus = #{receiptStatus},
+        confirmFlag = #{confirmFlag},
+        confirmTime = #{confirmTime},
+        updateDate = #{updateDate}
+        WHERE orderID = #{orderId}
+    </update>
+    <select id="getMainOrderByOrderId" resultType="com.caimei365.order.model.po.OrderPo">
+        SELECT
+            orderSource,
+            orderNo,
+            userID AS userId,
+            clubID AS clubId,
+            buyUserID AS buyUserId,
+            orderTime AS orderTime,
+            updateDate AS updateDate,
+            delFlag,
+            userBeans,
+            orderType,
+            orderSubmitType,
+            confirmFlag,
+            onlinePayFlag,
+            splitFlag,
+            payFlag,
+            receiptStatus,
+            payStatus,
+            zeroCostFlag,
+            sendOutStatus,
+            refundType,
+            affirmPaymentFlag,
+            productCount,
+            presentCount,
+            promotionalGiftsCount,
+            hasActProduct,
+            promotionFullReduction,
+            secondHandOrderFlag,
+            invoiceFlag,
+            freePostFlag AS postageFlag,
+            freight AS postage,
+            productTotalFee,
+            orderTotalFee,
+            payTotalFee,
+            payableAmount,
+            balancePayFee,
+            status,
+            confirmTime,
+            payTime,
+            rebateFlag,
+            clauseID AS clauseId,
+            clauseName
+        FROM cm_order
+        WHERE orderID = #{orderId}
+    </select>
+    <select id="getOrderProductList" resultType="com.caimei365.order.model.po.OrderProductPo">
+        SELECT
+            cop.orderID AS orderId,
+            cop.orderNo,
+            cop.shopOrderID AS shopOrderId,
+            cop.shopOrderNo,
+            cop.orderPromotionsId,
+            cop.productId,
+            cop.shopId,
+            cop.name,
+            cop.image,
+            cop.price,
+            cop.shopName,
+            cop.costPrice,
+            cop.normalPrice,
+            cop.ladderPriceFlag,
+            cop.discountPrice,
+            cop.discount,
+            cop.totalAmount,
+            cop.totalFee,
+            cop.shouldPayFee,
+            cop.productUnit,
+            cop.num,
+            cop.presentNum,
+            cop.discountFee,
+            cop.includedTax,
+            cop.invoiceType,
+            cop.taxRate,
+            cop.addedValueTax,
+            cop.totalAddedValueTax,
+            cop.singleShouldPayTotalTax,
+            cop.shouldPayTotalTax,
+            cop.shopProductAmount,
+            cop.singleShopFee,
+            cop.shopFee,
+            cop.singleOtherFee,
+            cop.otherFee,
+            cop.singleCmFee,
+            cop.cmFee,
+            cop.payStatus,
+            cop.buyAgainFlag,
+            cop.notOutStore,
+            cop.isActProduct AS actProduct,
+            p.productCategory AS productCategory
+        FROM cm_order_product cop
+        LEFT JOIN product p ON p.productID = cop.productID
+        WHERE cop.orderID = #{orderID}
+    </select>
+    <select id="getUserMoneyByUserId" resultType="java.lang.Double">
+        SELECT
+        userMoney FROM user
+        WHERE userID = #{userId}
+    </select>
+</mapper>

+ 5 - 0
src/main/resources/mapper/OrderSellerMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei365.order.mapper.OrderSellerMapper">
+
+</mapper>

+ 2 - 41
src/main/resources/mapper/SubmitMapper.xml

@@ -67,30 +67,10 @@
         INSERT INTO cm_user_balance_record (userId, type, balanceType, addDate, amount, orderId, remark, delFlag)
         VALUES (#{userId}, #{type}, #{balanceType}, #{addDate}, #{amount}, #{orderId}, #{remark}, #{delFlag})
     </insert>
-    <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
-        INSERT INTO cm_discern_receipt (payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
-                                        receiptDate, confirmDate, reviewDate, updateDate, delFlag)
-        VALUES (#{payWay}, #{payType}, #{receiptType}, #{receiptStatus}, #{receiptAmount}, #{confirmType},
-                #{receiptDate}, #{confirmDate}, #{reviewDate}, #{updateDate}, #{delFlag})
-    </insert>
-    <insert id="insertOrderReceiptRelation" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
-        INSERT INTO cm_receipt_order_relation (relationType, receiptId, associateAmount, orderId, delFlag)
-        VALUES (#{relationType}, #{receiptId}, #{associateAmount}, #{orderId}, #{delFlag})
-    </insert>
     <insert id="insertBeansHistory" parameterType="com.caimei365.order.model.po.UserBeansHistoryPo">
         INSERT INTO user_beans_history (userId, type, beansType, orderId, num, pushStatus, addTime, delFlag)
         VALUES (#{userId}, #{type}, #{beansType}, #{orderId}, #{num}, #{pushStatus}, #{addTime}, #{delFlag})
     </insert>
-    <insert id="insertPurchasePrice" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.PurchasePricePo" useGeneratedKeys="true">
-        INSERT INTO repeat_purchase_price (userId, clubId, orderId, productId, shopId, shopName,
-                                            taxRate, currentPrice, createTime, updateTime, delFlag)
-        VALUES (#{userId}, #{clubId}, #{orderId}, #{productId}, #{shopId}, #{shopName},
-                #{taxRate}, #{currentPrice}, #{createTime}, #{updateTime}, #{delFlag})
-    </insert>
-    <insert id="insertPurchaseHistory" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.PurchaseHistoryPo" useGeneratedKeys="true">
-        INSERT INTO repeat_purchase_price_history (userId, clubId, orderId, productId, price, currentCostPrice, createTime, delFlag)
-        VALUES (#{userId}, #{clubId}, #{orderId}, #{productId}, #{price}, #{currentCostPrice}, #{createTime}, #{delFlag})
-    </insert>
     <update id="updateUserMoney">
         UPDATE USER SET userMoney = #{userMoney}, ableUserMoney = #{ableUserMoney}
         WHERE userID = #{userId}
@@ -99,11 +79,6 @@
         UPDATE USER SET userBeans = #{userBeans}
         WHERE userID = #{userId}
     </update>
-    <update id="updatePurchasePrice">
-        UPDATE repeat_purchase_price SET
-        currentPrice = #{currentPrice}, taxRate = #{taxRate}, updateTime = #{updateTime}
-        WHERE id = #{id}
-    </update>
     <delete id="deleteOrderInvoiceByOrderId">
         DELETE FROM bp_order_invoice WHERE orderId = #{orderId}
     </delete>
@@ -124,7 +99,7 @@
             ableUserMoney,
             userBeans
         FROM user
-        WHERE userID = #{userID}
+        WHERE userID = #{userId}
     </select>
     <select id="getShopNameById" resultType="java.lang.String">
         SELECT `name` FROM shop WHERE shopID = #{shopId}
@@ -174,21 +149,7 @@
         WHERE a.addressID = #{addressId}
         LIMIT 1
     </select>
-    <select id="getPurchasePricePo" resultType="com.caimei365.order.model.po.PurchasePricePo">
-        SELECT
-            id,
-            userId,
-            clubId,
-            orderId,
-            productId,
-            shopId,
-            shopName,
-            taxRate,
-            currentPrice,
-            createTime
-        FROM repeat_purchase_price
-        WHERE userId = #{userId} AND productId = #{productId} AND delFlag='0'
-    </select>
+
 
 
 </mapper>