|
@@ -44,16 +44,6 @@ public class AirwallexPayController {
|
|
|
// @Value("${test.value:bbb}")
|
|
|
// private String testValue;
|
|
|
|
|
|
- public AirwallexPayController(TAdminService tAdminService, AirwallexService airwallexService, TCoinOrderService tCoinOrderService, TOrderDetailsService tOrderDetailsService, TAirwallexPaymentService tAirwallexPaymentService, SzwlFeign szwlFeign, TAirwallexMchService airwallexMchService) {
|
|
|
- this.tAdminService = tAdminService;
|
|
|
- this.airwallexService = airwallexService;
|
|
|
- this.tCoinOrderService = tCoinOrderService;
|
|
|
- this.tOrderDetailsService = tOrderDetailsService;
|
|
|
- this.tAirwallexPaymentService = tAirwallexPaymentService;
|
|
|
- this.szwlFeign = szwlFeign;
|
|
|
- this.airwallexMchService = airwallexMchService;
|
|
|
- }
|
|
|
-
|
|
|
TAdminService tAdminService;
|
|
|
|
|
|
AirwallexService airwallexService;
|
|
@@ -68,7 +58,18 @@ public class AirwallexPayController {
|
|
|
|
|
|
TAirwallexMchService airwallexMchService;
|
|
|
|
|
|
+ TAirwallexWalletService airwallexWalletService;
|
|
|
|
|
|
+ public AirwallexPayController(TAdminService tAdminService, AirwallexService airwallexService, TCoinOrderService tCoinOrderService, TOrderDetailsService tOrderDetailsService, TAirwallexPaymentService tAirwallexPaymentService, SzwlFeign szwlFeign, TAirwallexMchService airwallexMchService, TAirwallexWalletService airwallexWalletService) {
|
|
|
+ this.tAdminService = tAdminService;
|
|
|
+ this.airwallexService = airwallexService;
|
|
|
+ this.tCoinOrderService = tCoinOrderService;
|
|
|
+ this.tOrderDetailsService = tOrderDetailsService;
|
|
|
+ this.tAirwallexPaymentService = tAirwallexPaymentService;
|
|
|
+ this.szwlFeign = szwlFeign;
|
|
|
+ this.airwallexMchService = airwallexMchService;
|
|
|
+ this.airwallexWalletService = airwallexWalletService;
|
|
|
+ }
|
|
|
|
|
|
@ApiOperation(value = "创建收款人")
|
|
|
@PostMapping("/caBeneficiary")
|
|
@@ -144,6 +145,8 @@ public class AirwallexPayController {
|
|
|
// 在 Airwallex 支付之前,要先判断
|
|
|
|
|
|
BigDecimal amount = paymentIntentRequestBody.getAmount();
|
|
|
+ Date createDate = paymentIntentRequestBody.getCreateDate();
|
|
|
+ Date modifyDate = paymentIntentRequestBody.getModifyDate();
|
|
|
String currency = paymentIntentRequestBody.getCurrency();
|
|
|
String merchantOrderId = paymentIntentRequestBody.getMerchantOrderId();
|
|
|
// String requestId = paymentIntentRequestBody.getRequestId();
|
|
@@ -188,7 +191,8 @@ public class AirwallexPayController {
|
|
|
// 创建订单
|
|
|
TCoinOrder tCoinOrder = new TCoinOrder();
|
|
|
tCoinOrder.setAdminId(adminById.getId());
|
|
|
- tCoinOrder.setCreateDate(new Date());
|
|
|
+ tCoinOrder.setCreateDate(createDate);
|
|
|
+ tCoinOrder.setModifyDate(modifyDate);
|
|
|
tCoinOrder.setSn(sn);
|
|
|
tCoinOrder.setAmount(amount);
|
|
|
tCoinOrder.setCurrency(currency);
|
|
@@ -234,14 +238,13 @@ public class AirwallexPayController {
|
|
|
}
|
|
|
tCoinOrder.setAltInfo(airDistributionDetails.toString());
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 订单明细表
|
|
|
TOrderDetails tOrderDetails = new TOrderDetails();
|
|
|
tOrderDetails.setId(merchantOrderId);
|
|
|
tOrderDetails.setAdminId(adminById.getId());
|
|
|
tOrderDetails.setEquipmentId(equipmentId);
|
|
|
- tOrderDetails.setCreateDate(new Date());
|
|
|
+ tOrderDetails.setCreateDate(createDate);
|
|
|
+ tOrderDetails.setModifyDate(modifyDate);
|
|
|
tOrderDetails.setOrderSn(sn);
|
|
|
tOrderDetails.setPrice(amount);
|
|
|
tOrderDetails.setProductName(productName);
|
|
@@ -322,7 +325,7 @@ public class AirwallexPayController {
|
|
|
// JSONObject customerObj = JSON.parseObject(customer);
|
|
|
// String address = customerObj.getString("address");
|
|
|
|
|
|
- // TODO: 要改
|
|
|
+ // TODO: 要改???
|
|
|
String type = jsonObject.getJSONObject("latest_payment_attempt").getJSONObject("payment_method").getString("type");
|
|
|
// JSONObject jsonObject4 = Optional.ofNullable(jsonObject)
|
|
|
// .flatMap(jsonObject3 -> Optional.ofNullable(jsonObject3.getJSONObject("customer")))
|
|
@@ -371,6 +374,7 @@ public class AirwallexPayController {
|
|
|
|
|
|
// String requestId = refundRequestBody.getRequestId();
|
|
|
String paymentIntentId = refundRequestBody.getPaymentIntentId();
|
|
|
+ Date refundDate = refundRequestBody.getRefundDate();
|
|
|
// String reason = refundRequestBody.getReason();
|
|
|
|
|
|
// QueryWrapper<TOrderAbroad> tOrderAbroadQueryWrapper = new QueryWrapper<>();
|
|
@@ -396,7 +400,7 @@ public class AirwallexPayController {
|
|
|
// DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
// String format = localDateTime.format(dtf);
|
|
|
// 退款发起时间
|
|
|
- coinOrder.setRefundDate(new Date());
|
|
|
+ coinOrder.setRefundDate(refundDate);
|
|
|
tCoinOrderService.updateById(coinOrder);
|
|
|
|
|
|
|
|
@@ -485,7 +489,7 @@ public class AirwallexPayController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "新建一笔付款")
|
|
|
+ @ApiOperation(value = "新建一笔付款,用于提现")
|
|
|
@PostMapping("/caPayment")
|
|
|
public R caPayment(@RequestBody CaPaymentRequestDTO caPaymentRequestDTO) {
|
|
|
|
|
@@ -509,7 +513,7 @@ public class AirwallexPayController {
|
|
|
String beneficiaryId = jsonNode.get("beneficiary_id").asText();
|
|
|
String createdAtStr = jsonNode.get("created_at").asText();
|
|
|
|
|
|
- // TODO: 保存支付提现明细
|
|
|
+ // 保存支付提现明细
|
|
|
TAirwallexPayment tAirwallexPayment = new TAirwallexPayment();
|
|
|
tAirwallexPayment.setPaymentId(paymentId);
|
|
|
tAirwallexPayment.setPaymentCurrency(paymentCurrency);
|
|
@@ -523,8 +527,7 @@ public class AirwallexPayController {
|
|
|
tAirwallexPayment.setAdminId(adminId);
|
|
|
tAirwallexPaymentService.save(tAirwallexPayment);
|
|
|
|
|
|
- // TODO: 从当前余额中扣除提现金额,考虑货币
|
|
|
- // TODO: 改成每次将余额全部提现
|
|
|
+ // TODO: 从当前余额中扣除提现金额,考虑货币,改成每次将余额全部提现
|
|
|
// tAirwallexWalletService.list()
|
|
|
// LambdaQueryWrapper<TAirwallexWallet> wrapper = Wrappers.lambdaQuery();
|
|
|
// wrapper.eq(TAirwallexWallet::getAdminId, adminId);
|
|
@@ -590,9 +593,9 @@ public class AirwallexPayController {
|
|
|
agencyAmount = null, // 一级分销商所得的钱
|
|
|
merchantAmount = null; // 二级分销商所得的钱
|
|
|
|
|
|
- TAirwallexMch selfAirMch = null, // 商家收款信息
|
|
|
- agencyAirMch = null, // 一级分销商收款信息
|
|
|
- merchantAirMch = null; // 二级分销商收款信息
|
|
|
+ TAirwallexWallet selfAirWallet = null, // 商家收款信息
|
|
|
+ agencyAirWallet = null, // 一级分销商收款信息
|
|
|
+ merchantAirWallet = null; // 二级分销商收款信息
|
|
|
|
|
|
ObjectNode airJson = null, // 空中云汇
|
|
|
selfJson = null, // 商家
|
|
@@ -618,9 +621,14 @@ public class AirwallexPayController {
|
|
|
|
|
|
// Airwallex 平台收款信息表
|
|
|
// Long adminId = proportion.getAdminId();
|
|
|
- LambdaQueryWrapper<TAirwallexMch> wrapper = Wrappers.lambdaQuery();
|
|
|
- wrapper.eq(TAirwallexMch::getAdminId, proportion.getAdminId());
|
|
|
- selfAirMch = airwallexMchService.getOne(wrapper);
|
|
|
+// LambdaQueryWrapper<TAirwallexMch> wrapper = Wrappers.lambdaQuery();
|
|
|
+// wrapper.eq(TAirwallexMch::getAdminId, proportion.getAdminId());
|
|
|
+// selfAirMch = airwallexMchService.getOne(wrapper);
|
|
|
+
|
|
|
+ // Airwallex 钱包信息
|
|
|
+ LambdaQueryWrapper<TAirwallexWallet> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TAirwallexWallet::getAdminId, proportion.getAdminId());
|
|
|
+ selfAirWallet = airwallexWalletService.getOne(query);
|
|
|
|
|
|
// 平台分销
|
|
|
// airJson = JsonNodeFactory.instance.objectNode();
|
|
@@ -632,7 +640,7 @@ public class AirwallexPayController {
|
|
|
|
|
|
// 商家分销
|
|
|
selfJson = JsonNodeFactory.instance.objectNode();
|
|
|
- selfJson.put("airBeneId", selfAirMch.getBeneficiaryId());
|
|
|
+ selfJson.put("airBeneId", selfAirWallet.getAdminId()); // 受益人Bene编号,使用adminId
|
|
|
selfJson.put("airAmount", selfAmount.toString());
|
|
|
altInfos.add(selfJson);
|
|
|
break;
|
|
@@ -645,19 +653,20 @@ public class AirwallexPayController {
|
|
|
selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
|
|
// Airwallex 平台收款信息表
|
|
|
- agencyAirMch = airwallexMchService.getAirMch(proportion.getAgencyId());
|
|
|
- selfAirMch = airwallexMchService.getAirMch(proportion.getAdminId());
|
|
|
+ agencyAirWallet = airwallexWalletService.getAirWallet(proportion.getAgencyId());
|
|
|
+ selfAirWallet = airwallexWalletService.getAirWallet(proportion.getAdminId());
|
|
|
+
|
|
|
if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
|
|
|
// 一级代理获得利润
|
|
|
agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
agencyJson = JsonNodeFactory.instance.objectNode();
|
|
|
- agencyJson.put("airBeneId", agencyAirMch.getBeneficiaryId());
|
|
|
+ agencyJson.put("airBeneId", agencyAirWallet.getAdminId());
|
|
|
agencyJson.put("airAmount", agencyAmount.toString());
|
|
|
altInfos.add(agencyJson);
|
|
|
}
|
|
|
// 商家自己获得利润
|
|
|
selfJson = JsonNodeFactory.instance.objectNode();
|
|
|
- selfJson.put("airBeneId", selfAirMch.getBeneficiaryId());
|
|
|
+ selfJson.put("airBeneId", selfAirWallet.getAdminId());
|
|
|
selfJson.put("airAmount", selfAmount.toString());
|
|
|
altInfos.add(selfJson);
|
|
|
break;
|
|
@@ -672,14 +681,28 @@ public class AirwallexPayController {
|
|
|
// 商家分销获得利润,五舍六入
|
|
|
selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
// Airwallex 平台收款信息表
|
|
|
- selfAirMch = airwallexMchService.getAirMch(proportion.getAdminId());
|
|
|
- agencyAirMch = airwallexMchService.getAirMch(proportion.getAgencyId());
|
|
|
- merchantAirMch = airwallexMchService.getAirMch(proportion.getMerchantId());
|
|
|
+ Long adminId = proportion.getAdminId();
|
|
|
+ if (adminId != null) {
|
|
|
+ selfAirWallet = airwallexWalletService.getAirWallet(adminId);
|
|
|
+ System.out.println("selfAirWallet打印出来》》》" + selfAirWallet);
|
|
|
+ }
|
|
|
+ Long agencyId = proportion.getAgencyId();
|
|
|
+ if (agencyId != null) {
|
|
|
+ agencyAirWallet = airwallexWalletService.getAirWallet(agencyId);
|
|
|
+ System.out.println("agencyAirWallet打印出来》》》" + agencyAirWallet);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long merchantId = proportion.getMerchantId();
|
|
|
+ if (merchantId != null ) {
|
|
|
+ merchantAirWallet = airwallexWalletService.getAirWallet(merchantId);
|
|
|
+ System.out.println("merchantAirWallet打印出来》》》" + merchantAirWallet);
|
|
|
+ }
|
|
|
+
|
|
|
if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
|
|
|
// 一级代理获得利润
|
|
|
agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
agencyJson = JsonNodeFactory.instance.objectNode();
|
|
|
- agencyJson.put("airBeneId", agencyAirMch.getBeneficiaryId());
|
|
|
+ agencyJson.put("airBeneId", agencyAirWallet.getAdminId());
|
|
|
agencyJson.put("airAmount", agencyAmount.toString());
|
|
|
altInfos.add(agencyJson);
|
|
|
}
|
|
@@ -687,13 +710,13 @@ public class AirwallexPayController {
|
|
|
// 二级经销商获得利润
|
|
|
merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
merchantJson = JsonNodeFactory.instance.objectNode();
|
|
|
- merchantJson.put("airBeneId", merchantAirMch.getBeneficiaryId());
|
|
|
+ merchantJson.put("airBeneId", merchantAirWallet.getAdminId());
|
|
|
merchantJson.put("airAmount", merchantAmount.toString());
|
|
|
altInfos.add(merchantJson);
|
|
|
}
|
|
|
// 商家自己获得利润
|
|
|
selfJson = JsonNodeFactory.instance.objectNode();
|
|
|
- selfJson.put("airBeneId", selfAirMch.getBeneficiaryId());
|
|
|
+ selfJson.put("airBeneId", selfAirWallet.getAdminId());
|
|
|
selfJson.put("airAmount", selfAmount.toString());
|
|
|
altInfos.add(selfJson);
|
|
|
break;
|