|
|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.zhumj.service;
|
|
|
|
|
|
+import com.alipay.api.AlipayClient;
|
|
|
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
|
|
|
import com.github.binarywang.wxpay.bean.entpay.EntPayResult;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
@@ -9,6 +10,7 @@ import com.izouma.zhumj.domain.MemberInfo;
|
|
|
import com.izouma.zhumj.domain.User;
|
|
|
import com.izouma.zhumj.domain.UserMoneyWithdrawApply;
|
|
|
import com.izouma.zhumj.enums.WithdrawApplyStatus;
|
|
|
+import com.izouma.zhumj.enums.WithdrawMethod;
|
|
|
import com.izouma.zhumj.exception.BusinessException;
|
|
|
import com.izouma.zhumj.repo.CheckinInfoRepo;
|
|
|
import com.izouma.zhumj.repo.MemberRepo;
|
|
|
@@ -36,8 +38,9 @@ public class UserMoneyWithdrawApplyService {
|
|
|
private WxPayService wxPayService;
|
|
|
private CheckinInfoRepo checkinInfoRepo;
|
|
|
private MemberRepo memberRepo;
|
|
|
+ private AlipayClient alipayClient;
|
|
|
|
|
|
- public UserMoneyWithdrawApply apply(Long userId) {
|
|
|
+ public UserMoneyWithdrawApply apply(Long userId, WithdrawMethod method) {
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
MemberInfo memberInfo = memberRepo.findById(user.getIdNo()).orElseThrow(new BusinessException("无住客信息"));
|
|
|
if (Optional.ofNullable(memberInfo.getMoney()).orElse(BigDecimal.ZERO).compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
@@ -47,6 +50,7 @@ public class UserMoneyWithdrawApplyService {
|
|
|
.userId(userId)
|
|
|
.amount(memberInfo.getMoney())
|
|
|
.status(WithdrawApplyStatus.APPLY)
|
|
|
+ .method(method)
|
|
|
.build();
|
|
|
if (StringUtils.isNotBlank(user.getIdNo())) {
|
|
|
checkinInfoRepo.findFirstByIdNoOrderByCheckinTimeDescCreatedAtDesc(user.getIdNo())
|
|
|
@@ -72,28 +76,40 @@ public class UserMoneyWithdrawApplyService {
|
|
|
userMoneyWithdrawApplyRepo.saveAndFlush(apply);
|
|
|
}
|
|
|
CheckinInfo checkinInfo = checkinInfoRepo.findFirstByIdNo(user.getIdNo());
|
|
|
- try {
|
|
|
- EntPayRequest request = new EntPayRequest();
|
|
|
- request.setPartnerTradeNo(apply.getTradeNo());
|
|
|
- request.setAmount(apply.getAmount().multiply(BigDecimal.valueOf(100)).intValue());
|
|
|
- request.setOpenid(user.getOpenId());
|
|
|
- request.setCheckName("NO_CHECK");
|
|
|
- request.setDescription(checkinInfo.getStoreInfo().getStoreName()+","+
|
|
|
- checkinInfo.getRoomInfo().getRoomName()+","
|
|
|
- +checkinInfo.getRoomInfo().getRoomName()
|
|
|
- +"余额提现");
|
|
|
- request.setSpbillCreateIp("192.168.31.12");
|
|
|
- EntPayResult result = wxPayService.getEntPayService().entPay(request);
|
|
|
- result.checkResult(wxPayService, "MD5", true);
|
|
|
- } catch (WxPayException e) {
|
|
|
- log.error("余额提现失败", e);
|
|
|
- throw new BusinessException(e.getMessage());
|
|
|
+ String body = checkinInfo.getStoreInfo().getStoreName() + "," +
|
|
|
+ checkinInfo.getRoomInfo().getRoomName() + ","
|
|
|
+ + checkinInfo.getBedInfo().getBedName()
|
|
|
+ + "余额提现";
|
|
|
+
|
|
|
+ switch (apply.getMethod()) {
|
|
|
+ case WECHAT:
|
|
|
+ try {
|
|
|
+ EntPayRequest request = new EntPayRequest();
|
|
|
+ request.setPartnerTradeNo(apply.getTradeNo());
|
|
|
+ request.setAmount(apply.getAmount().multiply(BigDecimal.valueOf(100)).intValue());
|
|
|
+ request.setOpenid(user.getOpenId());
|
|
|
+ request.setCheckName("NO_CHECK");
|
|
|
+ request.setDescription(body);
|
|
|
+ request.setSpbillCreateIp("192.168.31.12");
|
|
|
+ EntPayResult result = wxPayService.getEntPayService().entPay(request);
|
|
|
+ result.checkResult(wxPayService, "MD5", true);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ log.error("余额提现失败", e);
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ALIPAY:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BusinessException("不支持此提现方式");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
apply.setStatus(WithdrawApplyStatus.SUCCESS);
|
|
|
apply.setTransferTime(LocalDateTime.now());
|
|
|
|
|
|
- memberInfo.setMoney(Optional.ofNullable(memberInfo.getMoney()).orElse(BigDecimal.ZERO).subtract(apply.getAmount()));
|
|
|
+ memberInfo.setMoney(Optional.ofNullable(memberInfo.getMoney()).orElse(BigDecimal.ZERO)
|
|
|
+ .subtract(apply.getAmount()));
|
|
|
memberRepo.save(memberInfo);
|
|
|
|
|
|
userMoneyRecordService.saveWithdrawRecord(user.getId(), user.getIdNo(), apply.getAmount(), apply.getId());
|
|
|
@@ -106,11 +122,11 @@ public class UserMoneyWithdrawApplyService {
|
|
|
userMoneyWithdrawApplyRepo.save(apply);
|
|
|
}
|
|
|
|
|
|
- public void applyAndPass(Long userId) {
|
|
|
+ public void applyAndPass(Long userId, WithdrawMethod method) {
|
|
|
if (SecurityUtils.getAuthenticatedUser().isTemporal()) {
|
|
|
throw new BusinessException("扫码进入无法提现");
|
|
|
}
|
|
|
- UserMoneyWithdrawApply apply = apply(userId);
|
|
|
+ UserMoneyWithdrawApply apply = apply(userId, method);
|
|
|
try {
|
|
|
pass(apply.getId());
|
|
|
} catch (BusinessException e) {
|