|
|
@@ -1,73 +1,142 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.ym.mec.biz.dal.dao.StudentRechargeDao;
|
|
|
import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SysUserCashAccountDetailDao;
|
|
|
-import com.ym.mec.biz.dal.dto.RechargeDto;
|
|
|
import com.ym.mec.biz.dal.entity.StudentRecharge;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.PlatformCashAccountStatusEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.TransTypeEnum;
|
|
|
+import com.ym.mec.biz.service.PayService;
|
|
|
import com.ym.mec.biz.service.StudentRechargeService;
|
|
|
+import com.ym.mec.biz.service.SysUserCashAccountDetailService;
|
|
|
import com.ym.mec.biz.service.SysUserCashAccountService;
|
|
|
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.union.NotifyMsg;
|
|
|
|
|
|
@Service
|
|
|
-public class StudentRechargeServiceImpl extends BaseServiceImpl<String, StudentRecharge> implements StudentRechargeService {
|
|
|
-
|
|
|
+public class StudentRechargeServiceImpl extends BaseServiceImpl<String, StudentRecharge> implements StudentRechargeService {
|
|
|
+
|
|
|
@Resource
|
|
|
private StudentRechargeDao studentRechargeDao;
|
|
|
- @Autowired
|
|
|
- private StudentRegistrationDao studentRegistrationDao;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private StudentRegistrationDao studentRegistrationDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
|
|
|
|
@Resource
|
|
|
- private SysUserCashAccountDetailDao sysUserCashAccountDetailDao;
|
|
|
+ private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PayService payService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IdGeneratorService idGeneratorService;
|
|
|
+
|
|
|
@Override
|
|
|
public BaseDAO<String, StudentRecharge> getDAO() {
|
|
|
return studentRechargeDao;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean recharge(RechargeDto rechargeDto) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<?, ?> recharge(Integer userId, String bankCardNo, BigDecimal amount) {
|
|
|
|
|
|
- //TODO ���õ�����֧��
|
|
|
- Date now = new Date();
|
|
|
+ Date now = new Date();
|
|
|
|
|
|
- //��ֵ��¼
|
|
|
- StudentRecharge studentRecharge = new StudentRecharge();
|
|
|
- studentRecharge.setAmount(rechargeDto.getRechargeAmount());
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.get(userId);
|
|
|
+ if (userCashAccount == null) {
|
|
|
+ throw new BizException("账户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userCashAccount.getStatus() != PlatformCashAccountStatusEnum.NORMAL) {
|
|
|
+ throw new BizException("账户不可用");
|
|
|
+ }
|
|
|
+
|
|
|
+ StudentRecharge studentRecharge = new StudentRecharge();
|
|
|
+ studentRecharge.setAmount(amount);
|
|
|
studentRecharge.setCreateTime(now);
|
|
|
- studentRecharge.setUserId(rechargeDto.getUserId().longValue());
|
|
|
+ studentRecharge.setUserId(userId);
|
|
|
+ studentRecharge.setStatus(DealStatusEnum.ING);
|
|
|
studentRecharge.setTransNo(null);
|
|
|
+ studentRecharge.setOrderNo(idGeneratorService.generatorId("recharge") + "");
|
|
|
studentRechargeDao.insert(studentRecharge);
|
|
|
- //�˻��ʽ���ˮ
|
|
|
- SysUserCashAccountDetail cashAccount = new SysUserCashAccountDetail();
|
|
|
- cashAccount.setAmount(rechargeDto.getRechargeAmount());
|
|
|
- cashAccount.setBalance(null);
|
|
|
- cashAccount.setTransNo(null);
|
|
|
- cashAccount.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
|
|
|
- cashAccount.setUserId(rechargeDto.getUserId());
|
|
|
- cashAccount.setCreateTime(now);
|
|
|
- sysUserCashAccountDetailDao.insert(cashAccount);
|
|
|
-
|
|
|
- //�ۼ��˻�
|
|
|
- sysUserCashAccountService.updateBalance(rechargeDto.getUserId(),rechargeDto.getRechargeAmount());
|
|
|
+
|
|
|
+ try {
|
|
|
+ return payService.getPayMap(amount, studentRecharge.getOrderNo(), "https://pay.dayaedu.com/api/yqpay/notify", "http://dev.dayaedu.com", "测试订单",
|
|
|
+ "测试订单");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("调用支付接口出错", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean rechargeCallback(NotifyMsg notifyMsg) {
|
|
|
+
|
|
|
+ if (notifyMsg.getStatus().equals("TRADE_SUCCESS") || notifyMsg.getStatus().equals("TRADE_CLOSED")) {
|
|
|
+
|
|
|
+ String orderNo = notifyMsg.getMerOrderId();
|
|
|
+
|
|
|
+ StudentRecharge studentRecharge = studentRechargeDao.queryByOrderNo(orderNo);
|
|
|
+
|
|
|
+ if (studentRecharge == null) {
|
|
|
+ throw new BizException("充值记录不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ DealStatusEnum status = notifyMsg.getStatus().equals("TRADE_SUCCESS") ? DealStatusEnum.SUCCESS : DealStatusEnum.FAilED;
|
|
|
+
|
|
|
+ String transNo = notifyMsg.getSeqId();
|
|
|
+
|
|
|
+ String paymentChannel = notifyMsg.getTargetSys();
|
|
|
+
|
|
|
+ Date paymentDate = notifyMsg.getPayTime();
|
|
|
+
|
|
|
+ studentRecharge.setPayPlatform(paymentChannel);
|
|
|
+ studentRecharge.setStatus(status);
|
|
|
+ studentRecharge.setTransNo(transNo);
|
|
|
+ studentRecharge.setModifyTime(paymentDate);
|
|
|
+
|
|
|
+ studentRechargeDao.update(studentRecharge);
|
|
|
+
|
|
|
+ if (status == DealStatusEnum.SUCCESS) {
|
|
|
+
|
|
|
+ TransTypeEnum transType = TransTypeEnum.FAST_PAYMENT;
|
|
|
+
|
|
|
+ if ("WXPay".equals(paymentChannel)) {
|
|
|
+ transType = TransTypeEnum.WECHAT;
|
|
|
+ } else if ("Alipay 2.0".equals(paymentChannel)) {
|
|
|
+ transType = TransTypeEnum.ALIPAY;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新账户余额
|
|
|
+ // 新增交易流水
|
|
|
+ sysUserCashAccountDetailService.addCashAccountDetail(studentRecharge.getUserId(), studentRecharge.getAmount(), orderNo, transNo,
|
|
|
+ PlatformCashAccountDetailTypeEnum.RECHARGE, transType, status, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StudentRecharge selectByTransNo(String transNo) {
|
|
|
- return studentRechargeDao.selectByTransNo(transNo);
|
|
|
+ public StudentRecharge queryByTransNo(String transNo) {
|
|
|
+ return studentRechargeDao.queryByTransNo(transNo);
|
|
|
}
|
|
|
}
|