|
@@ -0,0 +1,162 @@
|
|
|
+package com.ym.mec.biz.service.impl;
|
|
|
+
|
|
|
+import com.ym.mec.biz.dal.dao.DegreeRegistrationDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SporadicChargeInfoDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+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.service.DegreeRegistrationService;
|
|
|
+import com.ym.mec.biz.service.PayService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderService;
|
|
|
+import com.ym.mec.biz.service.SysConfigService;
|
|
|
+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 org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, DegreeRegistration> implements DegreeRegistrationService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DegreeRegistrationDao degreeRegistrationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SporadicChargeInfoDao sporadicChargeInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IdGeneratorService idGeneratorService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysConfigDao sysConfigDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PayService payService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, DegreeRegistration> getDAO() {
|
|
|
+ return degreeRegistrationDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map pay(DegreeRegistration degreeRegistration) throws Exception {
|
|
|
+ Date nowDate = new Date();
|
|
|
+ //获取收费项价格
|
|
|
+ SporadicChargeInfo chargeInfo = sporadicChargeInfoDao.get(degreeRegistration.getSporadicId());
|
|
|
+ if (chargeInfo == null) {
|
|
|
+ throw new BizException("支付项不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ DegreeRegistration degree = degreeRegistrationDao.findByMobileAndSporadicId(degreeRegistration.getMobile(), degreeRegistration.getSporadicId());
|
|
|
+ if (degree == null) {
|
|
|
+ degreeRegistration.setMoney(chargeInfo.getAmount());
|
|
|
+ degreeRegistration.setStatus(1);
|
|
|
+ degreeRegistration.setCreateTime(nowDate);
|
|
|
+ degreeRegistration.setUpdateTime(nowDate);
|
|
|
+ degreeRegistrationDao.insert(degreeRegistration);
|
|
|
+ }
|
|
|
+ if (degree != null && !degree.getStatus().equals(2)) {
|
|
|
+ degreeRegistration.setId(degree.getId());
|
|
|
+ degreeRegistrationDao.update(degreeRegistration);
|
|
|
+ }
|
|
|
+ degreeRegistrationDao.getLock(degreeRegistration.getId());
|
|
|
+
|
|
|
+ BigDecimal amount = chargeInfo.getAmount();
|
|
|
+
|
|
|
+ OrderTypeEnum type = OrderTypeEnum.SPORADIC;
|
|
|
+
|
|
|
+ Integer userId = degreeRegistration.getId();
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ String channelType = "";
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ studentPaymentOrder.setUserId(userId);
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.SPORADIC);
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setType(type);
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setMusicGroupId(degreeRegistration.getSporadicId().toString());
|
|
|
+ studentPaymentOrder.setOrganId(chargeInfo.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(chargeInfo.getOrganId());
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ Map<String, String> notifyMap = new HashMap<>();
|
|
|
+ notifyMap.put("tradeState", "1");
|
|
|
+ notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
|
|
|
+ notifyMap.put("channelType", channelType);
|
|
|
+ notifyMap.put("orderNo", "");
|
|
|
+ studentPaymentOrderService.updateOrder(notifyMap);
|
|
|
+ return notifyMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
+
|
|
|
+ Map<String, BigDecimal> classFee = new HashMap<>();
|
|
|
+ classFee.put("course", BigDecimal.ZERO);
|
|
|
+ classFee.put("instrument", BigDecimal.ZERO);
|
|
|
+ classFee.put("accessories", BigDecimal.ZERO);
|
|
|
+ classFee.put("other", amount);
|
|
|
+
|
|
|
+ String receiver = "daya";
|
|
|
+ //深圳的零星缴费是在深圳
|
|
|
+ String sDaYaOrganIds = sysConfigDao.findConfigValue(SysConfigService.SZ_DA_YA_ORGAN_IDS);
|
|
|
+ if (StringUtils.isNotBlank(sDaYaOrganIds)) {
|
|
|
+ List<String> sDaYaOrganIdList = Arrays.asList(sDaYaOrganIds.split(","));
|
|
|
+ if (sDaYaOrganIdList.contains(chargeInfo.getOrganId().toString())) {
|
|
|
+ receiver = "sdaya";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map payMap = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ chargeInfo.getTitle(),
|
|
|
+ chargeInfo.getTitle(),
|
|
|
+ userId,
|
|
|
+ classFee,
|
|
|
+ chargeInfo.getOrganId(),
|
|
|
+ receiver
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<String, BigDecimal> routingFee = (Map<String, BigDecimal>) payMap.get("routingFee");
|
|
|
+ studentPaymentOrder.setOrganId(chargeInfo.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId((Integer) payMap.get("routingOrganId"));
|
|
|
+ studentPaymentOrder.setComAmount(routingFee.get("COM"));
|
|
|
+ studentPaymentOrder.setPerAmount(routingFee.get("PER"));
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ return payMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateStatus(Integer id, Integer status) {
|
|
|
+ DegreeRegistration degree = degreeRegistrationDao.getLock(id);
|
|
|
+ if (degree == null || degree.getStatus().equals(2)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ degree.setStatus(status);
|
|
|
+ if (degreeRegistrationDao.update(degree) <= 0) {
|
|
|
+ throw new BizException("更新支付状态失败");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|