|
@@ -24,6 +24,7 @@ import com.szwl.service.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -31,6 +32,8 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.OffsetDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
@@ -144,9 +147,8 @@ public class AirwallexPayController {
|
|
|
// 如果是海外客户,使用的是 Airwallex ,就要判断他有没有设置分销
|
|
|
// 在 Airwallex 支付之前,要先判断
|
|
|
|
|
|
+ String createDate = paymentIntentRequestBody.getCreateDate();
|
|
|
BigDecimal amount = paymentIntentRequestBody.getAmount();
|
|
|
- Date createDate = paymentIntentRequestBody.getCreateDate();
|
|
|
- Date modifyDate = paymentIntentRequestBody.getModifyDate();
|
|
|
String currency = paymentIntentRequestBody.getCurrency();
|
|
|
String merchantOrderId = paymentIntentRequestBody.getMerchantOrderId();
|
|
|
// String requestId = paymentIntentRequestBody.getRequestId();
|
|
@@ -191,8 +193,23 @@ public class AirwallexPayController {
|
|
|
// 创建订单
|
|
|
TCoinOrder tCoinOrder = new TCoinOrder();
|
|
|
tCoinOrder.setAdminId(adminById.getId());
|
|
|
- tCoinOrder.setCreateDate(createDate);
|
|
|
- tCoinOrder.setModifyDate(modifyDate);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(createDate)) {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date parse = null;
|
|
|
+ try {
|
|
|
+ parse = simpleDateFormat.parse(createDate);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ tCoinOrder.setCreateDate(parse);
|
|
|
+ tCoinOrder.setModifyDate(parse);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tCoinOrder.setCreateDate(new Date());
|
|
|
+ tCoinOrder.setModifyDate(new Date());
|
|
|
+ }
|
|
|
+ tCoinOrder.setPayDate(new Date());
|
|
|
tCoinOrder.setSn(sn);
|
|
|
tCoinOrder.setAmount(amount);
|
|
|
tCoinOrder.setCurrency(currency);
|
|
@@ -243,8 +260,18 @@ public class AirwallexPayController {
|
|
|
tOrderDetails.setId(merchantOrderId);
|
|
|
tOrderDetails.setAdminId(adminById.getId());
|
|
|
tOrderDetails.setEquipmentId(equipmentId);
|
|
|
- tOrderDetails.setCreateDate(createDate);
|
|
|
- tOrderDetails.setModifyDate(modifyDate);
|
|
|
+ if (StringUtils.isNotEmpty(createDate)) {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date parse = null;
|
|
|
+ try {
|
|
|
+ parse = simpleDateFormat.parse(createDate);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ tOrderDetails.setCreateDate(parse);
|
|
|
+ } else {
|
|
|
+ tOrderDetails.setCreateDate(new Date());
|
|
|
+ }
|
|
|
tOrderDetails.setOrderSn(sn);
|
|
|
tOrderDetails.setPrice(amount);
|
|
|
tOrderDetails.setProductName(productName);
|
|
@@ -403,6 +430,7 @@ public class AirwallexPayController {
|
|
|
coinOrder.setRefundDate(refundDate);
|
|
|
tCoinOrderService.updateById(coinOrder);
|
|
|
|
|
|
+ // TODO: 退款要扣除用户钱包中的金额,如果金额为0或者不足,改为负数?或者提示余额不足,联系商家手动退款
|
|
|
|
|
|
// 发起退款
|
|
|
// String refund = airwallexService.createARefund(requestId, paymentIntentId, reason);
|
|
@@ -527,7 +555,7 @@ public class AirwallexPayController {
|
|
|
tAirwallexPayment.setAdminId(adminId);
|
|
|
tAirwallexPaymentService.save(tAirwallexPayment);
|
|
|
|
|
|
- // TODO: 从当前余额中扣除提现金额,考虑货币,改成每次将余额全部提现
|
|
|
+ // TODO: 默认每次将余额全部提现,考虑货币
|
|
|
// tAirwallexWalletService.list()
|
|
|
// LambdaQueryWrapper<TAirwallexWallet> wrapper = Wrappers.lambdaQuery();
|
|
|
// wrapper.eq(TAirwallexWallet::getAdminId, adminId);
|
|
@@ -765,4 +793,18 @@ public class AirwallexPayController {
|
|
|
return distributionDetails;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 查询实时汇率
|
|
|
+ // Retrieve an indicative MarketFX quote
|
|
|
+ @ApiOperation(value = "查询实时汇率")
|
|
|
+ @GetMapping("/getMarketFX")
|
|
|
+ public Map<String, Object> getMarketFX(@RequestParam Map<String, String> params) {
|
|
|
+ String buyCurrency = params.get("buy_currency");
|
|
|
+ String sellCurrency = params.get("sell_currency");
|
|
|
+ BigDecimal buyAmount = new BigDecimal(params.get("buy_amount"));
|
|
|
+
|
|
|
+ Map<String, Object> marketFX = airwallexService.getMarketFX(buyCurrency, sellCurrency, buyAmount);
|
|
|
+
|
|
|
+ return marketFX;
|
|
|
+ }
|
|
|
}
|