周箭河 пре 4 година
родитељ
комит
feba719758

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentInstrument.java

@@ -17,6 +17,12 @@ public class StudentInstrument {
     private Integer studentId;
 
     /**
+     * 分部id
+     */
+    @ApiModelProperty(value = "分部id")
+    private Integer organId;
+
+    /**
      * 商品id
      */
     @ApiModelProperty(value = "商品id")
@@ -160,4 +166,12 @@ public class StudentInstrument {
     public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
     }
+
+    public Integer getOrganId() {
+        return organId;
+    }
+
+    public void setOrganId(Integer organId) {
+        this.organId = organId;
+    }
 }

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/GroupType.java

@@ -12,7 +12,8 @@ public enum GroupType implements BaseEnum<String, GroupType> {
 	REPAIR("乐器维修"),
 	GOODS_SELL("商品销售"),
 	OUTORDER("外部订单"),
-	SUBJECT_CHANGE("声部更换");
+	SUBJECT_CHANGE("声部更换"),
+	MAINTENANCE("乐保");
 
 	private String desc;
 

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/OrderTypeEnum.java

@@ -21,7 +21,8 @@ public enum OrderTypeEnum implements BaseEnum<String, OrderTypeEnum> {
 	OUTORDER("OUTORDER", "外部订单"),
 	REPAIR("REPAIR","乐器维修"),
 	SUBJECT_CHANGE("SUBJECT_CHANGE","声部更换"),
-	DEGREE_REGISTRATION("DEGREE_REGISTRATION", "考级报名");
+	DEGREE_REGISTRATION("DEGREE_REGISTRATION", "考级报名"),
+	MAINTENANCE("MAINTENANCE","乐保");
 
 
 	private String code;

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/StudentInstrumentService.java

@@ -11,8 +11,9 @@ public interface StudentInstrumentService extends BaseService<Long, StudentInstr
 
     /**
      * 乐保支付
+     *
      * @param id
      * @return
      */
-    Map pay(Long id, BigDecimal amount);
+    Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception;
 }

+ 40 - 26
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -1,17 +1,16 @@
 package com.ym.mec.biz.service.impl;
 
-
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.TypeReference;
+import com.ym.mec.biz.dal.dao.StudentDao;
 import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
-import com.ym.mec.biz.dal.entity.*;
-import com.ym.mec.biz.dal.enums.GoodsType;
-import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
+import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.SysUserCashAccount;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.dal.enums.GroupType;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
-import com.ym.mec.biz.service.PayService;
-import com.ym.mec.biz.service.StudentInstrumentService;
-import com.ym.mec.biz.service.SysUserCashAccountService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.IdGeneratorService;
@@ -20,8 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 @Service
 public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentInstrument> implements StudentInstrumentService {
@@ -36,6 +36,12 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     private PayService payService;
     @Autowired
     private SysConfigDao sysConfigDao;
+    @Autowired
+    private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
+    @Autowired
+    private StudentDao studentDao;
 
     @Override
     public BaseDAO<Long, StudentInstrument> getDAO() {
@@ -43,7 +49,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     }
 
     @Override
-    public Map pay(Long id,BigDecimal amount) {
+    public Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception {
         StudentInstrument studentInstrument = studentInstrumentDao.get(id);
         if (studentInstrument == null) {
             throw new BizException("所选乐器不存在,请核查");
@@ -51,7 +57,6 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         Integer userId = studentInstrument.getStudentId();
         BigDecimal orderAmount = new BigDecimal(400);
 
-
         if (amount.compareTo(orderAmount) != 0) {
             throw new BizException("商品价格不符");
         }
@@ -59,10 +64,10 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         String orderNo = idGeneratorService.generatorId("payment") + "";
 
         String channelType = "";
-
         Date date = new Date();
+
         BigDecimal balance = BigDecimal.ZERO;
-        if (registerPayDto.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
+        if (isUseBalance && amount.compareTo(BigDecimal.ZERO) > 0) {
             SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
             if (userCashAccount == null) {
                 throw new BizException("用户账户找不到");
@@ -70,23 +75,32 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
             if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
                 balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
                 amount = amount.subtract(balance);
-                studentPaymentOrder.setPaymentChannel("BALANCE");
-                studentPaymentOrder.setActualAmount(amount);
-                studentPaymentOrder.setBalancePaymentAmount(balance);
-                sysUserCashAccountService.updateBalance(userId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团报名");
+                sysUserCashAccountService.updateBalance(userId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐保购买");
             }
         }
+        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
+
         studentPaymentOrder.setPaymentChannel("BALANCE");
+        studentPaymentOrder.setUserId(userId);
+        studentPaymentOrder.setGroupType(GroupType.MAINTENANCE);
+        studentPaymentOrder.setOrderNo(orderNo);
+        studentPaymentOrder.setType(OrderTypeEnum.MAINTENANCE);
+        studentPaymentOrder.setExpectAmount(amount);
+        studentPaymentOrder.setActualAmount(amount);
+        studentPaymentOrder.setBalancePaymentAmount(balance);
+        studentPaymentOrder.setStatus(DealStatusEnum.ING);
+        studentPaymentOrder.setMusicGroupId(studentInstrument.getId().toString());
         studentPaymentOrder.setRemitFee(BigDecimal.ZERO);
         studentPaymentOrder.setCourseRemitFee(BigDecimal.ZERO);
-        studentPaymentOrder.setOrganId(musicGroup.getOrganId());
-        studentPaymentOrder.setRoutingOrganId(musicGroup.getOrganId());
+        studentPaymentOrder.setOrganId(studentInstrument.getOrganId());
+        studentPaymentOrder.setRoutingOrganId(studentInstrument.getOrganId());
+        studentPaymentOrder.setCreateTime(date);
         studentPaymentOrder.setUpdateTime(date);
-        studentPaymentOrderService.update(studentPaymentOrder);
-        studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
+        studentPaymentOrderService.insert(studentPaymentOrder);
+        studentPaymentOrder.setVersion(0);
 
         if (amount.compareTo(BigDecimal.ZERO) == 0) {
-            studentPaymentRouteOrderService.addRouteOrder(orderNo, musicGroup.getOrganId(), balance);
+            studentPaymentRouteOrderService.addRouteOrder(orderNo, studentInstrument.getOrganId(), balance);
             Map<String, String> notifyMap = new HashMap<>();
             notifyMap.put("tradeState", "1");
             notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
@@ -109,11 +123,11 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
                 baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
                 orderSubject,
                 orderSubject,
-                musicGroup.getOrganId(),
+                studentInstrument.getOrganId(),
                 receiver
         );
 
-        studentPaymentOrder.setOrganId(musicGroup.getOrganId());
+        studentPaymentOrder.setOrganId(studentInstrument.getOrganId());
         studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
         studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
         studentPaymentOrder.setUpdateTime(date);

+ 10 - 3
mec-biz/src/main/resources/config/mybatis/StudentInstrumentMapper.xml

@@ -6,6 +6,7 @@
     <!--@Table student_instrument-->
     <id column="id_" property="id" />
     <result column="student_id_" property="studentId" />
+    <result column="organ_id_" property="organId" />
     <result column="goods_id_" property="goodsId" />
     <result column="status_" property="status" />
     <result column="start_time_" property="startTime" />
@@ -19,7 +20,7 @@
   </resultMap>
   <sql id="Base_Column_List">
     <!--@mbg.generated-->
-    id_,student_id_, goods_id_,goods_name_,goods_brand_,specification_,goods_img_, status_, start_time_, end_time_, create_time_, update_time
+    id_,student_id_,organ_id_, goods_id_,goods_name_,goods_brand_,specification_,goods_img_, status_, start_time_, end_time_, create_time_, update_time
   </sql>
   <select id="get" parameterType="java.lang.Integer" resultMap="StudentInstrument">
     <!--@mbg.generated-->
@@ -36,15 +37,21 @@
   
   <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.StudentInstrument" useGeneratedKeys="true">
     <!--@mbg.generated-->
-    insert into student_instrument (student_id_,goods_id_,goods_name_,goods_brand_,specification_,goods_img_, status_, start_time_, end_time_, create_time_, update_time
+    insert into student_instrument (student_id_,organ_id_,goods_id_,goods_name_,goods_brand_,specification_,goods_img_, status_, start_time_, end_time_, create_time_, update_time
       )
-    values (#{studentId},#{goodsId},#{goodsName},#{goodsBrand},#{specification},#{goodsImg}, #{status}, #{startTime}, #{endTime}, #{createTime}, #{updateTime}
+    values (#{studentId},#{organId},#{goodsId},#{goodsName},#{goodsBrand},#{specification},#{goodsImg}, #{status}, #{startTime}, #{endTime}, #{createTime}, #{updateTime}
       )
   </insert>
   <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentInstrument">
     <!--@mbg.generated-->
     update student_instrument
     <set>
+      <if test="studentId != null">
+        student_id_ = #{studentId},
+      </if>
+      <if test="organId != null">
+        organ_id_ = #{organId},
+      </if>
       <if test="goodsId != null">
         goods_id_ = #{goodsId},
       </if>

+ 8 - 3
mec-student/src/main/java/com/ym/mec/student/controller/StudentInstrumentController.java

@@ -20,6 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
+
 @RequestMapping("studentInstrument")
 @Api(tags = "乐器与月保服务")
 @RestController
@@ -43,8 +45,11 @@ public class StudentInstrumentController extends BaseController {
 
     @ApiOperation(value = "乐保支付")
     @PostMapping("/pay")
-    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "开通月保的乐器记录id", required = true, dataType = "int")})
-    public HttpResponseResult pay(Long id) {
-        return null;
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "开通月保的乐器记录id", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "amount", value = "金额", required = true, dataType = "BigDecimal"),
+            @ApiImplicitParam(name = "isUseBalance", value = "是否使用余额", required = true, dataType = "boolean")
+    })
+    public HttpResponseResult pay(Long id, BigDecimal amount, Boolean isUseBalance) throws Exception {
+        return succeed(studentInstrumentService.pay(id, amount, isUseBalance));
     }
 }