浏览代码

乐器维修支持优惠券

zouxuan 4 年之前
父节点
当前提交
272f20d607

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SellOrder.java

@@ -203,6 +203,17 @@ public class SellOrder {
 
     private Boolean hasRoute = false;
 
+    @ApiModelProperty(value="优惠券减免")
+    private BigDecimal couponRemitAmount = BigDecimal.ZERO;
+
+    public BigDecimal getCouponRemitAmount() {
+        return couponRemitAmount;
+    }
+
+    public void setCouponRemitAmount(BigDecimal couponRemitAmount) {
+        this.couponRemitAmount = couponRemitAmount;
+    }
+
     public String getReceiveStatus() {
         return receiveStatus;
     }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentRepair.java

@@ -209,9 +209,19 @@ public class StudentRepair extends PayParamBasicDto {
     @ApiModelProperty(value = "更新时间", required = false)
     private Date updateTime;
 
+    private String couponIds;
+
     @ApiModelProperty(value = "辅件金额", required = false)
     private BigDecimal repairGoodsAmount = BigDecimal.ZERO;
 
+    public String getCouponIds() {
+        return couponIds;
+    }
+
+    public void setCouponIds(String couponIds) {
+        this.couponIds = couponIds;
+    }
+
     public String getGoodsJson() {
         return goodsJson;
     }

+ 30 - 19
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -76,11 +76,11 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             }
         }
         //商品总价值去掉优惠券减免
-        if(goodsTotalPrice.compareTo(couponRemitFee) <= 0){
-            goodsTotalPrice = BigDecimal.ZERO;
-        }else {
-            goodsTotalPrice = goodsTotalPrice.subtract(couponRemitFee);
-        }
+//        if(goodsTotalPrice.compareTo(couponRemitFee) <= 0){
+//            goodsTotalPrice = BigDecimal.ZERO;
+//        }else {
+//            goodsTotalPrice = goodsTotalPrice.subtract(couponRemitFee);
+//        }
 
         //已分配的商品余额
         BigDecimal hasRouteBalance = BigDecimal.ZERO;
@@ -106,19 +106,22 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             }
             goodsPrice = nowGoods.getDiscountPrice();
             //扣除减免金额
-            if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
-                if(j == goodsIds.size() - 1){
-                    goodsPrice = goodsPrice.subtract(couponRemitFee);
-                }else {
-                    //获取比例
-                    BigDecimal divide = goodsPrice.divide(goodsPrice.add(couponRemitFee), 6, BigDecimal.ROUND_HALF_UP);
-                    //分摊金额
-                    BigDecimal scale = goodsPrice.multiply(divide).setScale(2, BigDecimal.ROUND_HALF_UP);
-                    freeCouponRemitFee = freeCouponRemitFee.subtract(scale);
-                    goodsPrice = goodsPrice.subtract(scale);
-                }
-            }
-
+//            if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
+//                if(j == goodsIds.size() - 1){
+//                    goodsPrice = goodsPrice.subtract(freeCouponRemitFee);
+//                }else {
+//                    //获取比例
+//                    BigDecimal divide = goodsPrice.divide(goodsPrice.add(couponRemitFee), 6, BigDecimal.ROUND_HALF_UP);
+//                    //分摊金额
+//                    BigDecimal scale = couponRemitFee.multiply(divide).setScale(2, BigDecimal.ROUND_HALF_UP);
+//                    freeCouponRemitFee = freeCouponRemitFee.subtract(scale);
+//                    goodsPrice = goodsPrice.subtract(scale);
+//                }
+//            }
+
+            //当前商品占用的总优惠券减免
+            BigDecimal couponBalance = goodsTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                    couponRemitFee.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
             //当前商品占用的总余额
             BigDecimal goodsBalance = goodsTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
                     goodsTotalBalance.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
@@ -127,9 +130,11 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                     goodsTotalActualAmount.multiply(goodsPrice).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
 
             if (i == goodsNum) {
+                couponBalance = couponRemitFee.subtract(freeCouponRemitFee);
                 goodsBalance = goodsTotalBalance.subtract(hasRouteBalance);
                 goodsActualAmount = goodsTotalActualAmount.subtract(hasRouteActualAmount);
             }
+            freeCouponRemitFee = freeCouponRemitFee.subtract(couponBalance);
             hasRouteBalance = hasRouteBalance.add(goodsBalance);
             hasRouteActualAmount = hasRouteActualAmount.add(goodsActualAmount);
             i++;
@@ -146,6 +151,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 
             BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
             BigDecimal hasRouteSellOrderBalance = BigDecimal.ZERO;
+            BigDecimal hasRouteCouponBalance = BigDecimal.ZERO;
             for (SellOrder sellOrder : sellOrderList) {
                 if (!goodsId.equals(sellOrder.getParentGoodsId()) && !goodsId.equals(sellOrder.getGoodsId())) {
                     continue;
@@ -155,21 +161,26 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 }
                 BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
                 BigDecimal sellOrderBalance = BigDecimal.ZERO;
+                BigDecimal sellOrderCouponBalance = BigDecimal.ZERO;
                 if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
                     sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsActualAmount).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
                     sellOrderBalance = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(goodsBalance).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
+                    sellOrderCouponBalance = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(couponBalance).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
                 }
 
                 complementGoodsNum = complementGoodsNum - sellOrder.getNum();
                 if (complementGoodsNum <= 0) {
                     sellOrderActualAmount = goodsActualAmount.subtract(hasRouteSellOrderActualAmount);
                     sellOrderBalance = goodsBalance.subtract(hasRouteSellOrderBalance);
+                    sellOrderCouponBalance = couponBalance.subtract(hasRouteCouponBalance);
                 }
                 hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
                 hasRouteSellOrderBalance = hasRouteSellOrderBalance.add(sellOrderBalance);
+                hasRouteCouponBalance = hasRouteCouponBalance.add(sellOrderCouponBalance);
 
-                sellOrder.setExpectAmount(sellOrderActualAmount.add(sellOrderBalance));
+                sellOrder.setExpectAmount(sellOrderActualAmount.add(sellOrderBalance).add(sellOrderCouponBalance));
                 sellOrder.setBalanceAmount(sellOrderBalance);
+                sellOrder.setCouponRemitAmount(sellOrderCouponBalance);
                 sellOrder.setActualAmount(sellOrderActualAmount);
                 sellOrder.setOrganId(order.getOrganId());
                 sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());

+ 13 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -342,13 +342,17 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             }
         }
         studentGoodsSellDao.update(studentGoodsSell);
-        studentPaymentOrder = new StudentPaymentOrder();
+        String couponIds = studentGoodsSell.getCouponIds();
+        List<Integer> couponIdList = new ArrayList<>();
+        if(StringUtils.isNotEmpty(couponIds)){
+            couponIdList = Arrays.stream(couponIds.split(",")).mapToInt(Integer::valueOf).boxed().collect(Collectors.toList());
+        }
+        studentPaymentOrder = sysCouponCodeService.use(couponIdList,amount);
+        amount = studentPaymentOrder.getActualAmount();
         studentPaymentOrder.setUserId(studentId);
         studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
         studentPaymentOrder.setOrderNo(orderNo);
         studentPaymentOrder.setType(OrderTypeEnum.GOODS_SELL);
-        studentPaymentOrder.setExpectAmount(amount);
-        studentPaymentOrder.setActualAmount(amount);
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
         studentPaymentOrder.setOrganId(studentGoodsSell.getOrganId());
         studentPaymentOrder.setRoutingOrganId(studentGoodsSell.getOrganId());
@@ -458,13 +462,17 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 }
             }
         }
-        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(repairInfo.getCouponIdList(),amount);
+        List<Integer> couponIdList = repairInfo.getCouponIdList();
+        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(couponIdList,amount);
         amount = studentPaymentOrder.getActualAmount();
         amount = amount.subtract(repairInfo.getExemptionAmount());
         if (amount.compareTo(BigDecimal.ZERO) < 0) {
             throw new BizException("特权减免金额不能大于总金额");
         }
 
+        if(couponIdList != null && couponIdList.size() > 0){
+            repairInfo.setCouponIds(StringUtils.join(couponIdList,","));
+        }
         studentRepairDao.insert(repairInfo);
         if (repairInfo.getType() == 1) {
             Map<String, Object> repairInfoMap = new HashMap<>();
@@ -1076,7 +1084,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             sysUserCashAccountDetailService.insert(paymentDetail);
             //优惠券减免金额
             BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
-            if(studentPaymentOrder.getCouponRemitFee().compareTo(BigDecimal.ZERO) > 0 && repairInfo.getAmount().compareTo(BigDecimal.ZERO) > 0){
+            if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0 && repairInfo.getAmount().compareTo(BigDecimal.ZERO) > 0){
                 //获取维修金额
                 BigDecimal repairAmount = repairInfo.getAmount();
                 //获取比例

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMessageServiceImpl.java

@@ -273,7 +273,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 		privateMessage.setTargetId(receiver.split(","));
 		privateMessage.setSenderId(sender);
 		privateMessage.setContent(new ImTxtMessage(content,null));
-		imFeignService.privateSend(privateMessage);
+//		imFeignService.privateSend(privateMessage);
 	}
 
 	@Override

+ 9 - 5
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -16,6 +16,7 @@
         <result column="expect_amount_" property="expectAmount"/>
         <result column="actual_amount_" property="actualAmount"/>
         <result column="balance_amount_" property="balanceAmount"/>
+        <result column="coupon_remit_amount_" property="couponRemitAmount"/>
         <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="parent_goods_id_" property="parentGoodsId"/>
         <result column="goods_id_" property="goodsId"/>
@@ -47,7 +48,7 @@
         actual_amount_,balance_amount_, sell_cost_, sell_cost2_, type_,parent_goods_id_, goods_id_,goods_name_, num_,
         user_id_,
         payment_channel_,mer_no_,batch_no_,stock_type_,account_type_,status_, refund_time_,sell_time_, create_ime_,
-        update_time_
+        update_time_,coupon_remit_amount_
     </sql>
     <select id="get" parameterType="java.lang.Integer" resultMap="SellOrder">
         <!--@mbg.generated-->
@@ -67,18 +68,21 @@
         insert into sell_order (edu_teacher_id_,organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_,
         expect_amount_,actual_amount_,balance_amount_, type_,parent_goods_id_, goods_id_,goods_name_, sell_cost_,
         sell_cost2_, num_, user_id_, payment_channel_,
-        mer_no_,batch_no_,stock_type_,account_type_, refund_time_,sell_time_, create_ime_, update_time_)
+        mer_no_,batch_no_,stock_type_,account_type_, refund_time_,sell_time_, create_ime_, update_time_,coupon_remit_amount_)
         values (#{eduTeacherId},#{organId}, #{cooperationOrganId}, #{transNo}, #{orderNo},#{orderId}, #{expectAmount},
         #{actualAmount}, #{balanceAmount}, #{type},#{parentGoodsId}, #{goodsId}, #{goodsName}, #{sellCost},
         #{sellCost2}, #{num}, #{userId},
         #{paymentChannel}, #{merNo},#{batchNo},
         #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{accountType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-        #{refundTime},#{sellTime}, #{createIme}, #{updateTime})
+        #{refundTime},#{sellTime}, #{createIme}, #{updateTime}, #{couponRemitAmount})
     </insert>
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.SellOrder">
         <!--@mbg.generated-->
         update sell_order
         <set>
+            <if test="couponRemitAmount != null">
+                coupon_remit_amount_ = #{couponRemitAmount},
+            </if>
             <if test="eduTeacherId != null">
                 edu_teacher_id_ = #{eduTeacherId},
             </if>
@@ -256,7 +260,7 @@
         insert into sell_order (organ_id_, cooperation_organ_id_, trans_no_,order_id_, order_no_, expect_amount_,
         actual_amount_,balance_amount_, type_, parent_goods_id_, goods_id_,goods_name_, sell_cost_, sell_cost2_, num_,
         user_id_, payment_channel_,
-        mer_no_,batch_no_,stock_type_,account_type_, sell_time_,edu_teacher_id_, create_ime_, update_time_)
+        mer_no_,batch_no_,stock_type_,account_type_, sell_time_,edu_teacher_id_, create_ime_, update_time_,coupon_remit_amount_)
         VALUE
         <foreach collection="sellOrders" separator="," item="sellOrder">
             (#{sellOrder.organId},#{sellOrder.cooperationOrganId},#{sellOrder.transNo},#{sellOrder.orderId},#{sellOrder.orderNo},
@@ -264,7 +268,7 @@
             #{sellOrder.goodsName},#{sellOrder.sellCost},#{sellOrder.sellCost2},#{sellOrder.num},#{sellOrder.userId},
             #{sellOrder.paymentChannel},#{sellOrder.merNo},#{sellOrder.batchNo},
             #{sellOrder.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{sellOrder.accountType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-            #{sellOrder.sellTime},#{sellOrder.eduTeacherId},NOW(),NOW())
+            #{sellOrder.sellTime},#{sellOrder.eduTeacherId},NOW(),NOW(),#{sellOrder.couponRemitAmount})
         </foreach>
     </insert>
 

+ 6 - 2
mec-biz/src/main/resources/config/mybatis/StudentRepairMapper.xml

@@ -38,6 +38,7 @@
         <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="username_" jdbcType="VARCHAR" property="studentName"/>
         <result column="goods_json_" jdbcType="VARCHAR" property="goodsJson"/>
+        <result column="coupon_ids_" jdbcType="VARCHAR" property="couponIds"/>
     </resultMap>
     <!-- 根据主键查询一条记录 -->
     <select id="get" resultMap="StudentRepair">
@@ -52,7 +53,7 @@
         insert into student_repair (id_,music_group_id_, trans_no_,student_instrument_id_,maintenance_status_,repair_name_,
         repair_img_,exemption_amount_,organ_id_,student_id_, student_name_,student_school_,employee_id_, employee_name_,
         subject_id_,subject_name_, type_, instrument_no_,fee_list_,description_, amount_, finish_time_,send_type_,
-        contact_name_, contact_mobile_,address_,pay_status_, create_time_,update_time_,repair_status_,goods_json_)
+        contact_name_, contact_mobile_,address_,pay_status_, create_time_,update_time_,repair_status_,goods_json_,coupon_ids_)
         values (#{id,jdbcType=INTEGER},#{musicGroupId}, #{transNo,jdbcType=VARCHAR}, #{studentInstrumentId},
         #{maintenanceStatus},#{repairName},#{repairImg},#{exemptionAmount},#{organId,jdbcType=INTEGER},
         #{studentId,jdbcType=INTEGER}, #{studentName,jdbcType=VARCHAR}, #{studentSchool,jdbcType=VARCHAR},
@@ -61,11 +62,14 @@
         #{feeList,jdbcType=VARCHAR},#{description,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},
         #{finishTime,jdbcType=TIMESTAMP},#{sendType,jdbcType=INTEGER}, #{contactName,jdbcType=VARCHAR},
         #{contactMobile,jdbcType=VARCHAR},#{address,jdbcType=VARCHAR}, #{payStatus,jdbcType=INTEGER},
-        #{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{repairStatus},#{goodsJson})
+        #{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{repairStatus},#{goodsJson},#{couponIds})
     </insert>
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentRepair">
         UPDATE student_repair
         <set>
+            <if test="couponIds != null">
+                coupon_ids_ = #{couponIds},
+            </if>
             <if test="musicGroupId != null">
                 music_group_id_ = #{musicGroupId},
             </if>