소스 검색

乐器维修支持优惠券

zouxuan 3 년 전
부모
커밋
ea77903aca

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

@@ -68,9 +68,19 @@ public class StudentGoodsSell {
 	@ApiModelProperty(value = "优惠券列表", required = false)
 	private List<Integer> couponIdList;
 
+	private String couponIds;
+
 	@ApiModelProperty(value = "优惠券详情列表", required = false)
 	private List<SysCouponCodeDto> couponCodeDtoList;
 
+	public String getCouponIds() {
+		return couponIds;
+	}
+
+	public void setCouponIds(String couponIds) {
+		this.couponIds = couponIds;
+	}
+
 	public List<SysCouponCodeDto> getCouponCodeDtoList() {
 		return couponCodeDtoList;
 	}

+ 2 - 15
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentRepair.java

@@ -1,12 +1,13 @@
 package com.ym.mec.biz.dal.entity;
 
+import com.ym.mec.biz.dal.dto.PayParamBasicDto;
 import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 import java.math.BigDecimal;
 import java.util.Date;
 
-public class StudentRepair {
+public class StudentRepair extends PayParamBasicDto {
     private Integer id;
     /**
      * 维修单号
@@ -197,12 +198,6 @@ public class StudentRepair {
     private Integer repairStatus;
 
     /**
-     * 使用余额
-     */
-    @ApiModelProperty(value = "使用余额", required = false)
-    private Boolean isUseBalancePayment;
-
-    /**
      * 送修时间
      */
     @ApiModelProperty(value = "送修时间", required = true)
@@ -441,14 +436,6 @@ public class StudentRepair {
         this.employeeAddress = employeeAddress;
     }
 
-    public Boolean getIsUseBalancePayment() {
-        return isUseBalancePayment;
-    }
-
-    public void setIsUseBalancePayment(Boolean useBalancePayment) {
-        isUseBalancePayment = useBalancePayment;
-    }
-
     @Override
     public String toString() {
         return ToStringBuilder.reflectionToString(this);

+ 5 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java

@@ -17,12 +17,13 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
     /**
      * 添加销售订单
      *
-     * @param goodsIds
-     * @param totalAmount
-     * @param balance
+     * @param goodsIds 商品列表
+     * @param totalAmount 订单总额
+     * @param balance 余额支付
+     * @param couponRemitFee 优惠券减免
      * @return
      */
-    List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance);
+    List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance, BigDecimal couponRemitFee);
 
     /**
      * 将订单详情加入销售列表

+ 23 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -50,7 +50,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 
     @Override
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-    public List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance) {
+    public List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance, BigDecimal couponRemitFee) {
         if (goodsIds == null || goodsIds.size() <= 0) {
             return null;
         }
@@ -75,6 +75,12 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 }
             }
         }
+        //商品总价值去掉优惠券减免
+        if(goodsTotalPrice.compareTo(couponRemitFee) <= 0){
+            goodsTotalPrice = BigDecimal.ZERO;
+        }else {
+            goodsTotalPrice = goodsTotalPrice.subtract(couponRemitFee);
+        }
 
         //已分配的商品余额
         BigDecimal hasRouteBalance = BigDecimal.ZERO;
@@ -87,8 +93,9 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos());
 
         List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIds, accountType);
-
-        for (Integer goodsId : goodsIds) {
+        BigDecimal freeCouponRemitFee = couponRemitFee;
+        for (int j = 0; j < goodsIds.size(); j++) {
+            Integer goodsId = goodsIds.get(j);
             BigDecimal goodsPrice = BigDecimal.ZERO;
             Goods nowGoods = new Goods();
             for (Goods goods : goodies) {
@@ -98,6 +105,19 @@ 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);
+                }
+            }
 
             //当前商品占用的总余额
             BigDecimal goodsBalance = goodsTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :

+ 4 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java

@@ -149,13 +149,10 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
     public StudentGoodsSell getStudentGoodsOrder(Integer goodsSellId) {
         StudentGoodsSell studentGoodsSell = studentGoodsSellDao.get(goodsSellId);
         //获取优惠券列表
-        StudentPaymentOrder paymentOrder = studentPaymentOrderDao.findOrderByOrderNo(studentGoodsSell.getOrderNo());
-        if(paymentOrder != null){
-            String couponCodeId = paymentOrder.getCouponCodeId();
-            if(StringUtils.isNotEmpty(couponCodeId)){
-                List<Integer> couponIdList = Arrays.stream(couponCodeId.split(",")).map(id -> Integer.valueOf(id)).collect(Collectors.toList());
-                studentGoodsSell.setCouponCodeDtoList(sysCouponCodeDao.findByIdList(couponIdList));
-            }
+        String couponIds = studentGoodsSell.getCouponIds();
+        if(StringUtils.isNotEmpty(couponIds)){
+            List<Integer> couponIdList = Arrays.stream(couponIds.split(",")).map(id -> Integer.valueOf(id)).collect(Collectors.toList());
+            studentGoodsSell.setCouponCodeDtoList(sysCouponCodeDao.findByIdList(couponIdList));
         }
         return studentGoodsSell;
     }

+ 26 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -220,6 +220,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
         String orderNo = idGeneratorService.generatorId("payment") + "";
         studentGoodsSell.setOrderNo(orderNo);
+        List<Integer> couponIdList = studentGoodsSell.getCouponIdList();
+        if(couponIdList != null && couponIdList.size() > 0){
+            studentGoodsSell.setCouponIds(StringUtils.join(couponIdList,","));
+        }
         studentGoodsSellDao.insert(studentGoodsSell);
 
         if (studentGoodsSell.getType() == 1) {
@@ -454,6 +458,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 }
             }
         }
+        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(repairInfo.getCouponIdList(),amount);
+        amount = studentPaymentOrder.getActualAmount();
         amount = amount.subtract(repairInfo.getExemptionAmount());
         if (amount.compareTo(BigDecimal.ZERO) < 0) {
             throw new BizException("特权减免金额不能大于总金额");
@@ -469,13 +475,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         repairInfo.setPayStatus(1);
         String channelType = "";
 
-        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
         studentPaymentOrder.setUserId(repairInfo.getStudentId());
         studentPaymentOrder.setGroupType(GroupType.REPAIR);
         studentPaymentOrder.setOrderNo(orderNo);
         studentPaymentOrder.setType(OrderTypeEnum.REPAIR);
-        studentPaymentOrder.setExpectAmount(amount);
-        studentPaymentOrder.setActualAmount(amount);
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
         studentPaymentOrder.setMusicGroupId(repairInfo.getId().toString());
         studentPaymentOrder.setPaymentChannel("BALANCE");
@@ -487,7 +490,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setVersion(0);
 
         BigDecimal balance = BigDecimal.ZERO;
-        if (repairInfo.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
+        if (repairInfo.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
             SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(repairInfo.getStudentId());
             if (userCashAccount == null) {
                 throw new BizException("用户账户找不到");
@@ -612,7 +615,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         amount = amount.subtract(studentRepair.getExemptionAmount());
 
         String orderNo = idGeneratorService.generatorId("payment") + "";
-        studentRepair.setIsUseBalancePayment(repairInfo.getIsUseBalancePayment());
+        studentRepair.setUseBalancePayment(repairInfo.getUseBalancePayment());
         studentRepair.setTransNo(orderNo);
         studentRepair.setRepairStatus(0);
         studentRepair.setPayStatus(1);
@@ -643,7 +646,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setVersion(0);
 
         BigDecimal balance = BigDecimal.ZERO;
-        if (studentRepair.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
+        if (studentRepair.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
             SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentRepair.getStudentId());
             if (userCashAccount == null) {
                 throw new BizException("用户账户找不到");
@@ -1071,12 +1074,28 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
             }
             sysUserCashAccountDetailService.insert(paymentDetail);
+            //优惠券减免金额
+            BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
+            if(studentPaymentOrder.getCouponRemitFee().compareTo(BigDecimal.ZERO) > 0 && repairInfo.getAmount().compareTo(BigDecimal.ZERO) > 0){
+                //获取维修金额
+                BigDecimal repairAmount = repairInfo.getAmount();
+                //获取比例
+                BigDecimal divide = repairAmount.divide(repairAmount.add(couponRemitFee), 6, BigDecimal.ROUND_HALF_UP);
+                BigDecimal bigDecimal = couponRemitFee.multiply(divide).setScale(2, BigDecimal.ROUND_HALF_UP);
+                couponRemitFee = couponRemitFee.subtract(bigDecimal);
+                repairInfo.setAmount(repairAmount.subtract(bigDecimal));
+                studentRepairDao.update(repairInfo);
+            }
             //生成销售订单
             if (StringUtils.isNotBlank(repairInfo.getGoodsJson())) {
                 List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
                 List<Integer> goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
                 if (goodsIds.size() > 0) {
-                    sellOrderService.addSellOrder(studentPaymentOrder.getId(), null, goodsIds, studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()), studentPaymentOrder.getBalancePaymentAmount());
+                    sellOrderService.addSellOrder(studentPaymentOrder.getId(),
+                            null,
+                            goodsIds,
+                            studentPaymentOrder.getExpectAmount().add(repairInfo.getExemptionAmount()),
+                            studentPaymentOrder.getBalancePaymentAmount(),couponRemitFee);
                 }
             }
 

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

@@ -21,6 +21,7 @@
 		<result column="cooperation_organ_id_" property="cooperationOrganId" />
 		<result column="create_time_" property="createTime" />
 		<result column="update_time_" property="updateTime" />
+		<result column="coupon_ids_" property="couponIds" />
 	</resultMap>
 	
 	<!-- 根据主键查询一条记录 -->
@@ -38,14 +39,17 @@
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentGoodsSell" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
 		INSERT INTO student_goods_sell (user_id_,teacher_id_,goods_json_,total_amount_,market_amount_,
-		create_time_,update_time_,order_no_,organ_id_,author_user_,cooperation_organ_id_,coupon_market_amount_)
+		create_time_,update_time_,order_no_,organ_id_,author_user_,cooperation_organ_id_,coupon_market_amount_,coupon_ids_)
 		VALUES(#{userId},#{teacherId},#{goodsJson},#{totalAmount},#{marketAmount},
-		NOW(),NOW(),#{orderNo},#{organId},#{authorUser},#{cooperationOrganId},#{couponMarketAmount})
+		NOW(),NOW(),#{orderNo},#{organId},#{authorUser},#{cooperationOrganId},#{couponMarketAmount},#{couponIds})
 	</insert>
 	
 	<!-- 根据主键查询一条记录 -->
 	<update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentGoodsSell">
 		UPDATE student_goods_sell <set>
+		<if test="couponIds != null">
+			coupon_ids_ = #{couponIds},
+		</if>
 		<if test="couponMarketAmount != null">
 			coupon_market_amount_ = #{couponMarketAmount},
 		</if>

+ 1 - 1
mec-web/src/main/java/com/ym/mec/web/controller/education/EduRepairController.java

@@ -103,7 +103,7 @@ public class EduRepairController extends BaseController {
 
     @ApiOperation("添加维修单")
     @PostMapping(value = "/addRepair")
-    public HttpResponseResult addRepair(StudentRepair repairInfo) throws Exception {
+    public HttpResponseResult addRepair(@RequestBody StudentRepair repairInfo) throws Exception {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if (sysUser == null) {
             return failed(HttpStatus.FORBIDDEN, "请登录");