Przeglądaj źródła

add web乐器维护列表

周箭河 4 lat temu
rodzic
commit
12338b7b23

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

@@ -2,6 +2,7 @@ package com.ym.mec.biz.service;
 
 import com.ym.mec.biz.dal.entity.StudentInstrument;
 
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.common.service.BaseService;
 
 import java.math.BigDecimal;
@@ -16,4 +17,10 @@ public interface StudentInstrumentService extends BaseService<Long, StudentInstr
      * @return
      */
     Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception;
-}
+
+    /**
+     * 回调页面
+     * @param studentPaymentOrder
+     * @return
+     */
+    Boolean orderCallback(StudentPaymentOrder studentPaymentOrder);

+ 129 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -1,27 +1,31 @@
 package com.ym.mec.biz.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 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.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.dal.entity.*;
+import com.ym.mec.biz.dal.enums.*;
 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;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentInstrument> implements StudentInstrumentService {
@@ -41,7 +45,9 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     @Autowired
     private StudentPaymentOrderService studentPaymentOrderService;
     @Autowired
-    private StudentDao studentDao;
+    private ContractService contractService;
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     @Override
     public BaseDAO<Long, StudentInstrument> getDAO() {
@@ -49,6 +55,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception {
         StudentInstrument studentInstrument = studentInstrumentDao.get(id);
         if (studentInstrument == null) {
@@ -134,4 +141,118 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         studentPaymentOrderService.update(studentPaymentOrder);
         return payMap;
     }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
+        Date nowDate = new Date();
+        //更新订单信息
+        studentPaymentOrder.setUpdateTime(nowDate);
+        int updateCount = studentPaymentOrderService.update(studentPaymentOrder);
+        if (updateCount <= 0) {
+            throw new BizException("订单更新失败");
+        }
+        //更新维修单信息
+        StudentInstrument studentInstrument = get(Long.parseLong(studentPaymentOrder.getMusicGroupId()));
+        if (studentInstrument == null) {
+            throw new BizException("乐保信息不存在");
+        }
+
+        Integer userId = studentPaymentOrder.getUserId();
+
+        Map<Integer, String> map = new HashMap<>();
+        map.put(userId, userId.toString());
+
+        if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
+            try {
+                contractService.transferProduceContract(userId, null);
+            } catch (Exception e) {
+                logger.error("产品协议生成失败", e);
+            }
+
+            repairInfo.setPayStatus(2);
+            repairInfo.setUpdateTime(nowDate);
+            if (this.update(repairInfo) <= 0) {
+                throw new BizException("维修单更新失败");
+            }
+
+            //插入交易明细
+            BigDecimal amount = studentPaymentOrder.getActualAmount();
+            SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
+            //充值
+            SysUserCashAccountDetail rechargeDetail = new SysUserCashAccountDetail();
+            rechargeDetail.setAmount(amount);
+            rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
+            rechargeDetail.setComment("缴费前充值");
+            rechargeDetail.setCreateTime(nowDate);
+            rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
+            rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
+            rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
+            rechargeDetail.setUpdateTime(nowDate);
+            rechargeDetail.setUserId(userId);
+            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
+            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
+            sysUserCashAccountDetailService.insert(rechargeDetail);
+
+            //缴费
+            SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
+            paymentDetail.setAmount(amount.negate());
+            paymentDetail.setBalance(cashAccount.getBalance());
+            paymentDetail.setComment("乐器维修");
+            paymentDetail.setCreateTime(nowDate);
+            paymentDetail.setStatus(DealStatusEnum.SUCCESS);
+            paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
+            paymentDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
+            paymentDetail.setUpdateTime(nowDate);
+            paymentDetail.setUserId(userId);
+            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+            if (studentPaymentOrder.getComAmount() != null) {
+                rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
+                rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
+            }
+            sysUserCashAccountDetailService.insert(paymentDetail);
+            //生成销售订单
+            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(), studentPaymentOrder.getBalancePaymentAmount());
+                }
+            }
+
+            String imContent = repairInfo.getStudentName() + "学员您好,您的乐器维修已受理,我们会尽快完成保养维修";
+
+            if (repairInfo.getType().equals(1)) { //线上
+                imContent = repairInfo.getStudentName() + "学员您好,请尽快寄送乐器至维修点,我们会尽快完成保养维修\n" +
+                        "联系人:" + repairInfo.getEmployeeName() + "(" + repairInfo.getEmployeePhone() + ")\n" +
+                        "地址:" + repairInfo.getEmployeeAddress() + "";
+
+                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_ONLINE_PAYMENT_SUCCESS, map, null, 0, "1", "STUDENT",
+                        repairInfo.getStudentName(), repairInfo.getEmployeeName(), repairInfo.getEmployeePhone(), repairInfo.getEmployeeAddress());
+            } else {
+                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_OFFLINE_PAYMENT_SUCCESS, map, null, 0, "1", "STUDENT",
+                        repairInfo.getStudentName());
+            }
+            sysMessageService.sendNoAuthPrivateMessage(repairInfo.getEmployeeId().toString(), userId.toString(), imContent);
+            return true;
+        }
+
+        if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
+            repairInfo.setPayStatus(0);
+            repairInfo.setUpdateTime(nowDate);
+            if (this.update(repairInfo) <= 0) {
+                throw new BizException("维修单更新失败");
+            }
+            if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
+                sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
+            }
+
+            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_SPORADIC_PAYMENT_FAILED, map, null, 0, "", "STUDENT",
+                    studentPaymentOrder.getActualAmount(), "乐器维修");
+            return false;
+        }
+        return false;
+    }
 }

+ 5 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -13,6 +13,7 @@ import java.util.stream.Collectors;
 
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
+import com.ym.mec.biz.service.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -35,16 +36,6 @@ import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
 import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
 import com.ym.mec.biz.dal.page.SporadicOrderQueryInfo;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
-import com.ym.mec.biz.service.DegreeRegistrationService;
-import com.ym.mec.biz.service.MusicGroupService;
-import com.ym.mec.biz.service.PracticeGroupService;
-import com.ym.mec.biz.service.SporadicChargeInfoService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
-import com.ym.mec.biz.service.StudentRepairService;
-import com.ym.mec.biz.service.SubjectChangeService;
-import com.ym.mec.biz.service.SysUserCashAccountService;
-import com.ym.mec.biz.service.VipGroupService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -95,6 +86,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private SysConfigDao sysConfigDao;
     @Autowired
     private GoodsDao goodsDao;
+    @Autowired
+    private StudentInstrumentService studentInstrumentService;
 
     @Override
     public BaseDAO<Long, StudentPaymentOrder> getDAO() {
@@ -372,6 +365,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             subjectChangeService.orderCallback(order);
         } else if (order.getType().equals(OrderTypeEnum.DEGREE_REGISTRATION)) {
             degreeRegistrationService.updateStatus(order);
+        }else if (order.getType().equals(OrderTypeEnum.MAINTENANCE)) {
+            studentInstrumentService.orderCallback(order);
         }
     }