|
|
@@ -7,10 +7,13 @@ import com.alipay.api.domain.AlipayTradeAppPayModel;
|
|
|
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
|
|
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
|
|
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
|
|
+import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.EcommerceService;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.izouma.zhumj.config.Constants;
|
|
|
import com.izouma.zhumj.domain.*;
|
|
|
@@ -58,6 +61,7 @@ public class ClientRoomInfoService {
|
|
|
private final FeeTypeRepo feeTypeRepo;
|
|
|
private final UserMoneyRecordRepo userMoneyRecordRepo;
|
|
|
private final MemberRepo memberRepo;
|
|
|
+// private final EcommerceService ecommerceService;
|
|
|
// private final AlipayClient alipayClient;
|
|
|
|
|
|
public ClientRoomInfoService(UserRepo userRepo, CheckinInfoRepo checkinInfoRepo, WxPayService wxPayService,
|
|
|
@@ -75,6 +79,7 @@ public class ClientRoomInfoService {
|
|
|
this.userMoneyRecordRepo = userMoneyRecordRepo;
|
|
|
this.memberRepo = memberRepo;
|
|
|
// this.alipayClient = alipayClient;
|
|
|
+// this.ecommerceService = ecommerceService;
|
|
|
}
|
|
|
|
|
|
public ClientRoomInfoDTO getClientRoomInfoDTO(Long userId) {
|
|
|
@@ -335,4 +340,131 @@ public class ClientRoomInfoService {
|
|
|
return new PageImpl<>(new ArrayList<>(), pageable, 0);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public Object subRecharge(Long userId, BigDecimal amount, RechargeType type, PayMethod payMethod) throws WxPayException, AlipayApiException {
|
|
|
+ if (amount.compareTo(BigDecimal.valueOf(0.01)) < 0) {
|
|
|
+ throw new BusinessException("最少充值0.01元");
|
|
|
+ }
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("无记录"));
|
|
|
+ CheckinInfo checkinInfo = checkinInfoRepo.findFirstByIdNoOrderByCheckinTimeDescCreatedAtDesc(user.getIdNo())
|
|
|
+ .orElseThrow(new BusinessException("无记录"));
|
|
|
+ String storeName = Optional.ofNullable(checkinInfo.getStoreInfo())
|
|
|
+ .map(StoreInfo::getStoreName)
|
|
|
+ .orElse(null);
|
|
|
+ String bedName = Optional.ofNullable(checkinInfo.getBedInfo())
|
|
|
+ .map(BedInfo::getBedName)
|
|
|
+ .orElse(null);
|
|
|
+ String body = "";
|
|
|
+ switch (type) {
|
|
|
+ case ROOM:
|
|
|
+ body = "房间余额充值";
|
|
|
+ break;
|
|
|
+ case PERSON:
|
|
|
+ body = "账户余额充值";
|
|
|
+ break;
|
|
|
+ case AMMETER:
|
|
|
+ body = "电表充值";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ body = "充值";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(storeName)) {
|
|
|
+ body += "," + storeName;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(bedName)) {
|
|
|
+ body += "," + bedName;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ switch (payMethod) {
|
|
|
+ case WEIXIN:
|
|
|
+ WxPayUnifiedOrderRequest request;
|
|
|
+ PartnerTransactionsRequest partnerTransactionsRequest;
|
|
|
+ partnerTransactionsRequest = new PartnerTransactionsRequest();
|
|
|
+ partnerTransactionsRequest.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
|
|
|
+ partnerTransactionsRequest.setNotifyUrl(wxNotifyUrl);
|
|
|
+
|
|
|
+ PartnerTransactionsRequest.Payer payer = new PartnerTransactionsRequest.Payer();
|
|
|
+ payer.setSpOpenid(user.getOpenId());
|
|
|
+ payer.setSpOpenid(user.getOpenId());
|
|
|
+ partnerTransactionsRequest.setPayer(payer);
|
|
|
+
|
|
|
+ PartnerTransactionsRequest.SettleInfo settleInfo = new PartnerTransactionsRequest.SettleInfo();
|
|
|
+ partnerTransactionsRequest.setSettleInfo(settleInfo);
|
|
|
+ partnerTransactionsRequest.setDescription(body);
|
|
|
+
|
|
|
+ partnerTransactionsRequest.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
|
|
|
+ partnerTransactionsRequest.setAttach(new JsonUtils.Builder()
|
|
|
+ .add(Constants.ATTACH_TYPE, "recharge")
|
|
|
+ .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
|
|
|
+ .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
|
|
|
+ .add(Constants.ATTACH_USER_ID, userId)
|
|
|
+ .add(Constants.ATTACH_AMOUNT, amount)
|
|
|
+ .add(Constants.ATTACH_REMARK, "")
|
|
|
+ .build());
|
|
|
+
|
|
|
+
|
|
|
+ PartnerTransactionsRequest.Amount requestAmount = new PartnerTransactionsRequest.Amount();
|
|
|
+ requestAmount.setTotal(amount.multiply(BigDecimal.valueOf(100)).intValue());
|
|
|
+ requestAmount.setCurrency("CNY");
|
|
|
+ partnerTransactionsRequest.setAmount(requestAmount);
|
|
|
+ request = new WxPayUnifiedOrderRequest();
|
|
|
+ request.setSpbillCreateIp("180.102.110.170");
|
|
|
+ request.setNotifyUrl(wxNotifyUrl);
|
|
|
+ request.setTradeType(WxPayConstants.TradeType.JSAPI);
|
|
|
+ request.setOpenid(user.getOpenId());
|
|
|
+ request.setSignType("MD5");
|
|
|
+ request.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
|
|
|
+ request.setTotalFee(amount.multiply(BigDecimal.valueOf(100)).intValue());
|
|
|
+ request.setAttach(new JsonUtils.Builder()
|
|
|
+ .add(Constants.ATTACH_TYPE, "recharge")
|
|
|
+ .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
|
|
|
+ .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
|
|
|
+ .add(Constants.ATTACH_USER_ID, userId)
|
|
|
+ .add(Constants.ATTACH_AMOUNT, amount)
|
|
|
+ .add(Constants.ATTACH_REMARK, "")
|
|
|
+ .build());
|
|
|
+
|
|
|
+ request.setBody(body);
|
|
|
+
|
|
|
+ // 测试环境设为1分
|
|
|
+ if (Arrays.stream(environment.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
|
|
|
+ // request.setTotalFee(1);
|
|
|
+ }
|
|
|
+ return wxPayService.getEcommerceService()
|
|
|
+ .partnerTransactions(TradeTypeEnum.JSAPI, partnerTransactionsRequest);
|
|
|
+// case ALIPAY:
|
|
|
+// AlipayTradeAppPayRequest alipayRequest = new AlipayTradeAppPayRequest();
|
|
|
+// AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
|
|
+// model.setOutTradeNo(UUID.randomUUID().toString());
|
|
|
+// model.setSubject(body);
|
|
|
+// model.setTotalAmount(amount.toString());
|
|
|
+// model.setDisablePayChannels("pcredit,creditCard");
|
|
|
+// model.setProductCode("QUICK_MSECURITY_PAY");
|
|
|
+// model.setBody(new JsonUtils.Builder()
|
|
|
+// .add(Constants.ATTACH_TYPE, "recharge")
|
|
|
+// .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
|
|
|
+// .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
|
|
|
+// .add(Constants.ATTACH_USER_ID, userId)
|
|
|
+// .add(Constants.ATTACH_AMOUNT, amount)
|
|
|
+// .add(Constants.ATTACH_REMARK, "")
|
|
|
+// .build());
|
|
|
+// if (Arrays.stream(environment.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
|
|
|
+// // 测试环境设为1分
|
|
|
+//// model.setTotalAmount("0.01");
|
|
|
+// }
|
|
|
+//
|
|
|
+// alipayRequest.setNotifyUrl(aliNotifyUrl);
|
|
|
+// alipayRequest.setBizModel(model);
|
|
|
+//
|
|
|
+// AlipayTradeAppPayResponse response = alipayClient.sdkExecute(alipayRequest);
|
|
|
+// if (response.isSuccess()) {
|
|
|
+// return response.getBody();
|
|
|
+// } else {
|
|
|
+// throw new BusinessException("支付宝下单失败");
|
|
|
+// }
|
|
|
+ default:
|
|
|
+ throw new BusinessException("不支持此支付方式");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|