|
@@ -24,6 +24,7 @@ import com.ym.mec.util.http.HttpUtil;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -125,6 +126,15 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
|
|
|
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
|
|
|
+ @Autowired
|
|
|
+ private StudentRegistrationService studentRegistrationService;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
|
|
|
+ @Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<String, MusicGroup> getDAO() {
|
|
@@ -215,6 +225,285 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map pay(RegisterPayDto registerPayDto) throws Exception {
|
|
|
+
|
|
|
+ StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
|
|
|
+ if (studentRegistration == null) {
|
|
|
+ throw new BizException("报名信息有误,请核查");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer userId = studentRegistration.getUserId();
|
|
|
+
|
|
|
+ BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
|
|
|
+ BigDecimal orderAmount = new BigDecimal("0");
|
|
|
+
|
|
|
+ //获取课程价格
|
|
|
+ MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
|
|
|
+ BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
|
|
|
+ if (studentRegistration.getTemporaryCourseFee() != null) {
|
|
|
+ courseFee = studentRegistration.getTemporaryCourseFee();
|
|
|
+ }
|
|
|
+ orderAmount = orderAmount.add(courseFee);
|
|
|
+
|
|
|
+
|
|
|
+ //乐器及打包辅件
|
|
|
+ List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
|
|
|
+
|
|
|
+ if (studentRegistration.getTemporaryCourseFee() != null) {
|
|
|
+ List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
|
|
|
+ for (StudentPaymentOrderDetail orderDetail : orderDetails) {
|
|
|
+ if (orderDetail == null || orderDetail.getPrice() == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup = new MusicGroupSubjectGoodsGroup();
|
|
|
+ GoodsType goodsType = orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) ? GoodsType.INSTRUMENT : GoodsType.ACCESSORIES;
|
|
|
+ musicGroupSubjectGoodsGroup.setType(goodsType);
|
|
|
+ musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
|
|
|
+ musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
|
|
|
+
|
|
|
+ goodsGroups.add(musicGroupSubjectGoodsGroup);
|
|
|
+
|
|
|
+ orderAmount = orderAmount.add(orderDetail.getPrice());
|
|
|
+ }
|
|
|
+ } else if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
|
|
|
+ goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
|
|
|
+ for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
|
|
|
+ if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
|
|
|
+ orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ orderAmount = orderAmount.add(goodsGroup.getPrice());
|
|
|
+ //团购乐器减免课程费用
|
|
|
+ if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
|
|
|
+ orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独辅件
|
|
|
+ List<Goods> goodsList = null;
|
|
|
+ if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
|
|
|
+ goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独教谱
|
|
|
+ List<Goods> otherGoodsList = null;
|
|
|
+ if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
|
|
|
+ otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
|
|
|
+ for (Goods goods : otherGoodsList) {
|
|
|
+ orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amount.compareTo(orderAmount) != 0) {
|
|
|
+ throw new BizException("商品价格不符");
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+
|
|
|
+ String channelType = "";
|
|
|
+
|
|
|
+ StudentPaymentOrder studentPaymentOrder = studentRegistrationService.addOrder(studentRegistration, amount, orderNo, channelType, courseFee, goodsGroups, goodsList, otherGoodsList);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ if(registerPayDto.getIsUseBalancePayment() || amount.doubleValue() == 0){
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
|
|
|
+ if(userCashAccount == null){
|
|
|
+ throw new BizException("用户账户找不到");
|
|
|
+ }
|
|
|
+ if(userCashAccount.getBalance().subtract(amount).doubleValue() > 0){
|
|
|
+ // 更新订单信息
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(amount);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+
|
|
|
+ sysUserCashAccountService.updateBalance(userId, amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"乐团续费");
|
|
|
+
|
|
|
+ //更新下次续费时间
|
|
|
+ /*musicGroupStudentFee.setUpdateTime(date);
|
|
|
+ musicGroupStudentFee.setLatestPaidTime(date);
|
|
|
+ musicGroupStudentFee.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
|
|
|
+ musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
|
|
|
+ musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId));
|
|
|
+ musicGroupStudentFeeDao.update(musicGroupStudentFee);*/
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }else{
|
|
|
+ if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团续费");
|
|
|
+ amount = amount.subtract(userCashAccount.getBalance());
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
|
+ } else {
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map payMap = payService.getPayMap(
|
|
|
+ orderAmount,
|
|
|
+ orderNo,
|
|
|
+ "http://mstudev.dayaedu.com/api-student/studentOrder/notify",
|
|
|
+ "http://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
|
|
|
+ "测试订单",
|
|
|
+ "测试订单");
|
|
|
+
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+
|
|
|
+ return payMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map rePay(RegisterPayDto registerPayDto) throws Exception {
|
|
|
+ StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
|
|
|
+ if (studentRegistration == null) {
|
|
|
+ throw new BizException("报名信息有误,请核查");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer userId = studentRegistration.getUserId();
|
|
|
+
|
|
|
+ StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.ING);
|
|
|
+ if (ApplyOrder == null) {
|
|
|
+ throw new BizException("没有支付中的订单,请勿非法请求");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
|
|
|
+ BigDecimal orderAmount = new BigDecimal("0");
|
|
|
+
|
|
|
+ //获取课程价格
|
|
|
+ MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
|
|
|
+ BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
|
|
|
+ if (studentRegistration.getTemporaryCourseFee() != null) {
|
|
|
+ courseFee = studentRegistration.getTemporaryCourseFee();
|
|
|
+ }
|
|
|
+ orderAmount = orderAmount.add(courseFee);
|
|
|
+
|
|
|
+
|
|
|
+ //乐器及打包辅件
|
|
|
+ List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
|
|
|
+ if (studentRegistration.getTemporaryCourseFee() != null) {
|
|
|
+ List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
|
|
|
+ for (StudentPaymentOrderDetail orderDetail : orderDetails) {
|
|
|
+ if (orderDetail == null || orderDetail.getPrice() == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup = new MusicGroupSubjectGoodsGroup();
|
|
|
+ GoodsType goodsType = orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) ? GoodsType.INSTRUMENT : GoodsType.ACCESSORIES;
|
|
|
+ musicGroupSubjectGoodsGroup.setType(goodsType);
|
|
|
+ musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
|
|
|
+ musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
|
|
|
+ goodsGroups.add(musicGroupSubjectGoodsGroup);
|
|
|
+ orderAmount = orderAmount.add(orderDetail.getPrice());
|
|
|
+ }
|
|
|
+ } else if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
|
|
|
+ goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
|
|
|
+ for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
|
|
|
+ if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
|
|
|
+ orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ orderAmount = orderAmount.add(goodsGroup.getPrice());
|
|
|
+ //团购乐器减免课程费用
|
|
|
+ if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
|
|
|
+ orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独辅件
|
|
|
+ List<Goods> goodsList = null;
|
|
|
+ if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
|
|
|
+ goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独教谱
|
|
|
+ List<Goods> otherGoodsList = null;
|
|
|
+ if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
|
|
|
+ otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
|
|
|
+ for (Goods goods : otherGoodsList) {
|
|
|
+ orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amount.compareTo(orderAmount) != 0) {
|
|
|
+ throw new BizException("商品价格不符");
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+
|
|
|
+ String channelType = "";
|
|
|
+
|
|
|
+ StudentPaymentOrder studentPaymentOrder = studentRegistrationService.reAddOrder(userId, amount, orderNo, channelType, courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId(), ApplyOrder);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ if(registerPayDto.getIsUseBalancePayment() || amount.doubleValue() == 0){
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
|
|
|
+ if(userCashAccount == null){
|
|
|
+ throw new BizException("用户账户找不到");
|
|
|
+ }
|
|
|
+ if(userCashAccount.getBalance().subtract(amount).doubleValue() > 0){
|
|
|
+ // 更新订单信息
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(amount);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+
|
|
|
+ sysUserCashAccountService.updateBalance(userId, amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"乐团续费");
|
|
|
+
|
|
|
+ //更新下次续费时间
|
|
|
+ /*musicGroupStudentFee.setUpdateTime(date);
|
|
|
+ musicGroupStudentFee.setLatestPaidTime(date);
|
|
|
+ musicGroupStudentFee.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
|
|
|
+ musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
|
|
|
+ musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId));
|
|
|
+ musicGroupStudentFeeDao.update(musicGroupStudentFee);*/
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }else{
|
|
|
+ if (userCashAccount.getBalance().doubleValue() > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团续费");
|
|
|
+ amount = amount.subtract(userCashAccount.getBalance());
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
|
|
|
+ } else {
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map payMap = payService.getPayMap(
|
|
|
+ orderAmount,
|
|
|
+ orderNo,
|
|
|
+ "http://mstudev.dayaedu.com/api-student/studentOrder/notify",
|
|
|
+ "http://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
|
|
|
+ "测试订单",
|
|
|
+ "测试订单");
|
|
|
+
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+
|
|
|
+ return payMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void updateSubjectInfo(SubFeeSettingDto subFeeSettingDto) throws Exception {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
if(sysUser == null){
|
|
@@ -777,7 +1066,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
|
|
|
studentPaymentOrder.setMusicGroupId(musicGroupId);
|
|
|
studentPaymentOrder.setCreateTime(date);
|
|
|
studentPaymentOrder.setUpdateTime(date);
|
|
|
- studentPaymentOrder.setVersion(1);
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
ArrayList<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
@@ -826,7 +1115,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- Map<String, Object> payMap = payService.getPayMap(amount, idGeneratorService.generatorId("payment") + "", "https://pay.dayaedu.com/api/yqpay/notify",
|
|
|
+ Map<String, Object> payMap = payService.getPayMap(amount, studentPaymentOrder.getOrderNo(), "https://pay.dayaedu.com/api/yqpay/notify",
|
|
|
"http://dev.dayaedu.com", "续费", "乐团续费");
|
|
|
studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
studentPaymentOrder.setUpdateTime(date);
|