瀏覽代碼

提交订单,写入复购价

chao 4 年之前
父節點
當前提交
23e05f883f

+ 5 - 1
backup.sql

@@ -44,4 +44,8 @@ MODIFY COLUMN `shouldPayFee` decimal(20,6) DEFAULT NULL COMMENT '【V2021已废
 MODIFY COLUMN `payStatus` char(1) DEFAULT '0' COMMENT '【V2021已废弃】支付状态 0 未付款 1 已付款',
 MODIFY COLUMN `payDate` datetime DEFAULT NULL COMMENT '【V2021已废弃】支付时间',
 MODIFY COLUMN `stagesFlag` char(1) DEFAULT NULL COMMENT '【V2021已废弃】分期订单标志 0否 1是',
-MODIFY COLUMN `normalUserID` bigint(11) DEFAULT NULL COMMENT '【V2021已废弃】个人用户ID';
+MODIFY COLUMN `normalUserID` bigint(11) DEFAULT NULL COMMENT '【V2021已废弃】个人用户ID';
+
+-- 修改 repeat_purchase_price 复购价格库表
+ALTER TABLE `repeat_purchase_price`
+ADD COLUMN `updateTime` INT(11) DEFAULT NULL COMMENT '更新时间' AFTER `createTime`;

+ 20 - 2
src/main/java/com/caimei365/order/mapper/SubmitMapper.java

@@ -115,8 +115,26 @@ public interface SubmitMapper {
     void insertBeansHistory(UserBeansHistoryPo beansHistory);
     /**
      * 更新用户剩余采美豆数量
-     * @param beans 采美豆数量
+     * @param userBeans 采美豆数量
      * @param userId 机构用户Id
      */
-    void updateUserBeans(Integer userId, int beans);
+    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);
 }

+ 52 - 0
src/main/java/com/caimei365/order/model/po/PurchaseHistoryPo.java

@@ -0,0 +1,52 @@
+package com.caimei365.order.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 历史复购价记录
+ *
+ * @author : Charles
+ * @date : 2021/7/15
+ */
+@Data
+public class PurchaseHistoryPo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * id
+     */
+    private Integer id;
+    /**
+     * 用户id
+     */
+    private Integer userId;
+    /**
+     * 机构Id
+     */
+    private Integer clubId;
+    /**
+     * 订单Id
+     */
+    private Integer orderId;
+    /**
+     * 商品ID
+     */
+    private Integer productId;
+    /**
+     * 价格
+     */
+    private Double price;
+    /**
+     * 成本价
+     */
+    private Double currentCostPrice;
+    /**
+     * 添加时间
+     */
+    private String createTime;
+    /**
+     * 删除标记 0否 其余是
+     */
+    private Integer delFlag;
+}

+ 65 - 0
src/main/java/com/caimei365/order/model/po/PurchasePricePo.java

@@ -0,0 +1,65 @@
+package com.caimei365.order.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+/**
+ * 复购价格库
+ *
+ * @author : Charles
+ * @date : 2021/7/14
+ */
+@Data
+public class PurchasePricePo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * id
+     */
+    private Integer id;
+    /**
+     * 用户id
+     */
+    private Integer userId;
+    /**
+     * 机构Id
+     */
+    private Integer clubId;
+    /**
+     * 订单Id
+     */
+    private Integer orderId;
+    /**
+     * 商品ID
+     */
+    private Integer productId;
+    /**
+     * 供应商ID
+     */
+    private Integer shopId;
+    /**
+     * 供应商名称
+     */
+    private String shopName;
+    /**
+     * 税率
+     */
+    private Double taxRate;
+    /**
+     * 当前价
+     */
+    private Double currentPrice;
+    /**
+     * 下单时间
+     */
+    private String createTime;
+    /**
+     * 更新时间
+     */
+    private String updateTime;
+    /**
+     * 删除标记 0否 其余是
+     */
+    private Integer delFlag;
+}

+ 59 - 9
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -975,16 +975,66 @@ public class SubmitServiceImpl implements SubmitService {
              */
             if (3 != orderParamBo.getCartType()) {
                 // 非二手订单, 非活动商品,非阶梯价商品,非运费商品,非赠品 才可以写入复购价
-                boolean flag = ((!secondHandOrderFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
+                boolean purchaseFlag = ((!secondHandOrderFlag) && orderProduct.getActProduct() == 0 && orderProduct.getShopId() != 998 && orderProduct.getPrice() > 0);
+                boolean historyFlag = false;
                 // 不是二手订单才可以写入价格库
-                if (flag) {
-                    //  查询当前商品复购价
-                    //PurchasePricePo purchase = submitMapper.getPurchasePricePo(orderParamBo.getUserId(), orderProduct.getProductId());
-
-
-
-
-
+                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());
+                    }
                 }
             }
         }

+ 30 - 0
src/main/resources/mapper/SubmitMapper.xml

@@ -81,6 +81,16 @@
         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}
@@ -89,6 +99,11 @@
         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>
@@ -159,6 +174,21 @@
         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>