|
@@ -1,15 +1,20 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.dao.MemberRankPrivilegesDao;
|
|
|
+import com.ym.mec.biz.dal.dao.MemberRankSettingDao;
|
|
|
import com.ym.mec.biz.dal.dto.MemberPayParamDto;
|
|
|
+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.controller.BaseController;
|
|
|
+import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
+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.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -20,23 +25,11 @@ import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
-import com.ym.mec.auth.api.entity.SysUser;
|
|
|
-import com.ym.mec.biz.dal.dao.MemberRankPrivilegesDao;
|
|
|
-import com.ym.mec.biz.dal.dao.MemberRankSettingDao;
|
|
|
-import com.ym.mec.biz.dal.entity.CloudTeacherOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.MemberFeeSetting;
|
|
|
-import com.ym.mec.biz.dal.entity.MemberRankPrivileges;
|
|
|
-import com.ym.mec.biz.dal.entity.MemberRankSetting;
|
|
|
-import com.ym.mec.biz.dal.entity.Student;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
|
|
|
-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.util.date.DateUtil;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, MemberRankSetting> implements MemberRankSettingService {
|
|
@@ -45,36 +38,28 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
|
|
|
private MemberRankSettingDao memberRankSettingDao;
|
|
|
@Autowired
|
|
|
private MemberRankPrivilegesDao memberRankPrivilegesDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MemberFeeSettingService memberFeeSettingService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private StudentService studentService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ContractService contractService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private CloudTeacherOrderService cloudTeacherOrderService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IdGeneratorService idGeneratorService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysCouponCodeService sysCouponCodeService;
|
|
|
+ @Autowired
|
|
|
+ private StudentCloudCoachPaymentDetailsService studentCloudCoachPaymentDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private CloudCoachPaymentProgramService cloudCoachPaymentProgramService;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
@@ -144,76 +129,45 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
|
|
- public Map buy(MemberPayParamDto memberPayParamDto) throws Exception {
|
|
|
- logger.info("云教练活动购买:memberPayParamDto:{} ",memberPayParamDto);
|
|
|
- Integer userId = memberPayParamDto.getUserId();
|
|
|
- BigDecimal amount = memberPayParamDto.getAmount();
|
|
|
- Integer memberRankId = memberPayParamDto.getMemberRankId();
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpResponseResult buy(MemberPayParamDto memberPayParamDto) throws Exception {
|
|
|
+ logger.info("云教练购买:memberPayParamDto:{} ",memberPayParamDto);
|
|
|
+ Long paymentId = memberPayParamDto.getPaymentId();
|
|
|
+ StudentCloudCoachPaymentDetails cloudCoachPaymentDetails = studentCloudCoachPaymentDetailsService.get(paymentId);
|
|
|
+ if(cloudCoachPaymentDetails == null){
|
|
|
+ throw new BizException("云教练订单不存在,请联系指导老师");
|
|
|
+ }
|
|
|
+ if(cloudCoachPaymentDetails.getPaymentStatus() == 1){
|
|
|
+ throw new BizException("当前云教练订单已支付,感谢您的支持");
|
|
|
+ }
|
|
|
+ //判断用户是否已存在订单
|
|
|
+ List<StudentPaymentOrder> applyOrderList = studentPaymentOrderService.queryByDealStatus(paymentId.toString(), OrderTypeEnum.MEMBER,DealStatusEnum.ING);
|
|
|
+ if (CollectionUtils.isNotEmpty(applyOrderList)) {
|
|
|
+ HttpResponseResult result = studentPaymentOrderService.checkRepeatPay(applyOrderList.get(0), memberPayParamDto.getRepeatPay());
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer userId = cloudCoachPaymentDetails.getUserId();
|
|
|
Student student = studentService.getLocked(userId);
|
|
|
if (student == null) {
|
|
|
throw new BizException("非法访问");
|
|
|
}
|
|
|
- //是否可以购买
|
|
|
- buyCloudTeacherActive(userId,memberPayParamDto.getActiveRemark(),memberPayParamDto.getRemark());
|
|
|
SysUser user = sysUserFeignService.queryUserById(userId);
|
|
|
|
|
|
Integer organId = user.getOrganId();
|
|
|
if (organId == null) {
|
|
|
throw new BizException("学生没有分部编号");
|
|
|
}
|
|
|
+ CloudCoachPaymentProgram cloudCoachPaymentProgram = cloudCoachPaymentProgramService.get(cloudCoachPaymentDetails.getCloudCoachPaymentProgramId());
|
|
|
|
|
|
- MemberRankSetting memberRankSetting = memberRankSettingDao.get(memberRankId);
|
|
|
- if (memberRankSetting == null) {
|
|
|
- throw new BizException("会员等级错误");
|
|
|
- }
|
|
|
-
|
|
|
- MemberFeeSetting memberFeeSetting = memberFeeSettingService.findByRankIdAndOrganId(organId, memberRankId);
|
|
|
-
|
|
|
- if (memberFeeSetting == null) {
|
|
|
- throw new BizException("分部会员价格出现异常");
|
|
|
- }
|
|
|
-
|
|
|
- CloudTeacherOrder cloudTeacherOrder = new CloudTeacherOrder();
|
|
|
-
|
|
|
- BigDecimal actualAmount = BigDecimal.ZERO;
|
|
|
- cloudTeacherOrder.setType(memberPayParamDto.getPeriodEnum());
|
|
|
- switch (memberPayParamDto.getPeriodEnum()) {
|
|
|
- case DAY:
|
|
|
- actualAmount = memberFeeSetting.getCurrentDayFee();
|
|
|
- cloudTeacherOrder.setTime(1);
|
|
|
- break;
|
|
|
- case MONTH:
|
|
|
- actualAmount = memberFeeSetting.getCurrentMonthFee().multiply(new BigDecimal(memberPayParamDto.getBuyNum()));
|
|
|
- //购买月份加上赠送月份,目前只有按月购买的活动,其他的暂不处理
|
|
|
- cloudTeacherOrder.setTime(memberPayParamDto.getBuyNum() + memberPayParamDto.getGiveNum());
|
|
|
- break;
|
|
|
- case QUARTERLY:
|
|
|
- actualAmount = memberFeeSetting.getCurrentQuarterlyFee();
|
|
|
- cloudTeacherOrder.setTime(3);
|
|
|
- break;
|
|
|
- case YEAR_HALF:
|
|
|
- actualAmount = memberFeeSetting.getCurrentHalfYearFee();
|
|
|
- cloudTeacherOrder.setTime(6);
|
|
|
- break;
|
|
|
- case YEAR:
|
|
|
- actualAmount = memberFeeSetting.getCurrentYearFee();
|
|
|
- cloudTeacherOrder.setTime(1);
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- // 判断金额是否正确
|
|
|
- if (actualAmount.compareTo(amount) != 0) {
|
|
|
- throw new BizException("非法请求");
|
|
|
- }
|
|
|
+ BigDecimal actualAmount = cloudCoachPaymentProgram.getActualAmount();
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
- StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(memberPayParamDto.getCouponIdList(),amount,true);
|
|
|
- amount = studentPaymentOrder.getActualAmount();
|
|
|
+ StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(memberPayParamDto.getCouponIdList(),actualAmount,true);
|
|
|
+ actualAmount = studentPaymentOrder.getActualAmount();
|
|
|
studentPaymentOrder.setUserId(userId);
|
|
|
studentPaymentOrder.setOrganId(organId);
|
|
|
studentPaymentOrder.setRoutingOrganId(organId);
|
|
@@ -226,28 +180,16 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
|
|
|
studentPaymentOrder.setGroupType(GroupType.MEMBER);
|
|
|
studentPaymentOrder.setRemitFee(BigDecimal.ZERO);
|
|
|
studentPaymentOrder.setCourseRemitFee(BigDecimal.ZERO);
|
|
|
- studentPaymentOrder.setMemo(memberRankSetting.getName());
|
|
|
+ studentPaymentOrder.setMemo(cloudCoachPaymentProgram.getRemark());
|
|
|
studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
- studentPaymentOrder.setMusicGroupId(memberRankId + "");
|
|
|
-
|
|
|
- if (memberPayParamDto.isUseBalance()) {
|
|
|
- SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
|
|
|
- if (userCashAccount == null) {
|
|
|
- throw new BizException("用户账户找不到");
|
|
|
- }
|
|
|
- studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
- if (userCashAccount.getBalance().subtract(amount).doubleValue() >= 0) {
|
|
|
- studentPaymentOrder.setActualAmount(BigDecimal.ZERO);
|
|
|
- studentPaymentOrder.setBalancePaymentAmount(amount);
|
|
|
- sysUserCashAccountService.updateBalance(userId, amount.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "购买会员");
|
|
|
-
|
|
|
- } else {
|
|
|
- if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
- sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "购买会员");
|
|
|
- studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
|
- studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount().subtract(userCashAccount.getBalance()));
|
|
|
- }
|
|
|
- }
|
|
|
+ studentPaymentOrder.setMusicGroupId(paymentId.toString());
|
|
|
+ // 判断金额是否正确
|
|
|
+ if (actualAmount.compareTo(memberPayParamDto.getAmount()) != 0) {
|
|
|
+ throw new BizException("非法请求");
|
|
|
+ }
|
|
|
+ //使用余额支付
|
|
|
+ if (memberPayParamDto.getUseBalancePayment()) {
|
|
|
+ useBalanceAmount(studentPaymentOrder,"购买会员");
|
|
|
}
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
studentPaymentOrder.setOrderNo(orderNo);
|
|
@@ -255,27 +197,35 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
|
|
|
studentPaymentOrder.setUpdateTime(date);
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
-
|
|
|
- // 订单明细
|
|
|
- cloudTeacherOrder.setOrganId(studentPaymentOrder.getOrganId());
|
|
|
- cloudTeacherOrder.setStudentId(studentPaymentOrder.getUserId());
|
|
|
- cloudTeacherOrder.setLevel(memberRankId);
|
|
|
- cloudTeacherOrder.setAmount(amount);
|
|
|
- cloudTeacherOrder.setStatus(0);
|
|
|
- cloudTeacherOrder.setOrderId(studentPaymentOrder.getId());
|
|
|
- cloudTeacherOrder.setCreateTime(date);
|
|
|
- cloudTeacherOrder.setUpdateTime(date);
|
|
|
- cloudTeacherOrder.setActiveRemark(memberPayParamDto.getActiveRemark());
|
|
|
- cloudTeacherOrder.setRemark(memberPayParamDto.getRemark());
|
|
|
- cloudTeacherOrderService.insert(cloudTeacherOrder);
|
|
|
-
|
|
|
Map result = studentPaymentOrderService.createOrder(studentPaymentOrder, null, "BUY_MEMBER");
|
|
|
+ return BaseController.succeed(result);
|
|
|
+ }
|
|
|
|
|
|
- return result;
|
|
|
+ public StudentPaymentOrder useBalanceAmount(StudentPaymentOrder studentPaymentOrder,String memo){
|
|
|
+ Integer userId = studentPaymentOrder.getUserId();
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
|
|
|
+ if (userCashAccount == null) {
|
|
|
+ throw new BizException("用户账户找不到");
|
|
|
+ }
|
|
|
+ BigDecimal actualAmount = studentPaymentOrder.getActualAmount();
|
|
|
+ studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
+ if (userCashAccount.getBalance().subtract(actualAmount).doubleValue() >= 0) {
|
|
|
+ studentPaymentOrder.setActualAmount(BigDecimal.ZERO);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(actualAmount);
|
|
|
+ sysUserCashAccountService.updateBalance(userId, actualAmount.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, memo);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, memo);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
|
+ studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount().subtract(userCashAccount.getBalance()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return studentPaymentOrder;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
|
|
|
Integer userId = studentPaymentOrder.getUserId();
|
|
@@ -311,27 +261,28 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
|
|
|
|
|
|
// 支付成功
|
|
|
if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
- // 查询会员订单信息
|
|
|
-// CloudTeacherOrder cloudTeacherOrder = cloudTeacherOrderService.queryByOrderId(studentPaymentOrder.getId());
|
|
|
-// cloudTeacherOrder.setStatus(2);
|
|
|
-// cloudTeacherOrder.setUpdateTime(nowDate);
|
|
|
-//
|
|
|
-// PeriodEnum periodEnum = cloudTeacherOrder.getType();
|
|
|
-
|
|
|
-// if (student.getMemberRankSettingId() == null || nowDate.after(student.getMembershipEndTime())) {
|
|
|
-// cloudTeacherOrder.setStartTime(nowDate);
|
|
|
-// cloudTeacherOrder.setEndTime(studentService.getMembershipEndTime(periodEnum,nowDate,cloudTeacherOrder.getTime()));
|
|
|
-// } else {
|
|
|
-// cloudTeacherOrder.setStartTime(DateUtil.addDays(student.getMembershipEndTime(), 1));
|
|
|
-// cloudTeacherOrder.setEndTime(studentService.getMembershipEndTime(periodEnum,student.getMembershipEndTime(),cloudTeacherOrder.getTime()));
|
|
|
-// }
|
|
|
-
|
|
|
-// cloudTeacherOrderService.update(cloudTeacherOrder);
|
|
|
- // 添加会员有效时长
|
|
|
-// studentService.updateMemberRank(cloudTeacherOrder);
|
|
|
- //云教练活动赠送优惠券
|
|
|
-// cloudTeacherActiveGiveCoupon(cloudTeacherOrder);
|
|
|
-// // 插入交易明细
|
|
|
+ StudentCloudCoachPaymentDetails coachPaymentDetails = studentCloudCoachPaymentDetailsService.get(Long.parseLong(studentPaymentOrder.getMusicGroupId()));
|
|
|
+ CloudCoachPaymentProgram cloudCoachPaymentProgram = cloudCoachPaymentProgramService.get(coachPaymentDetails.getCloudCoachPaymentProgramId());
|
|
|
+ //保存云教练数据
|
|
|
+ CloudTeacherOrder cloudTeacherOrder = new CloudTeacherOrder();
|
|
|
+ cloudTeacherOrder.setOrderId(studentPaymentOrder.getId());
|
|
|
+ cloudTeacherOrder.setLevel(cloudCoachPaymentProgram.getMemberRankSettingId());
|
|
|
+ cloudTeacherOrder.setStatus(1);
|
|
|
+ cloudTeacherOrder.setType(cloudCoachPaymentProgram.getPeriod());
|
|
|
+ cloudTeacherOrder.setTime(cloudCoachPaymentProgram.getMemberNum().intValue());
|
|
|
+ cloudTeacherOrder.setStudentId(coachPaymentDetails.getUserId());
|
|
|
+ cloudTeacherOrder.setOrganId(studentPaymentOrder.getOrganId());
|
|
|
+ cloudTeacherOrder.setAmount(studentPaymentOrder.getActualAmount());
|
|
|
+ cloudTeacherOrderService.insert(cloudTeacherOrder);
|
|
|
+
|
|
|
+ //修改缴费状态
|
|
|
+ coachPaymentDetails.setPaymentStatus(1);
|
|
|
+ coachPaymentDetails.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+ studentCloudCoachPaymentDetailsService.update(coachPaymentDetails);
|
|
|
+ //修改实际缴费人数
|
|
|
+ cloudCoachPaymentProgram.setPaymentUserNum(cloudCoachPaymentProgram.getPaymentUserNum() + 1);
|
|
|
+ cloudCoachPaymentProgramService.update(cloudCoachPaymentProgram);
|
|
|
+ // 插入交易明细
|
|
|
BigDecimal amount = studentPaymentOrder.getActualAmount();
|
|
|
if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
|
|
@@ -407,17 +358,16 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
|
|
|
}
|
|
|
result.setCode(HttpStatus.OK.value());
|
|
|
MemberPayParamDto memberPayParamDto = new MemberPayParamDto();
|
|
|
- memberPayParamDto.setMemberRankId(memberRankId);
|
|
|
- memberPayParamDto.setUserId(userId);
|
|
|
- memberPayParamDto.setPeriodEnum(month);
|
|
|
- memberPayParamDto.setUseBalance(isUseBalance);
|
|
|
- memberPayParamDto.setBuyNum(buyNum);
|
|
|
- memberPayParamDto.setGiveNum(giveNum);
|
|
|
- memberPayParamDto.setActiveRemark(activeRemark);
|
|
|
- memberPayParamDto.setRemark(remark);
|
|
|
+// memberPayParamDto.setMemberRankId(memberRankId);
|
|
|
+// memberPayParamDto.setUserId(userId);
|
|
|
+// memberPayParamDto.setPeriodEnum(month);
|
|
|
+// memberPayParamDto.setUseBalance(isUseBalance);
|
|
|
+// memberPayParamDto.setBuyNum(buyNum);
|
|
|
+// memberPayParamDto.setGiveNum(giveNum);
|
|
|
+// memberPayParamDto.setActiveRemark(activeRemark);
|
|
|
+// memberPayParamDto.setRemark(remark);
|
|
|
memberPayParamDto.setAmount(amount);
|
|
|
- result.setData(this.buy(memberPayParamDto));
|
|
|
- return result;
|
|
|
+ return this.buy(memberPayParamDto);
|
|
|
}
|
|
|
|
|
|
//云教练活动赠送优惠券
|