|
@@ -1,23 +1,20 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
|
-import com.ym.mec.biz.dal.entity.Organization;
|
|
|
+import com.ym.mec.biz.dal.dto.DegreeRegistrationActivityDto;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.ym.mec.biz.dal.dto.PageInfoDegree;
|
|
|
-import com.ym.mec.biz.dal.entity.DegreeRegistration;
|
|
|
-import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
@@ -53,7 +50,13 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
private PayService payService;
|
|
|
|
|
|
@Autowired
|
|
|
- private OrganizationDao organizationDao;
|
|
|
+ private PracticeGroupSellPriceDao practiceGroupSellPriceDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, DegreeRegistration> getDAO() {
|
|
@@ -61,8 +64,12 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Map pay(DegreeRegistration degreeRegistration) throws Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public Map pay(DegreeRegistrationActivityDto degreeRegistration) throws Exception {
|
|
|
+ Student student = studentDao.getLocked(degreeRegistration.getUserId());
|
|
|
+
|
|
|
+ DegreeRegistration degree = degreeRegistrationDao.getWithUserIdAndActivityTag(degreeRegistration.getUserId(), ACTIVITY_TAG);
|
|
|
+
|
|
|
Date nowDate = new Date();
|
|
|
//获取收费项价格
|
|
|
SporadicChargeInfo chargeInfo = sporadicChargeInfoDao.get(degreeRegistration.getSporadicId());
|
|
@@ -75,20 +82,11 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
throw new BizException("报考级别为“" + chargeInfo.getTitle() + "”且乐理级别是“免考”时,必须上传证书");
|
|
|
}
|
|
|
|
|
|
- List<Organization> organs = organizationDao.findAllOrgans();
|
|
|
- Integer organId = chargeInfo.getOrganId();
|
|
|
- for (Organization organ : organs) {
|
|
|
- if (degreeRegistration.getCity().contains(organ.getName())) {
|
|
|
- organId = organ.getId();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
|
|
|
+ degreeRegistration.setActivityTag(ACTIVITY_TAG);
|
|
|
degreeRegistration.setLevel(chargeInfo.getTitle());
|
|
|
degreeRegistration.setOrderNo(orderNo);
|
|
|
- degreeRegistration.setOrganId(organId);
|
|
|
BigDecimal theoryMoney = BigDecimal.ZERO;
|
|
|
switch (degreeRegistration.getTheoryLevel()) {
|
|
|
case "一级":
|
|
@@ -109,7 +107,6 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
throw new BizException("您选择的乐理级别不存在,请核对");
|
|
|
}
|
|
|
degreeRegistration.setTheoryMoney(theoryMoney);
|
|
|
- DegreeRegistration degree = degreeRegistrationDao.findByMobileAndSporadicId(degreeRegistration.getMobile(), degreeRegistration.getSporadicId());
|
|
|
if (degree == null) {
|
|
|
degreeRegistration.setMoney(chargeInfo.getAmount());
|
|
|
degreeRegistration.setStatus(1);
|
|
@@ -117,7 +114,7 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
degreeRegistration.setUpdateTime(nowDate);
|
|
|
degreeRegistrationDao.insert(degreeRegistration);
|
|
|
} else if (degree.getStatus().equals(2)) {
|
|
|
- throw new BizException("您本次已报名,请勿重复报名");
|
|
|
+ //throw new BizException("您本次已报名,请勿重复报名");
|
|
|
} else {
|
|
|
degreeRegistration.setId(degree.getId());
|
|
|
degreeRegistration.setStatus(1);
|
|
@@ -125,13 +122,62 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
degreeRegistration.setUpdateTime(nowDate);
|
|
|
degreeRegistrationDao.update(degreeRegistration);
|
|
|
}
|
|
|
- degreeRegistrationDao.getLock(degreeRegistration.getId());
|
|
|
|
|
|
+ BigDecimal additionCoursePrice = new BigDecimal("0");
|
|
|
+ Map<CourseSchedule.CourseScheduleType, Integer> typeCourseTime = new HashMap<>();
|
|
|
+ if(Objects.nonNull(degreeRegistration.getAdditionCourseInfo())){
|
|
|
+ Map<CourseSchedule.CourseScheduleType, Integer> additionCourseInfo = degreeRegistration.getAdditionCourseInfo();
|
|
|
+ PracticeGroupSellPrice practiceGroupSellPrice = practiceGroupSellPriceDao.get(degreeRegistration.getId());
|
|
|
+ if(Objects.isNull(practiceGroupSellPrice)){
|
|
|
+ throw new BizException("该分部暂未参与此活动");
|
|
|
+ }
|
|
|
+ BigDecimal practiceUnitPrice = practiceGroupSellPrice.getOnceActivityPrice(),
|
|
|
+ vipUnitPrice = new BigDecimal("0"), highUnitPrice;
|
|
|
+ if(student.getIsNewUser()){
|
|
|
+ vipUnitPrice = practiceGroupSellPrice.getVipOneStudentTwelveCourseActivityPriceWithNewUser();
|
|
|
+ highUnitPrice = practiceGroupSellPrice.getHighOnlineTenCourseOriginalPriceWithNewUser();
|
|
|
+ if(!additionCourseInfo.containsKey(CourseSchedule.CourseScheduleType.VIP)){
|
|
|
+ additionCourseInfo.remove(CourseSchedule.CourseScheduleType.PRACTICE);
|
|
|
+ }
|
|
|
+ boolean vipMoreThan2 = additionCourseInfo.containsKey(CourseSchedule.CourseScheduleType.VIP)&&additionCourseInfo.get(CourseSchedule.CourseScheduleType.VIP)>=2;
|
|
|
+ if(vipMoreThan2){
|
|
|
+ degreeRegistration.setMoney(BigDecimal.ZERO);
|
|
|
+ highUnitPrice = practiceGroupSellPrice.getHighOnlineTenCourseActivityPriceWithNewUser();
|
|
|
+
|
|
|
+ }
|
|
|
+ if(vipMoreThan2&&additionCourseInfo.containsKey(CourseSchedule.CourseScheduleType.HIGH)){
|
|
|
+ degreeRegistration.setTheoryMoney(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ highUnitPrice = practiceGroupSellPrice.getHighOnlineTenCourseActivityPriceWithOldUser();
|
|
|
+ if(!additionCourseInfo.containsKey(CourseSchedule.CourseScheduleType.HIGH)){
|
|
|
+ additionCourseInfo.remove(CourseSchedule.CourseScheduleType.PRACTICE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Map.Entry<CourseSchedule.CourseScheduleType, Integer> courseScheduleTypeIntegerEntry : additionCourseInfo.entrySet()) {
|
|
|
+ BigDecimal courseTime = new BigDecimal(courseScheduleTypeIntegerEntry.getValue());
|
|
|
+ switch (courseScheduleTypeIntegerEntry.getKey()){
|
|
|
+ case VIP:
|
|
|
+ additionCoursePrice = additionCoursePrice.add(vipUnitPrice.multiply(courseTime));
|
|
|
+ typeCourseTime.put(courseScheduleTypeIntegerEntry.getKey(), courseScheduleTypeIntegerEntry.getValue()*12);
|
|
|
+ break;
|
|
|
+ case PRACTICE:
|
|
|
+ additionCoursePrice = additionCoursePrice.add(practiceUnitPrice.multiply(courseTime));
|
|
|
+ typeCourseTime.put(courseScheduleTypeIntegerEntry.getKey(), courseScheduleTypeIntegerEntry.getValue()*12);
|
|
|
+ break;
|
|
|
+ case HIGH:
|
|
|
+ additionCoursePrice = additionCoursePrice.add(highUnitPrice.multiply(courseTime));
|
|
|
+ typeCourseTime.put(courseScheduleTypeIntegerEntry.getKey(), courseScheduleTypeIntegerEntry.getValue()*10);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- BigDecimal amount = chargeInfo.getAmount();
|
|
|
+ BigDecimal amount = degreeRegistration.getMoney();
|
|
|
amount = amount.add(theoryMoney);
|
|
|
+ amount = amount.add(additionCoursePrice);
|
|
|
|
|
|
- OrderTypeEnum type = OrderTypeEnum.SPORADIC;
|
|
|
+ OrderTypeEnum type = OrderTypeEnum.DEGREE_REGISTRATION;
|
|
|
|
|
|
Integer userId = degreeRegistration.getId();
|
|
|
String channelType = "";
|
|
@@ -144,8 +190,8 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
studentPaymentOrder.setActualAmount(amount);
|
|
|
studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
studentPaymentOrder.setMusicGroupId(degreeRegistration.getSporadicId().toString());
|
|
|
- studentPaymentOrder.setOrganId(organId);
|
|
|
- studentPaymentOrder.setRoutingOrganId(organId);
|
|
|
+ studentPaymentOrder.setOrganId(degreeRegistration.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(degreeRegistration.getOrganId());
|
|
|
if (theoryMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
studentPaymentOrder.setMemo("乐理" + degreeRegistration.getTheoryLevel() + ",费用:" + theoryMoney);
|
|
|
}
|
|
@@ -162,6 +208,18 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
return notifyMap;
|
|
|
}
|
|
|
|
|
|
+ if(BigDecimal.ZERO.compareTo(additionCoursePrice)>0){
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.DEGREE_REGISTRATION);
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(JSON.toJSONString(typeCourseTime));
|
|
|
+ studentPaymentOrderDetail.setPrice(additionCoursePrice);
|
|
|
+ studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+ studentPaymentOrderDetail.setCreateTime(nowDate);
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(nowDate);
|
|
|
+ studentPaymentOrderDetailDao.insert(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+
|
|
|
String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
|
|
|
String receiver = "kjRegister";
|
|
@@ -173,11 +231,11 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
chargeInfo.getDetail(),
|
|
|
chargeInfo.getDetail(),
|
|
|
- organId,
|
|
|
+ degreeRegistration.getOrganId(),
|
|
|
receiver
|
|
|
);
|
|
|
|
|
|
- studentPaymentOrder.setOrganId(organId);
|
|
|
+ studentPaymentOrder.setOrganId(degreeRegistration.getOrganId());
|
|
|
studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
studentPaymentOrder.setUpdateTime(nowDate);
|
|
@@ -186,15 +244,22 @@ public class DegreeRegistrationServiceImpl extends BaseServiceImpl<Integer, Degr
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean updateStatus(Integer id, Integer status, String orderNo) {
|
|
|
- DegreeRegistration degree = degreeRegistrationDao.getLock(id);
|
|
|
+ public Boolean updateStatus(StudentPaymentOrder studentPaymentOrder) {
|
|
|
+ DegreeRegistration degree = degreeRegistrationDao.getLock(studentPaymentOrder.getUserId());
|
|
|
if (degree == null || degree.getStatus().equals(2)) {
|
|
|
return true;
|
|
|
}
|
|
|
- StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(orderNo);
|
|
|
- degree.setOrderNo(orderNo);
|
|
|
- degree.setTransNo(order.getTransNo());
|
|
|
- degree.setStatus(status);
|
|
|
+ degree.setOrderNo(studentPaymentOrder.getOrderNo());
|
|
|
+ degree.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
+ switch (studentPaymentOrder.getStatus()){
|
|
|
+ case SUCCESS:
|
|
|
+ degree.setStatus(2);
|
|
|
+ break;
|
|
|
+ case FAILED:
|
|
|
+ case CLOSE:
|
|
|
+ degree.setStatus(0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
degree.setUpdateTime(new Date());
|
|
|
if (degreeRegistrationDao.update(degree) <= 0) {
|
|
|
throw new BizException("更新支付状态失败");
|