Browse Source

Merge branch 'test' into dev

Ritchie 1 year ago
parent
commit
84e15e38c5
31 changed files with 1439 additions and 273 deletions
  1. 1 1
      src/main/java/com/szwl/common/myAnnotation/CamelCaseToUnderscoreFormatter.java
  2. 2 0
      src/main/java/com/szwl/constant/AirwallexConstant.java
  3. 24 102
      src/main/java/com/szwl/constant/HuifuConstant.java
  4. 372 26
      src/main/java/com/szwl/controller/AirwallexPayController.java
  5. 7 0
      src/main/java/com/szwl/controller/TAirwallexMchController.java
  6. 214 2
      src/main/java/com/szwl/controller/TCoinOrderController.java
  7. 437 84
      src/main/java/com/szwl/controller/TOrderController.java
  8. 42 2
      src/main/java/com/szwl/controller/WebhookController.java
  9. 32 10
      src/main/java/com/szwl/feign/bean/SzwlFeign.java
  10. 1 1
      src/main/java/com/szwl/mapper/TCoinOrderMapper.java
  11. 1 2
      src/main/java/com/szwl/mapper/xml/TCoinOrderMapper.xml
  12. 2 2
      src/main/java/com/szwl/mapper/xml/TOrderDetailsMapper.xml
  13. 10 1
      src/main/java/com/szwl/model/bean/PaymentIntentRequestBody.java
  14. 3 0
      src/main/java/com/szwl/model/bean/RefundRequestBody.java
  15. 2 2
      src/main/java/com/szwl/model/bo/JsonMessage.java
  16. 2 2
      src/main/java/com/szwl/model/entity/TAirwallexMch.java
  17. 2 5
      src/main/java/com/szwl/model/entity/TCoinOrder.java
  18. 1 1
      src/main/java/com/szwl/model/entity/TOrderDetails.java
  19. 10 1
      src/main/java/com/szwl/service/AirwallexService.java
  20. 7 0
      src/main/java/com/szwl/service/TAirwallexMchService.java
  21. 7 0
      src/main/java/com/szwl/service/TAirwallexWalletService.java
  22. 5 1
      src/main/java/com/szwl/service/TCoinOrderService.java
  23. 9 2
      src/main/java/com/szwl/service/THuifuMchService.java
  24. 58 5
      src/main/java/com/szwl/service/impl/AirwallexServiceImpl.java
  25. 50 1
      src/main/java/com/szwl/service/impl/TAirwallexMchServiceImpl.java
  26. 54 0
      src/main/java/com/szwl/service/impl/TAirwallexWalletServiceImpl.java
  27. 27 1
      src/main/java/com/szwl/service/impl/TCoinOrderServiceImpl.java
  28. 45 14
      src/main/java/com/szwl/service/impl/THuifuMchServiceImpl.java
  29. 0 1
      src/main/java/com/szwl/service/impl/TWeixinPayConfigServiceImpl.java
  30. 8 0
      src/main/java/com/szwl/utils/AirwallexWalletException.java
  31. 4 4
      src/test/java/com/szwl/AutoGeneratorTests.java

+ 1 - 1
src/main/java/com/szwl/common/myAnnotation/CamelCaseToUnderscoreFormatter.java

@@ -15,7 +15,7 @@ public class CamelCaseToUnderscoreFormatter implements Formatter<String> {
 
 	@Override
 	public String parse(String paramString, Locale paramLocale) throws ParseException {
-		// TODO Auto-generated method stub
+		// Auto-generated method stub
 		return convertCamelCaseToUnderscore(paramString);
 	}
 

+ 2 - 0
src/main/java/com/szwl/constant/AirwallexConstant.java

@@ -19,6 +19,8 @@ public class AirwallexConstant {
 
     public final static String QR_URL = "http://localhost:8080/shenze/#/hpp";
 
+//    public final static String QR_URL = "http://szwlh.sunzee.com.cn/shenze/#/hpp";
+
 
     public final static String MODE = "payment";
     /**

+ 24 - 102
src/main/java/com/szwl/constant/HuifuConstant.java

@@ -45,17 +45,32 @@ public class HuifuConstant {
     /**
      * 申泽商户公众账号ID
      */
-    public static final String WX_SUB_APP_ID = "wxcd5b1b2636c9f611";
+    public static final String SZ_WX_SUB_APP_ID = "wxcd5b1b2636c9f611";
 
     /**
-     * 申泽商户公众账号ID
+     * 七云商户公众账号ID
+     */
+    public static final String SC_WX_SUB_APP_ID = "wxd9c7c138a055ee66";
+
+    /**
+     * 申泽商户公众账号密钥
+     */
+    public static final String SZ_WX_APP_SECRET = "e2854aa99f8279f33b4f065b2ffb75b1";
+
+    /**
+     * 七云商户公众账号密钥
+     */
+    public static final String SC_WX_APP_SECRET = "f131c85c06a80e466bd7e366cd477b93";
+
+    /**
+     * 申泽分账商户号
      */
-    public static final String WX_APP_SECRET = "e2854aa99f8279f33b4f065b2ffb75b1";
+    public static final String SZ_DIV_HUIFU_ID = "6666000136120737";
 
     /**
-     * 分账商户号
+     * 七云分账商户号
      */
-    public static final String DIV_HUIFU_ID = "6666000136120737";
+    public static final String SC_DIV_HUIFU_ID = "6666000139220493";
 
     /**
      * >>>>>>>>>>>>> 币种 >>>>>>>>>>>>>
@@ -69,8 +84,10 @@ public class HuifuConstant {
     /**
      * 跳转链接
      */
-    public final static String JUMP_URL = "http://szwlh.sunzee.com.cn/shenze";
-//    public final static String JUMP_URL = "http://szwltest.sunzee.com.cn/shenze";
+    public final static String SZ_JUMP_URL = "http://szwlh.sunzee.com.cn/shenze";
+    public final static String SC_JUMP_URL = "http://sevencloud.com.cn/sc";
+//    public final static String SC_JUMP_URL = "http://szwltest.sunzee.com.cn/sc";
+//    public final static String SZ_JUMP_URL = "http://szwltest.sunzee.com.cn/shenze";
 
 
     /**
@@ -101,22 +118,6 @@ public class HuifuConstant {
     public final static String TRANS_STAT_P = "P";
     public final static String RESP_CODE_0 = "00000000";
 
-    /**
-     * >>>>>>>>>>>>> 签名类型 >>>>>>>>>>>>>
-     * 1=MD5,2=RSA
-     */
-    public final static String sign_type_MD5 = "1";
-    public final static String sign_type_RSA = "2";
-
-
-
-    /**
-     * >>>>>>>>>>>>> 账户类型 >>>>>>>>>>>>>
-     * 1 借记卡,4 对公账户
-     */
-    public final static Integer bank_account_type1 = 1;
-    public final static Integer bank_account_type4 = 4;
-
 
     /**
      *
@@ -196,85 +197,6 @@ public class HuifuConstant {
 
 
     /**
-     * >>>>>>>>>>>>> 支付交易类型 >>>>>>>>>>>>>
-     */
-    public static final Map<String, String> frp_code = new HashMap<>();
-    public static final String frp_code_ALIPAY_NATIVE = "ALIPAY_NATIVE";
-    public static final String frp_code_ALIPAY_CARD = "ALIPAY_CARD";
-    public static final String frp_code_ALIPAY_APP = "ALIPAY_APP";
-    public static final String frp_code_ALIPAY_H5 = "ALIPAY_H5";
-    public static final String frp_code_ALIPAY_FWC = "ALIPAY_FWC";
-    public static final String frp_code_ALIPAY_SYT = "ALIPAY_SYT";
-    public static final String frp_code_WEIXIN_NATIVE = "WEIXIN_NATIVE";
-    public static final String frp_code_WEIXIN_CARD = "WEIXIN_CARD";
-    public static final String frp_code_WEIXIN_APP = "WEIXIN_APP";
-    public static final String frp_code_WEIXIN_APP2 = "WEIXIN_APP2";
-    public static final String frp_code_WEIXIN_H5 = "WEIXIN_H5";
-    public static final String frp_code_WEIXIN_GZH = "WEIXIN_GZH";
-    public static final String frp_code_WEIXIN_XCX = "WEIXIN_XCX";
-    public static final String frp_code_JD_NATIVE = "JD_NATIVE";
-    public static final String frp_code_JD_CARD = "JD_CARD";
-    public static final String frp_code_JD_APP = "JD_APP";
-    public static final String frp_code_JD_H5 = "JD_H5";
-    public static final String frp_code_QQ_NATIVE = "QQ_NATIVE";
-    public static final String frp_code_QQ_CARD = "QQ_CARD";
-    public static final String frp_code_QQ_APP = "QQ_APP";
-    public static final String frp_code_QQ_H5 = "QQ_H5";
-    public static final String frp_code_QQ_GZH = "QQ_GZH";
-    public static final String frp_code_UNIONPAY_NATIVE = "UNIONPAY_NATIVE";
-    public static final String frp_code_UNIONPAY_CARD = "UNIONPAY_CARD";
-    public static final String frp_code_UNIONPAY_APP = "UNIONPAY_APP";
-    public static final String frp_code_UNIONPAY_H5 = "UNIONPAY_H5";
-    public static final String frp_code_BAIDU_NATIVE = "BAIDU_NATIVE";
-    public static final String frp_code_SUNING_NATIVE = "SUNING_NATIVE";
-
-
-    static {
-        biz_code.put(frp_code_ALIPAY_NATIVE, "支付宝扫码(主扫)");
-        biz_code.put(frp_code_ALIPAY_CARD, "支付宝刷卡(被扫)");
-        biz_code.put(frp_code_ALIPAY_APP, "支付宝APP 支付");
-        biz_code.put(frp_code_ALIPAY_H5, "支付宝H5");
-        biz_code.put(frp_code_ALIPAY_FWC, "支付宝服务窗");
-        biz_code.put(frp_code_ALIPAY_SYT, "支付宝收银台");
-        biz_code.put(frp_code_WEIXIN_NATIVE, "微信扫码(主扫)");
-        biz_code.put(frp_code_WEIXIN_CARD, "微信刷卡(被扫)");
-        biz_code.put(frp_code_WEIXIN_APP, "微信APP 支付");
-        biz_code.put(frp_code_WEIXIN_APP2, "微信APP2 支付");
-        biz_code.put(frp_code_WEIXIN_H5, "微信H5 支付");
-        biz_code.put(frp_code_WEIXIN_GZH, "微信公众号支付");
-        biz_code.put(frp_code_WEIXIN_XCX, "微信小程序支付");
-        biz_code.put(frp_code_JD_NATIVE, "京东扫码(主扫)");
-        biz_code.put(frp_code_JD_CARD, "京东刷卡(被扫)");
-        biz_code.put(frp_code_JD_APP, "京东APP 支付");
-        biz_code.put(frp_code_JD_H5, "京东H5 支付");
-        biz_code.put(frp_code_QQ_NATIVE, "QQ 扫码(主扫)");
-        biz_code.put(frp_code_QQ_CARD, "QQ 刷卡(被扫)");
-        biz_code.put(frp_code_QQ_APP, "QQ APP 支付");
-        biz_code.put(frp_code_QQ_H5, "QQH5 支付");
-        biz_code.put(frp_code_QQ_GZH, "QQ 公众号支付");
-        biz_code.put(frp_code_UNIONPAY_NATIVE, "银联扫码(主扫)");
-        biz_code.put(frp_code_UNIONPAY_CARD, "银联刷卡(被扫)");
-        biz_code.put(frp_code_UNIONPAY_APP, "银联APP 支付");
-        biz_code.put(frp_code_UNIONPAY_H5, "银联H5");
-        biz_code.put(frp_code_BAIDU_NATIVE, "百度扫码(主扫)");
-        biz_code.put(frp_code_SUNING_NATIVE, "苏宁扫码(主扫)");
-    }
-
-
-    /**
-     *
-     *
-     *  >>>>>>>>>>>>> 汇聚支付接口 >>>>>>>>>>>>>
-     *
-     *
-     */
-
-    /**
-     * 版本
-     */
-    public static final String pay_version = "2.1";
-
-    /**
      * 文件类型
      */
     public enum fileType {

+ 372 - 26
src/main/java/com/szwl/controller/AirwallexPayController.java

@@ -7,30 +7,33 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.szwl.common.AccessTokenCommon;
 import com.szwl.constant.AirwallexConstant;
 import com.szwl.feign.bean.SzwlFeign;
 import com.szwl.model.bean.PaymentIntentRequestBody;
 import com.szwl.model.bean.RefundRequestBody;
-import com.szwl.model.bo.JsonMessage;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.dto.*;
-import com.szwl.model.entity.TAdmin;
-import com.szwl.model.entity.TAirwallexPayment;
-import com.szwl.model.entity.TCoinOrder;
-import com.szwl.model.entity.TEquipment;
+import com.szwl.model.entity.*;
 import com.szwl.model.utils.AccessTokenThreadUtil;
 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.*;
 
 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.*;
@@ -41,8 +44,8 @@ import java.util.*;
 @RequestMapping("/api/airwallexPay")
 @Slf4j
 public class AirwallexPayController {
-    @Value("${test.value:bbb}")
-    private String testValue;
+//    @Value("${test.value:bbb}")
+//    private String testValue;
 
     TAdminService tAdminService;
 
@@ -50,16 +53,25 @@ public class AirwallexPayController {
 
     TCoinOrderService tCoinOrderService;
 
+    TOrderDetailsService tOrderDetailsService;
+
     TAirwallexPaymentService tAirwallexPaymentService;
 
     SzwlFeign szwlFeign;
 
-    public AirwallexPayController(TAdminService tAdminService, AirwallexService airwallexService, TCoinOrderService tCoinOrderService, TAirwallexPaymentService tAirwallexPaymentService, SzwlFeign szwlFeign) {
+    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 = "创建收款人")
@@ -135,6 +147,7 @@ public class AirwallexPayController {
         // 如果是海外客户,使用的是 Airwallex ,就要判断他有没有设置分销
         // 在 Airwallex 支付之前,要先判断
 
+        String createDate = paymentIntentRequestBody.getCreateDate();
         BigDecimal amount = paymentIntentRequestBody.getAmount();
         String currency = paymentIntentRequestBody.getCurrency();
         String merchantOrderId = paymentIntentRequestBody.getMerchantOrderId();
@@ -144,46 +157,165 @@ public class AirwallexPayController {
         String productName = paymentIntentRequestBody.getProductName();
         String clientId = paymentIntentRequestBody.getClientId();
         Long equipmentId = paymentIntentRequestBody.getEquipmentId();
+        Integer productNumber = paymentIntentRequestBody.getProductNumber();
+
+        // 生成订单编号
+        String sn = tCoinOrderService.initSn(equipmentId);
 
         // 七云还是申泽
         TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
+        if (equipment == null || equipmentId == null) {
+            return R.fail("找不到设备");
+        }
 //        System.out.println("设备信息:>>> " + equipment);
         String machineType = equipment.getMachineType(); // 设备类型
         Long adminId = equipment.getAdminId();
         if (adminId == null) {
             return R.fail("找不到设备商家");
         }
-        TAdmin byId = tAdminService.getById(adminId);
-        String companyType = byId.getCompanyType(); // 公司类型
-
+        String adminIdStr = String.valueOf(adminId);
+        // 根据 adminId 获取admin信息中的公司类型
+        TAdmin adminById = R.getDataIfSuccess(szwlFeign.getAdmin(adminIdStr));
+//        TAdmin byId = tAdminService.getById(adminId);
+        String companyType = adminById.getCompanyType(); // 公司类型
+
+        // Airwallex 分账参数
+        ArrayNode altInfos = JsonNodeFactory.instance.arrayNode();
+        // Airwallex 分账明细
+        ObjectNode airDistributionDetails = JsonNodeFactory.instance.objectNode();
+
+        // 查找商品
+        ResponseModel<TProduct> product = szwlFeign.getProduct(String.valueOf(equipmentId), productName);
+        // 获取关联设备的分销
+        TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
+        airDistributionDetails = getDistributionDetails(proportion, amount);
 
         // 创建订单
         TCoinOrder tCoinOrder = new TCoinOrder();
+        tCoinOrder.setAdminId(adminById.getId());
+
+        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);
         tCoinOrder.setMerchantOrderId(merchantOrderId);
         tCoinOrder.setRequestId(requestId);
         tCoinOrder.setProductId(productId);
         tCoinOrder.setProductName(productName);
+        tCoinOrder.setProductNumber(productNumber);
         tCoinOrder.setClientId(clientId);
         tCoinOrder.setEquipmentId(equipmentId);
         // 设置订单支付状态,0未支付,1已支付,3已退款。
-        tCoinOrder.setStatus("0");
+        tCoinOrder.setStatus(0);
         tCoinOrder.setIsAir("1");
+        tCoinOrder.setAltInfo(altInfos.toString());
         tCoinOrder.setMachineType(machineType);
         tCoinOrder.setCompanyType(companyType);
+        tCoinOrder.setType(adminById.getType());
+        switch (adminById.getType()) {
+            case 0:
+                tCoinOrder.setAdminProportion(proportion.getAdminProportion());
+                tCoinOrder.setAgencyProportion(proportion.getAgencyProportion());
+                tCoinOrder.setAgencyId(proportion.getAgencyId());
+                break;
+            case 1:
+                tCoinOrder.setAdminProportion(proportion.getAdminProportion());
+                tCoinOrder.setAgencyProportion(proportion.getAgencyProportion());
+                tCoinOrder.setAgencyId(proportion.getAgencyId());
+                tCoinOrder.setMerchantProportion(proportion.getMerchantProportion());
+                tCoinOrder.setMerchantId(proportion.getMerchantId());
+                break;
+            case 2:
+                tCoinOrder.setAdminProportion(proportion.getAdminProportion());
+                tCoinOrder.setAgencyProportion(proportion.getAgencyProportion());
+                tCoinOrder.setAgencyId(proportion.getAgencyId());
+                tCoinOrder.setMerchantProportion(proportion.getMerchantProportion());
+                tCoinOrder.setMerchantId(proportion.getMerchantId());
+                tCoinOrder.setPersonageProportion(proportion.getPersonageProportion());
+                tCoinOrder.setPersonageId(proportion.getPersonageId());
+                break;
+            default:
+                // 如果类型不匹配任何 case,则执行默认逻辑
+                break;
+        }
+        tCoinOrder.setAltInfo(airDistributionDetails.toString());
+
+        // 订单明细表
+        TOrderDetails tOrderDetails = new TOrderDetails();
+        tOrderDetails.setId(merchantOrderId);
+        tOrderDetails.setAdminId(adminById.getId());
+        tOrderDetails.setEquipmentId(equipmentId);
+        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);
+        tOrderDetails.setProductNo(product.getData().getNo());
+        tOrderDetails.setProductNumber(productNumber);
+        tOrderDetails.setAmount(amount);
+        tOrderDetails.setRefundStatus("0");
+        tOrderDetails.setCompanyType(companyType);
+        tOrderDetails.setMachineType(machineType);
+
+        String clientSix = clientId.substring(clientId.length() - 6);
+        String productNameMerge = "";
+        if (productNumber > 1) {
+            if (machineType == null || "0".equals(machineType)) {
+                productNameMerge = "棉花糖-" + equipment.getName() + "-" + clientSix;
+            } else {
+                productNameMerge = "爆米花-" + equipment.getName() + "-" + clientSix;
+            }
+        } else {
+            productNameMerge = productName + "-" + equipment.getName() + "-" + clientSix;
+        }
+
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectNode order = mapper.createObjectNode();
+        ArrayNode products = mapper.createArrayNode();
+
+        ObjectNode airProduct = mapper.createObjectNode();
+        // Name of the product. Maximum of 255 characters.
+//        airProduct.put("name", productNameMerge);
+        // Product description. Maximum of 500 characters.
+        airProduct.put("desc", productNameMerge);
+        airProduct.put("quantity", productNumber);
+
+        products.add(airProduct);
+        order.set("products", products);
 
         // 返回payment intent id和client secret
-        Map<String, Object> responseMap = airwallexService.caPaymentIntent(amount, currency, requestId, merchantOrderId);
+        Map<String, Object> responseMap = airwallexService.caPaymentIntent(amount, currency, requestId, merchantOrderId, order);
 
         String paymentIntentId = (String) responseMap.get("id");
         String clientSecret = (String) responseMap.get("client_secret");
 
-        // 把 paymentIntentId 保存到数据库
+        // 把 paymentIntentId 保存到表中
         tCoinOrder.setPaymentIntentId(paymentIntentId);
-        // 将订单存入数据库
-
-        tCoinOrderService.save(tCoinOrder);
 //        boolean save = tOrderAbroadService.save(tOrderAbroad);
 //        System.out.println("将订单存入数据库:" + save);
 
@@ -192,10 +324,11 @@ public class AirwallexPayController {
 //        String mode = AirwallexConstant.MODE;
 //        String locale = "it";
         String qrUrl = AirwallexConstant.QR_URL;
-
         String QR = qrUrl + "?intent_id=" + paymentIntentId + "&client_secret=" + clientSecret + "&currency=" + currency;
 
-        // TODO: 设置分销
+        // 将订单存入数据库
+        tCoinOrderService.save(tCoinOrder);
+        tOrderDetailsService.save(tOrderDetails);
 
         return R.ok().setData(QR);
     }
@@ -219,7 +352,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")))
@@ -268,6 +401,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<>();
@@ -283,7 +417,7 @@ public class AirwallexPayController {
         }
 
         // 支付状态:退款中
-        coinOrder.setStatus("2");
+        coinOrder.setStatus(2);
         // 修改订单表
 //        SimpleDateFormat sdf = new SimpleDateFormat();
 //        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
@@ -293,9 +427,10 @@ 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);
 
+        // TODO: 退款要扣除用户钱包中的金额,如果金额为0或者不足,改为负数?或者提示余额不足,联系商家手动退款
 
         // 发起退款
 //        String refund = airwallexService.createARefund(requestId, paymentIntentId, reason);
@@ -382,7 +517,7 @@ public class AirwallexPayController {
 
     }
 
-    @ApiOperation(value = "新建一笔付款")
+    @ApiOperation(value = "新建一笔付款,用于提现")
     @PostMapping("/caPayment")
     public R caPayment(@RequestBody CaPaymentRequestDTO caPaymentRequestDTO) {
 
@@ -406,7 +541,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);
@@ -420,8 +555,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);
@@ -461,4 +595,216 @@ public class AirwallexPayController {
         return R.ok(resp);
     }
 
+    /**
+     * 获取 Airwallex 分销明细
+     *
+     * @param proportion
+     * @param price
+     * @return
+     */
+    public ObjectNode getDistributionDetails(TProportion proportion, BigDecimal price) {
+        // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
+        Integer type = proportion.getType();
+
+        // 空中云汇 分账明细参数
+//        ArrayNode altInfos = new ObjectMapper().createArrayNode();
+        ArrayNode altInfos = JsonNodeFactory.instance.arrayNode();
+        ObjectNode distributionDetails = JsonNodeFactory.instance.objectNode();
+
+        BigDecimal airProportion = null, // 空中云汇平台分销百分比,假设是0
+                selfProportion = null, // 商家自己的分销百分比
+                agencyProportion = null, // 一级分销商分销百分比
+                merchantProportion = null; // 二级分销商分销百分比
+
+        BigDecimal airAmount = null, // 空中云汇的钱,假设是0
+                selfAmount = null, // 商家自己所得的钱
+                agencyAmount = null, // 一级分销商所得的钱
+                merchantAmount = null; // 二级分销商所得的钱
+
+        TAirwallexWallet selfAirWallet = null, // 商家收款信息
+                agencyAirWallet = null, // 一级分销商收款信息
+                merchantAirWallet = null; // 二级分销商收款信息
+
+        ObjectNode airJson = null, // 空中云汇
+                selfJson = null, // 商家
+                agencyJson = null, // 一级
+                merchantJson = null; // 二级
+
+        // 取消平台扣手续费,将price四舍五入保留2位小数
+        BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
+        BigDecimal refuseAmount = new BigDecimal(0.00);
+
+        switch (type) {
+            case 0: // 分账方有2个:申泽admin + 商家proportion
+                // 目前都暂定空中云汇平台分销为 0
+//                airProportion = proportion.getAdminProportion();
+                // 申泽的分销 eg.1%  不显示
+//                adminProportion = proportion.getAdminProportion();
+                // 商家自己的分销
+                selfProportion = proportion.getProportion();
+                // 平台分销获得利润
+//                airAmount = cutPrice.multiply(airProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
+                // 商家分销获得利润,五舍六入
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+
+                // Airwallex 平台收款信息表
+//                Long adminId = proportion.getAdminId();
+//                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();
+//                // 分账方受益人编号
+//                airJson.put("altMchId", selfAirMch.getBeneficiaryId());
+//                // 受益人所分金额,单位美元$
+//                airJson.put("altAirAmount", airAmount.toString());
+//                altInfos.add(airJson);
+
+                // 商家分销
+                selfJson = JsonNodeFactory.instance.objectNode();
+                selfJson.put("airBeneId", selfAirWallet.getAdminId()); // 受益人Bene编号,使用adminId
+                selfJson.put("airAmount", selfAmount.toString());
+                altInfos.add(selfJson);
+                break;
+            case 1: // 分账方有3个:申泽admin + 商家proportion + 商家一级agency
+                // 商家自己的分销
+                selfProportion = proportion.getProportion();
+                // 一级代理的分销
+                agencyProportion = proportion.getAgencyProportion();
+                // 商家分销获得利润
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+
+                // Airwallex 平台收款信息表
+                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", agencyAirWallet.getAdminId());
+                    agencyJson.put("airAmount", agencyAmount.toString());
+                    altInfos.add(agencyJson);
+                }
+                // 商家自己获得利润
+                selfJson = JsonNodeFactory.instance.objectNode();
+                selfJson.put("airBeneId", selfAirWallet.getAdminId());
+                selfJson.put("airAmount", selfAmount.toString());
+                altInfos.add(selfJson);
+                break;
+            case 2: // 分账方有4个:申泽admin + 商家self + 商家一级agency + 商家二级merchant
+                // 商家自己的分销
+                selfProportion = proportion.getProportion();
+                // 一级代理的分销
+                agencyProportion = proportion.getAgencyProportion();
+                // 二级代理的分销
+                merchantProportion = proportion.getMerchantProportion();
+
+                // 商家分销获得利润,五舍六入
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                // Airwallex 平台收款信息表
+                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", agencyAirWallet.getAdminId());
+                    agencyJson.put("airAmount", agencyAmount.toString());
+                    altInfos.add(agencyJson);
+                }
+                if (!(merchantProportion.compareTo(refuseAmount) == 0 || merchantProportion == null)) {
+                    // 二级经销商获得利润
+                    merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                    merchantJson = JsonNodeFactory.instance.objectNode();
+                    merchantJson.put("airBeneId", merchantAirWallet.getAdminId());
+                    merchantJson.put("airAmount", merchantAmount.toString());
+                    altInfos.add(merchantJson);
+                }
+                // 商家自己获得利润
+                selfJson = JsonNodeFactory.instance.objectNode();
+                selfJson.put("airBeneId", selfAirWallet.getAdminId());
+                selfJson.put("airAmount", selfAmount.toString());
+                altInfos.add(selfJson);
+                break;
+            case 3: // 分账方超过4个:申泽admin + 商家self + 商家一级agency + 商家二级merchant + 商家三级personage
+//                personageProportion = proportion.getPersonageProportion();
+                break;
+        }
+        // 计算airAmount的总和
+        BigDecimal sumAmount = BigDecimal.ZERO;
+        Iterator<JsonNode> iterator = altInfos.iterator();
+        while (iterator.hasNext()) {
+            JsonNode jsonNode = iterator.next();
+            String airAmounts = jsonNode.get("airAmount").asText();
+            if (airAmounts.equals("0.00")) {
+                iterator.remove();
+            }
+            if (jsonNode.has("airAmount")) {
+                BigDecimal airAmountSum = new BigDecimal(jsonNode.get("airAmount").asText());
+                sumAmount = sumAmount.add(airAmountSum);
+            }
+        }
+        // 如果sumAmount大于原本price
+        if (sumAmount.compareTo(price) > 0) {
+            BigDecimal subtract = sumAmount.subtract(price);
+            Iterator<JsonNode> iterator1 = altInfos.iterator();
+
+            while (iterator1.hasNext()) {
+                JsonNode jsonNode = iterator1.next();
+                String airBeneId = jsonNode.get("airBeneId").asText();
+//            String airBeneId1 = jsonNode.get("airBeneId").toString();
+
+                if (airBeneId.equals(AirwallexConstant.clientid)) {
+                    BigDecimal airAmount1 = new BigDecimal(jsonNode.get("airAmount").asText());
+                    BigDecimal fixAirAmount = airAmount1.subtract(subtract).max(BigDecimal.ZERO);
+
+//                    ObjectMapper objectMapper = new ObjectMapper();
+//                    ObjectNode objectNode = objectMapper.convertValue(jsonNode, ObjectNode.class);
+//                    objectNode.put("airAmount", fixAirAmount.toString());
+
+                    ((ObjectNode) jsonNode).put("airAmount", fixAirAmount.toString());
+                    break;
+                }
+            }
+        }
+        distributionDetails.put("alt_infos", altInfos);
+        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;
+    }
 }

+ 7 - 0
src/main/java/com/szwl/controller/TAirwallexMchController.java

@@ -1,6 +1,10 @@
 package com.szwl.controller;
 
 
+import com.szwl.model.bo.ResponseModel;
+import com.szwl.model.entity.TAirwallexMch;
+import com.szwl.service.TAdminService;
+import com.szwl.service.TAirwallexMchService;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
@@ -17,5 +21,8 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/tAirwallexMch")
 public class TAirwallexMchController {
 
+    public ResponseModel<TAirwallexMch> getAirMch(Long id) {
+        return null;
+    }
 }
 

+ 214 - 2
src/main/java/com/szwl/controller/TCoinOrderController.java

@@ -1,21 +1,233 @@
 package com.szwl.controller;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.szwl.constant.AirwallexConstant;
+import com.szwl.constant.HuifuConstant;
+import com.szwl.feign.bean.SzwlFeign;
+import com.szwl.model.bo.R;
+import com.szwl.model.entity.TAirwallexMch;
+import com.szwl.model.entity.TAirwallexWallet;
+import com.szwl.model.entity.THuifuMch;
+import com.szwl.model.entity.TProportion;
+import com.szwl.service.TAirwallexMchService;
+import com.szwl.service.TAirwallexWalletService;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Iterator;
+
 /**
  * <p>
- *  前端控制器
+ * 前端控制器
  * </p>
  *
  * @author wuhs
- * @since 2023-08-28
+ * @since 2023-08-29
  */
 @RestController
 @RequestMapping("/tCoinOrder")
 public class TCoinOrderController {
 
+    SzwlFeign szwlFeign;
+
+    TAirwallexWalletService airwallexWalletService;
+
+    public TCoinOrderController(TAirwallexWalletService airwallexWalletService, SzwlFeign szwlFeign) {
+        this.airwallexWalletService = airwallexWalletService;
+        this.szwlFeign = szwlFeign;
+    }
+
+
+    /**
+     * 获取 Airwallex 分销明细
+     *
+     * @param proportion
+     * @param price
+     * @return
+     */
+    public ObjectNode getDistributionDetails(TProportion proportion, BigDecimal price) {
+        // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
+        Integer type = proportion.getType();
+
+        // 空中云汇 分账明细参数
+//        ArrayNode altInfos = new ObjectMapper().createArrayNode();
+        ArrayNode altInfos = JsonNodeFactory.instance.arrayNode();
+        ObjectNode distributionDetails = JsonNodeFactory.instance.objectNode();
+
+        BigDecimal airProportion = null, // 空中云汇平台分销百分比,假设是0
+                selfProportion = null, // 商家自己的分销百分比
+                agencyProportion = null, // 一级分销商分销百分比
+                merchantProportion = null; // 二级分销商分销百分比
+
+        BigDecimal airAmount = null, // 空中云汇的钱,假设是0
+                selfAmount = null, // 商家自己所得的钱
+                agencyAmount = null, // 一级分销商所得的钱
+                merchantAmount = null; // 二级分销商所得的钱
+
+        TAirwallexWallet selfAirWallet = null, // 商家收款信息
+                agencyAirWallet = null, // 一级分销商收款信息
+                merchantAirWallet = null; // 二级分销商收款信息
+
+        ObjectNode airJson = null, // 空中云汇
+                selfJson = null, // 商家
+                agencyJson = null, // 一级
+                merchantJson = null; // 二级
+
+        // 取消平台扣手续费,将price四舍五入保留2位小数
+        BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
+        BigDecimal refuseAmount = new BigDecimal(0.00);
+
+        switch (type) {
+            case 0: // 分账方有2个:申泽admin + 商家proportion
+                // 目前都暂定空中云汇平台分销为 0
+//                airProportion = proportion.getAdminProportion();
+                // 申泽的分销 eg.1%  不显示
+//                adminProportion = proportion.getAdminProportion();
+                // 商家自己的分销
+                selfProportion = proportion.getProportion();
+                // 平台分销获得利润
+//                airAmount = cutPrice.multiply(airProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
+                // 商家分销获得利润,五舍六入
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+
+                // Airwallex 平台收款信息表
+//                Long adminId = proportion.getAdminId();
+                LambdaQueryWrapper<TAirwallexWallet> wrapper = Wrappers.lambdaQuery();
+                wrapper.eq(TAirwallexWallet::getAdminId, proportion.getAdminId());
+                selfAirWallet = airwallexWalletService.getOne(wrapper);
+
+                // 平台分销
+//                airJson = JsonNodeFactory.instance.objectNode();
+//                // 分账方受益人编号
+//                airJson.put("altMchId", selfAirMch.getBeneficiaryId());
+//                // 受益人所分金额,单位美元$
+//                airJson.put("altAirAmount", airAmount.toString());
+//                altInfos.add(airJson);
+
+                // 商家分销
+                selfJson = JsonNodeFactory.instance.objectNode();
+                selfJson.put("airBeneId", selfAirWallet.getAdminId());
+                selfJson.put("airAmount", selfAmount.toString());
+                altInfos.add(selfJson);
+                break;
+            case 1: // 分账方有3个:申泽admin + 商家proportion + 商家一级agency
+                // 商家自己的分销
+                selfProportion = proportion.getProportion();
+                // 一级代理的分销
+                agencyProportion = proportion.getAgencyProportion();
+                // 商家分销获得利润
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+
+                // Airwallex 平台收款信息表
+                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", agencyAirWallet.getAdminId());
+                    agencyJson.put("airAmount", agencyAmount.toString());
+                    altInfos.add(agencyJson);
+                }
+                // 商家自己获得利润
+                selfJson = JsonNodeFactory.instance.objectNode();
+                selfJson.put("airBeneId", selfAirWallet.getAdminId());
+                selfJson.put("airAmount", selfAmount.toString());
+                altInfos.add(selfJson);
+                break;
+            case 2: // 分账方有4个:申泽admin + 商家self + 商家一级agency + 商家二级merchant
+                // 商家自己的分销
+                selfProportion = proportion.getProportion();
+                // 一级代理的分销
+                agencyProportion = proportion.getAgencyProportion();
+                // 二级代理的分销
+                merchantProportion = proportion.getMerchantProportion();
+
+                // 商家分销获得利润,五舍六入
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                // Airwallex 平台收款信息表
+                selfAirWallet = airwallexWalletService.getAirWallet(proportion.getAdminId());
+                agencyAirWallet = airwallexWalletService.getAirWallet(proportion.getAgencyId());
+                merchantAirWallet = airwallexWalletService.getAirWallet(proportion.getMerchantId());
+                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", agencyAirWallet.getAdminId());
+                    agencyJson.put("airAmount", agencyAmount.toString());
+                    altInfos.add(agencyJson);
+                }
+                if (!(merchantProportion.compareTo(refuseAmount) == 0 || merchantProportion == null)) {
+                    // 二级经销商获得利润
+                    merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                    merchantJson = JsonNodeFactory.instance.objectNode();
+                    merchantJson.put("airBeneId", merchantAirWallet.getAdminId());
+                    merchantJson.put("airAmount", merchantAmount.toString());
+                    altInfos.add(merchantJson);
+                }
+                // 商家自己获得利润
+                selfJson = JsonNodeFactory.instance.objectNode();
+                selfJson.put("airBeneId", selfAirWallet.getAdminId());
+                selfJson.put("airAmount", selfAmount.toString());
+                altInfos.add(selfJson);
+                break;
+            case 3: // 分账方超过4个:申泽admin + 商家self + 商家一级agency + 商家二级merchant + 商家三级personage
+//                personageProportion = proportion.getPersonageProportion();
+                break;
+        }
+        // 计算airAmount的总和
+        BigDecimal sumAmount = BigDecimal.ZERO;
+        Iterator<JsonNode> iterator = altInfos.iterator();
+        while (iterator.hasNext()) {
+            JsonNode jsonNode = iterator.next();
+            String airAmounts = jsonNode.get("airAmount").asText();
+            if (airAmounts.equals("0.00")) {
+                iterator.remove();
+            }
+            if (jsonNode.has("airAmount")) {
+                BigDecimal airAmountSum = new BigDecimal(jsonNode.get("airAmount").asText());
+                sumAmount = sumAmount.add(airAmountSum);
+            }
+        }
+        // 如果sumAmount大于原本price
+        if (sumAmount.compareTo(price) > 0) {
+            BigDecimal subtract = sumAmount.subtract(price);
+            Iterator<JsonNode> iterator1 = altInfos.iterator();
+
+            while (iterator1.hasNext()) {
+                JsonNode jsonNode = iterator1.next();
+                String airBeneId = jsonNode.get("airBeneId").asText();
+//            String airBeneId1 = jsonNode.get("airBeneId").toString();
+
+                if (airBeneId.equals(AirwallexConstant.clientid)) {
+                    BigDecimal airAmount1 = new BigDecimal(jsonNode.get("airAmount").asText());
+                    BigDecimal fixAirAmount = airAmount1.subtract(subtract).max(BigDecimal.ZERO);
+
+//                    ObjectMapper objectMapper = new ObjectMapper();
+//                    ObjectNode objectNode = objectMapper.convertValue(jsonNode, ObjectNode.class);
+//                    objectNode.put("airAmount", fixAirAmount.toString());
+
+                    ((ObjectNode) jsonNode).put("airAmount", fixAirAmount.toString());
+                    break;
+                }
+            }
+        }
+        distributionDetails.put("alt_infos", altInfos);
+        return distributionDetails;
+    }
 }
 

+ 437 - 84
src/main/java/com/szwl/controller/TOrderController.java

@@ -192,9 +192,6 @@ public class TOrderController {
             return JsonMessage.error("参数错误");
         }
 
-        if (equipment == null) {
-            return JsonMessage.error("找不到设备");
-        }
 
         Long equipmentId = equipment.getId();
         //查找商品
@@ -230,12 +227,13 @@ public class TOrderController {
 
         // 支付方式:0或null为汇聚,1为汇付支付
         String payPlatform = admin.getPayPlatform();
+        String companyType = admin.getCompanyType();
         // 汇聚分账参数
         JSONArray altInfo = new JSONArray();
         // 汇付分账明细参数
         JSONObject acctSplitBunch = new JSONObject();
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
-            acctSplitBunch = getAcctSplitBunch(proportion, price);
+            acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
         } else {
             altInfo = getAltInfo(proportion, price);
         }
@@ -282,14 +280,14 @@ public class TOrderController {
         if(admin.getType()==0){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(admin.getId());
+            order.setAgencyId(proportion.getAgencyId());
         }
         if(admin.getType()==1){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
             order.setAgencyId(proportion.getAgencyId());
             order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(admin.getId());
+            order.setMerchantId(proportion.getMerchantId());
         }
         if(admin.getType()==2){
             order.setAdminProportion(proportion.getAdminProportion());
@@ -298,7 +296,7 @@ public class TOrderController {
             order.setMerchantProportion(proportion.getMerchantProportion());
             order.setMerchantId(proportion.getMerchantId());
             order.setPersonageProportion(proportion.getPersonageProportion());
-            order.setPersonageId(admin.getId());
+            order.setPersonageId(proportion.getPersonageId());
         }
 
         order.setPayPlatform(payPlatform);
@@ -315,7 +313,7 @@ public class TOrderController {
         orderDetails.setProductNumber(productNumber);
         orderDetails.setAmount(price);
         orderDetails.setRefundStatus("0");
-        orderDetails.setCompanyType(admin.getCompanyType());
+        orderDetails.setCompanyType(companyType);
         orderDetails.setMachineType(equipment.getMachineType());
 
         String client6 = clientId.substring(clientId.length() - 6);
@@ -332,8 +330,12 @@ public class TOrderController {
                 tHuifuTempOrder.setId(id);
                 BeanUtil.copyProperties(order,tHuifuTempOrder,ignoreProperties);
                 huifuTempOrderService.save(tHuifuTempOrder);
-                result =  HuifuConstant.JUMP_URL+ "/#/weChatPay?id=" + id;
-                System.out.println(result);
+                if (StrUtil.isNotEmpty(companyType)&&companyType.equals("1")) {
+                    result =  HuifuConstant.SC_JUMP_URL+ "/#/weChatPay?id=" + id;
+                } else {
+                    result =  HuifuConstant.SZ_JUMP_URL+ "/#/weChatPay?id=" + id;
+                }
+                log.info("返回链接:{}", result);
                 String qrcode = toQrcode(result);
                 JSONObject kindData = new JSONObject();
                 kindData.put("sn", sn);
@@ -344,7 +346,7 @@ public class TOrderController {
             try {
                 result = huifuMchService.uniPay(
                         orderNo, amount, productName1, productDesc,
-                        notifyUrl, frpCode, openId, appid, acctSplitBunch
+                        notifyUrl, frpCode, openId, appid, acctSplitBunch, companyType
                 );
             } catch (Exception e) {
                 e.printStackTrace();
@@ -490,12 +492,13 @@ public class TOrderController {
 
         // 支付方式:0或null为汇聚,1为汇付支付
         String payPlatform = admin.getPayPlatform();
+        String companyType = admin.getCompanyType();
         // 汇聚分账参数
         JSONArray altInfo = new JSONArray();
         // 汇付分账明细参数
         JSONObject acctSplitBunch = new JSONObject();
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
-            acctSplitBunch = getAcctSplitBunch(proportion, price);
+      acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
         } else {
             altInfo = getAltInfo(proportion, price);
         }
@@ -543,14 +546,14 @@ public class TOrderController {
         if(admin.getType()==0){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(admin.getId());
+            order.setAgencyId(proportion.getAgencyId());
         }
         if(admin.getType()==1){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
             order.setAgencyId(proportion.getAgencyId());
             order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(admin.getId());
+            order.setMerchantId(proportion.getMerchantId());
         }
         if(admin.getType()==2){
             order.setAdminProportion(proportion.getAdminProportion());
@@ -559,7 +562,7 @@ public class TOrderController {
             order.setMerchantProportion(proportion.getMerchantProportion());
             order.setMerchantId(proportion.getMerchantId());
             order.setPersonageProportion(proportion.getPersonageProportion());
-            order.setPersonageId(admin.getId());
+            order.setPersonageId(proportion.getPersonageId());
         }
         order.setPayPlatform(payPlatform);
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
@@ -579,7 +582,7 @@ public class TOrderController {
         orderDetails.setProductNumber(productNumber);
         orderDetails.setAmount(price);
         orderDetails.setRefundStatus("0");
-        orderDetails.setCompanyType(admin.getCompanyType());
+        orderDetails.setCompanyType(companyType);
         orderDetails.setMachineType(equipment.getMachineType());
 
         String client6 = clientId.substring(clientId.length() - 6);
@@ -589,7 +592,7 @@ public class TOrderController {
             order.setAcctSplitBunch(acctSplitBunch.toString());
             try {
                 result = huifuMchService.cardPay(
-                        orderNo, amount, productName1, notifyUrl, authCode,  acctSplitBunch
+                        orderNo, amount, productName1, notifyUrl, authCode,  acctSplitBunch, companyType
                 );
             } catch (Exception e) {
                 e.printStackTrace();
@@ -727,12 +730,13 @@ public class TOrderController {
 
         // 支付方式:0或null为汇聚,1为汇付支付
         String payPlatform = admin.getPayPlatform();
+        String companyType = admin.getCompanyType();
         // 汇聚分账参数
         JSONArray altInfo = new JSONArray();
         // 汇付分账明细参数
         JSONObject acctSplitBunch = new JSONObject();
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
-            acctSplitBunch = getAcctSplitBunch(proportion, price);
+            acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
         } else {
             altInfo = getAltInfo(proportion, price);
         }
@@ -776,19 +780,19 @@ public class TOrderController {
         order.setAltInfo(altInfo.toString());
         order.setStatus(0);
         order.setType(admin.getType());
-        order.setCompanyType(admin.getCompanyType());
+        order.setCompanyType(companyType);
         order.setMachineType(equipment.getMachineType());
         if(admin.getType()==0){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(admin.getId());
+            order.setAgencyId(proportion.getAgencyId());
         }
         if(admin.getType()==1){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
             order.setAgencyId(proportion.getAgencyId());
             order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(admin.getId());
+            order.setMerchantId(proportion.getMerchantId());
         }
         if(admin.getType()==2){
             order.setAdminProportion(proportion.getAdminProportion());
@@ -797,7 +801,7 @@ public class TOrderController {
             order.setMerchantProportion(proportion.getMerchantProportion());
             order.setMerchantId(proportion.getMerchantId());
             order.setPersonageProportion(proportion.getPersonageProportion());
-            order.setPersonageId(admin.getId());
+            order.setPersonageId(proportion.getPersonageId());
         }
         order.setPayPlatform(payPlatform);
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
@@ -818,9 +822,31 @@ public class TOrderController {
         order2.setFrpCode(frpCode2);
         order2.setAltInfo(altInfo.toString());
         order2.setStatus(0);
+        order2.setType(admin.getType());
         order2.setPayPlatform(payPlatform);
-        order2.setCompanyType(admin.getCompanyType());
+        order2.setCompanyType(companyType);
         order2.setMachineType(equipment.getMachineType());
+        if(admin.getType()==0){
+            order2.setAdminProportion(proportion.getAdminProportion());
+            order2.setAgencyProportion(proportion.getAgencyProportion());
+            order2.setAgencyId(proportion.getAgencyId());
+        }
+        if(admin.getType()==1){
+            order2.setAdminProportion(proportion.getAdminProportion());
+            order2.setAgencyProportion(proportion.getAgencyProportion());
+            order2.setAgencyId(proportion.getAgencyId());
+            order2.setMerchantProportion(proportion.getMerchantProportion());
+            order2.setMerchantId(proportion.getMerchantId());
+        }
+        if(admin.getType()==2){
+            order2.setAdminProportion(proportion.getAdminProportion());
+            order2.setAgencyProportion(proportion.getAgencyProportion());
+            order2.setAgencyId(proportion.getAgencyId());
+            order2.setMerchantProportion(proportion.getMerchantProportion());
+            order2.setMerchantId(proportion.getMerchantId());
+            order2.setPersonageProportion(proportion.getPersonageProportion());
+            order2.setPersonageId(proportion.getPersonageId());
+        }
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
             order2.setIsSettlement("0");
         }
@@ -834,7 +860,7 @@ public class TOrderController {
         orderDetails.setProductNo(product.getNo());
         orderDetails.setProductNumber(productNumber);
         orderDetails.setAmount(price);
-        orderDetails.setCompanyType(admin.getCompanyType());
+        orderDetails.setCompanyType(companyType);
         orderDetails.setRefundStatus("0");
         orderDetails.setMachineType(equipment.getMachineType());
 
@@ -852,12 +878,17 @@ public class TOrderController {
             tHuifuTempOrder.setId(id);
             BeanUtil.copyProperties(order,tHuifuTempOrder,ignoreProperties);
             huifuTempOrderService.save(tHuifuTempOrder);
-            String result1 =  HuifuConstant.JUMP_URL+ "/#/weChatPay?id=" + id;
+            String result1 = "";
+            if (StrUtil.isNotEmpty(companyType)&&companyType.equals("1")) {
+                result1 =  HuifuConstant.SC_JUMP_URL+ "/#/weChatPay?id=" + id;
+            } else {
+                result1 =  HuifuConstant.SZ_JUMP_URL+ "/#/weChatPay?id=" + id;
+            }
             // 支付宝
             try {
                 result = huifuMchService.uniPay(
                         sn2, amount, productName1, productDesc,
-                        notifyUrl, frpCode2, openId, appid, acctSplitBunch
+                        notifyUrl, frpCode2, openId, appid, acctSplitBunch,companyType
                 );
             } catch (Exception e) {
                 e.printStackTrace();
@@ -1117,12 +1148,13 @@ public class TOrderController {
 
         // 支付方式:0或null为汇聚,1为汇付支付
         String payPlatform = admin.getPayPlatform();
+        String companyType = admin.getCompanyType();
         // 汇聚分账参数
         JSONArray altInfo = new JSONArray();
         // 汇付分账明细参数
         JSONObject acctSplitBunch = new JSONObject();
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
-            acctSplitBunch = getAcctSplitBunch(proportion, price);
+            acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
         } else {
             altInfo = getAltInfo(proportion, price);
         }
@@ -1170,19 +1202,19 @@ public class TOrderController {
         order.setProductNumber(productNumber);
         order.setStatus(0);
         order.setType(admin.getType());
-        order.setCompanyType(admin.getCompanyType());
+        order.setCompanyType(companyType);
         order.setMachineType(equipment.getMachineType());
         if(admin.getType()==0){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(admin.getId());
+            order.setAgencyId(proportion.getAgencyId());
         }
         if(admin.getType()==1){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
             order.setAgencyId(proportion.getAgencyId());
             order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(admin.getId());
+            order.setMerchantId(proportion.getMerchantId());
         }
         if(admin.getType()==2){
             order.setAdminProportion(proportion.getAdminProportion());
@@ -1191,7 +1223,7 @@ public class TOrderController {
             order.setMerchantProportion(proportion.getMerchantProportion());
             order.setMerchantId(proportion.getMerchantId());
             order.setPersonageProportion(proportion.getPersonageProportion());
-            order.setPersonageId(admin.getId());
+            order.setPersonageId(proportion.getPersonageId());
         }
         order.setPayPlatform(payPlatform);
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
@@ -1212,29 +1244,29 @@ public class TOrderController {
         order2.setAltInfo(altInfo.toString());
         order2.setStatus(0);
         order2.setProductNumber(productNumber);
-        order.setType(admin.getType());
-        order.setCompanyType(admin.getCompanyType());
+        order2.setType(admin.getType());
+        order2.setCompanyType(companyType);
         order2.setMachineType(equipment.getMachineType());
         if(admin.getType()==0){
-            order.setAdminProportion(proportion.getAdminProportion());
-            order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(admin.getId());
+            order2.setAdminProportion(proportion.getAdminProportion());
+            order2.setAgencyProportion(proportion.getAgencyProportion());
+            order2.setAgencyId(proportion.getAgencyId());
         }
         if(admin.getType()==1){
-            order.setAdminProportion(proportion.getAdminProportion());
-            order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(proportion.getAgencyId());
-            order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(admin.getId());
+            order2.setAdminProportion(proportion.getAdminProportion());
+            order2.setAgencyProportion(proportion.getAgencyProportion());
+            order2.setAgencyId(proportion.getAgencyId());
+            order2.setMerchantProportion(proportion.getMerchantProportion());
+            order2.setMerchantId(proportion.getMerchantId());
         }
         if(admin.getType()==2){
-            order.setAdminProportion(proportion.getAdminProportion());
-            order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(proportion.getAgencyId());
-            order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(proportion.getMerchantId());
-            order.setPersonageProportion(proportion.getPersonageProportion());
-            order.setPersonageId(admin.getId());
+            order2.setAdminProportion(proportion.getAdminProportion());
+            order2.setAgencyProportion(proportion.getAgencyProportion());
+            order2.setAgencyId(proportion.getAgencyId());
+            order2.setMerchantProportion(proportion.getMerchantProportion());
+            order2.setMerchantId(proportion.getMerchantId());
+            order2.setPersonageProportion(proportion.getPersonageProportion());
+            order2.setPersonageId(proportion.getPersonageId());
         }
         order2.setPayPlatform(payPlatform);
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
@@ -1246,7 +1278,7 @@ public class TOrderController {
         orderDetails.setAdminId(admin.getId());
         orderDetails.setEquipmentId(equipmentId);
         orderDetails.setCreateDate(new Date());
-        orderDetails.setCompanyType(admin.getCompanyType());
+        orderDetails.setCompanyType(companyType);
         orderDetails.setRefundStatus("0");
         orderDetails.setMachineType(equipment.getMachineType());
 
@@ -1273,12 +1305,17 @@ public class TOrderController {
             tHuifuTempOrder.setId(id);
             BeanUtil.copyProperties(order,tHuifuTempOrder,ignoreProperties);
             huifuTempOrderService.save(tHuifuTempOrder);
-            String result1 =  HuifuConstant.JUMP_URL+"/#/weChatPay?id=" + id;
+            String result1 = "";
+            if (StrUtil.isNotEmpty(companyType)&&companyType.equals("1")) {
+                result1 =  HuifuConstant.SC_JUMP_URL+ "/#/weChatPay?id=" + id;
+            } else {
+                result1 =  HuifuConstant.SZ_JUMP_URL+ "/#/weChatPay?id=" + id;
+            }
             // 支付宝
             try {
                 result = huifuMchService.uniPay(
                         sn2, amount, productName1, productDesc,
-                        notifyUrl, frpCode2, openId, appid, acctSplitBunch
+                        notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
                 );
             } catch (Exception e) {
                 e.printStackTrace();
@@ -1578,12 +1615,13 @@ public class TOrderController {
 
         // 支付方式:0或null为汇聚,1为汇付支付
         String payPlatform = admin.getPayPlatform();
+        String companyType = admin.getCompanyType();
         // 汇聚分账参数
         JSONArray altInfo = new JSONArray();
         // 汇付分账明细参数
         JSONObject acctSplitBunch = new JSONObject();
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
-            acctSplitBunch = getAcctSplitBunch(proportion, price);
+            acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
         } else {
             altInfo = getAltInfo(proportion, price);
         }
@@ -1673,7 +1711,7 @@ public class TOrderController {
         order.setType(admin.getType());
         order.setMarketingAmount(marketingAmount);
         order.setProductNumber(productNumber);
-        order.setCompanyType(admin.getCompanyType());
+        order.setCompanyType(companyType);
         order.setMachineType(equipment.getMachineType());
         if(couponList.size()>0){
             order.setCoupons(couponList.toString());
@@ -1681,14 +1719,14 @@ public class TOrderController {
         if(admin.getType()==0){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
-            order.setAgencyId(admin.getId());
+            order.setAgencyId(proportion.getAgencyId());
         }
         if(admin.getType()==1){
             order.setAdminProportion(proportion.getAdminProportion());
             order.setAgencyProportion(proportion.getAgencyProportion());
             order.setAgencyId(proportion.getAgencyId());
             order.setMerchantProportion(proportion.getMerchantProportion());
-            order.setMerchantId(admin.getId());
+            order.setMerchantId(proportion.getMerchantId());
         }
         if(admin.getType()==2){
             order.setAdminProportion(proportion.getAdminProportion());
@@ -1697,7 +1735,7 @@ public class TOrderController {
             order.setMerchantProportion(proportion.getMerchantProportion());
             order.setMerchantId(proportion.getMerchantId());
             order.setPersonageProportion(proportion.getPersonageProportion());
-            order.setPersonageId(admin.getId());
+            order.setPersonageId(proportion.getPersonageId());
         }
         order.setPayPlatform(payPlatform);
         if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
@@ -1726,7 +1764,7 @@ public class TOrderController {
         orderDetails.setAdminId(admin.getId());
         orderDetails.setEquipmentId(equipmentId);
         orderDetails.setCreateDate(new Date());
-        orderDetails.setCompanyType(admin.getCompanyType());
+        orderDetails.setCompanyType(companyType);
         orderDetails.setRefundStatus("0");
         orderDetails.setMachineType(equipment.getMachineType());
 
@@ -1747,7 +1785,7 @@ public class TOrderController {
             try {
                 result = huifuMchService.uniPay(
                         orderNo1, amount, productName1, productDesc,
-                        notifyUrl, frpCode1, openId, appid, acctSplitBunch
+                        notifyUrl, frpCode1, openId, appid, acctSplitBunch, companyType
                 );
             } catch (Exception e) {
                 e.printStackTrace();
@@ -1819,27 +1857,54 @@ public class TOrderController {
         // 获取code
         String code = request.getParameter("code");
         String id = request.getParameter("state");
-        // 获取openid
-        String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
-                "appid=" + HuifuConstant.WX_SUB_APP_ID +
-                "&secret=" + HuifuConstant.WX_APP_SECRET +
-                "&code=" + code +
-                "&grant_type=authorization_code";
-        org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
-        String openid = jsonObject.getString("openid");
-        // 从临时表中获取订单信息
         LambdaQueryWrapper<THuifuTempOrder> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(THuifuTempOrder::getId,id);
         THuifuTempOrder huifuTempOrder = huifuTempOrderService.getOne(wrapper);
+        // 从临时表中获取订单信息
         String result = null;
-        if(huifuTempOrder.getStatus() == 1) {
-//            result = "http://szwltest.sunzee.com.cn/shenze/#/popPayment?status=1";
-            result = HuifuConstant.JUMP_URL+"/#/popPayment?status=1";
-        } else {
-            try {
-                result = huifuMchService.wetchatPay(huifuTempOrder,openid);
-            } catch (Exception e) {
-                e.printStackTrace();
+        if(huifuTempOrder != null) {
+            String companyType = huifuTempOrder.getCompanyType();
+            if(huifuTempOrder.getStatus() == 1) {
+                if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+                    result = HuifuConstant.SC_JUMP_URL+"/#/popPayment?status=1";
+                } else {
+                    result = HuifuConstant.SZ_JUMP_URL+"/#/popPayment?status=1";
+                }
+            } else {
+                String openid;
+                if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+                    // 获取openid
+                    try {
+                        String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
+                                "appid=" + HuifuConstant.SC_WX_SUB_APP_ID +
+                                "&secret=" + HuifuConstant.SC_WX_APP_SECRET +
+                                "&code=" + code +
+                                "&grant_type=authorization_code";
+                        log.info("获取openID:{}", openUrl);
+                        org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
+                        log.info("获取openID结果:{}", jsonObject);
+                        openid = jsonObject.getString("openid");
+                        result = huifuMchService.wetchatPay(huifuTempOrder,openid);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                } else {
+                    // 获取openid
+                    try {
+                        String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
+                                "appid=" + HuifuConstant.SZ_WX_SUB_APP_ID +
+                                "&secret=" + HuifuConstant.SZ_WX_APP_SECRET +
+                                "&code=" + code +
+                                "&grant_type=authorization_code";
+                        log.info("获取openID:{}", openUrl);
+                        org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
+                        log.info("获取openID结果:{}", jsonObject);
+                        openid = jsonObject.getString("openid");
+                        result = huifuMchService.wetchatPay(huifuTempOrder,openid);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
             }
         }
         log.info("支付链接:{}",result);
@@ -2570,10 +2635,10 @@ public class TOrderController {
                 order.setRefundAmount(newRefundAmount);
                 // 如果小于订单金额
                 if(newRefundAmount.compareTo(order.getPrice()) < 0) {
-                    acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice().subtract(newRefundAmount)).toString();
+                    acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice().subtract(newRefundAmount), order.getCompanyType()).toString();
                     order.setAcctSplitBunch(acctSplitBunch);
                 } else {
-                    acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice()).toString();
+                    acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice(), order.getCompanyType()).toString();
                     order.setAcctSplitBunch(acctSplitBunch);
                 }
             } else {
@@ -2581,7 +2646,7 @@ public class TOrderController {
                 if(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP).compareTo(order.getPrice()) < 0) {
                     // 重新设置分销
                     acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice()
-                            .subtract(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP))).toString();
+                            .subtract(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP)), order.getCompanyType()).toString();
                     order.setAcctSplitBunch(acctSplitBunch);
                 }
             }
@@ -3165,7 +3230,8 @@ public class TOrderController {
                 merchantJson = new JSONObject();
                 merchantJson.put("altMchNo", selfMch.getAltMchNo());
                 merchantJson.put("altAmount", selfAmount.toString());
-                merchantJson.put("isGuar", "12");altInfo.add(merchantJson);
+                merchantJson.put("isGuar", "12");
+                altInfo.add(merchantJson);
                 break;
         }
         Iterator<Object> iterator = altInfo.iterator();
@@ -3185,7 +3251,7 @@ public class TOrderController {
      * @param price
      * @return
      */
-    public JSONObject getAcctSplitBunch(TProportion proportion, BigDecimal price) {
+    public JSONObject getAcctSplitBunch(TProportion proportion, BigDecimal price, String companyType) {
 
         // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
         Integer type = proportion.getType();
@@ -3232,7 +3298,12 @@ public class TOrderController {
                 // 公司平台分销
                 adminJson = new JSONObject();
                 adminJson.put("div_amt", adminAmount.toString());
-                adminJson.put("huifu_id", HuifuConstant.DIV_HUIFU_ID);
+                // 判断为申泽还是七云
+                if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+                    adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
+                } else {
+                    adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
+                }
                 acctInfos.add(adminJson);
                 // 商家分销获得利润
                 selfJson = new JSONObject();
@@ -3258,7 +3329,12 @@ public class TOrderController {
                 // 公司平台分销
                 adminJson = new JSONObject();
                 adminJson.put("div_amt", adminAmount.toString());
-                adminJson.put("huifu_id", HuifuConstant.DIV_HUIFU_ID);
+                // 判断为申泽还是七云
+                if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+                    adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
+                } else {
+                    adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
+                }
                 acctInfos.add(adminJson);
                 // 商家分销获得利润
                 selfJson = new JSONObject();
@@ -3294,7 +3370,12 @@ public class TOrderController {
                 // 公司平台分销
                 adminJson = new JSONObject();
                 adminJson.put("div_amt", adminAmount.toString());
-                adminJson.put("huifu_id", HuifuConstant.DIV_HUIFU_ID);
+                // 判断为申泽还是七云
+                if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+                    adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
+                } else {
+                    adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
+                }
                 acctInfos.add(adminJson);
                 // 商家分销获得利润
                 selfJson = new JSONObject();
@@ -3332,7 +3413,7 @@ public class TOrderController {
             for (int i = 0; i < acctInfos.size(); i++) {
                 JSONObject jsonObject = acctInfos.getJSONObject(i);
                 String huifuId = jsonObject.getString("huifu_id");
-                if (huifuId.equals(HuifuConstant.DIV_HUIFU_ID)) {
+                if (huifuId.equals(HuifuConstant.SZ_DIV_HUIFU_ID) || huifuId.equals(HuifuConstant.SC_DIV_HUIFU_ID)) {
                     BigDecimal currentDivAmt = new BigDecimal(jsonObject.getString("div_amt"));
                     BigDecimal adjustedDivAmt = currentDivAmt.subtract(diffAmount).max(BigDecimal.ZERO);
                     jsonObject.put("div_amt", adjustedDivAmt.toString());
@@ -3344,5 +3425,277 @@ public class TOrderController {
         return acctSplitBunch;
     }
 
+    /**
+     * 旧版退款成功回调
+     *
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/oldNotifyRefund", method = RequestMethod.GET)
+    @ResponseBody
+    public Object oldNotifyRefund(HttpServletRequest request) {
+
+        String r6_Status = request.getParameter("ra_Status");
+
+        // 订单号
+        String sn = request.getParameter("r2_OrderNo");
+        // 退款订单号
+        String refundSn = request.getParameter("r3_RefundOrderNo");
+        String num = refundSn.substring(refundSn.length() - 1);
+        Integer refundNumber = Integer.valueOf(num);
+
+//        LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
+        LambdaQueryWrapper<TOrder> query = new LambdaQueryWrapper<>();
+        query.eq(TOrder::getSn,sn);
+        if(StringUtils.isEmpty(sn)){
+            return  "error";
+        }
+//        List<TOrder> list = orderService.list(query);
+//        TOrder order = list.get(0);
+        TOrder order = orderService.getOne(query);
+        if (order == null) {
+            return "success";
+        }
+        if (order.getStatus() == 3) {
+            return "success";
+        }
+        // 判断退款版本号是否存在
+        String refundOrderNo = order.getRefundOrderNo();
+        if(StringUtils.isNotEmpty(refundOrderNo)) {
+            if(refundSn.equals(refundOrderNo)) {
+                try {
+                    esTOrderService.updateDataById(order);
+                }catch (Exception e) {
+                    e.printStackTrace();
+                }
+                return "success";
+            }
+        }
+        // 订单商品数量
+        Integer productNumber = order.getProductNumber();
+        if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
+            // 设置退款版本号
+            order.setRefundOrderNo(refundSn);
+            // 已退款
+            if(productNumber >= refundNumber){
+                productNumber -= refundNumber;
+                order.setProductNumber(productNumber);
+            }
+            // r4_refundAmount: 退款金额
+            BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
+            if(order.getRefundMarketingAmount()!=null){
+                r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
+            }
+            // price: 当前订单退完款剩余的金额
+            BigDecimal price = order.getPrice();
+            // 判断退款金额是否小于订单余额
+            if(r4_refundAmount.compareTo(price)==-1){
+                // refundAmount: 已退款金额
+                BigDecimal refundAmount = order.getRefundAmount();
+                if(refundAmount!=null){
+                    // 如果已退款金额不为空,则加上退款金额
+                    order.setRefundAmount(refundAmount.add(r4_refundAmount));
+                }else {
+                    // 已退款金额
+                    order.setRefundAmount(r4_refundAmount);
+                }
+                // 订单设置为支付状态
+                order.setStatus(1);
+                // 改变订单的金额,原先金额减去退款金额
+                order.setPrice(price.subtract(r4_refundAmount));
+                // 重置分销
+                if(order.getAltInfo()!=null) {
+                    TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
+                    String altInfo = altInfoReset(tEquipment.getId(), price.subtract(r4_refundAmount));
+                    order.setAltInfo(altInfo);
+                }
+            }
+            // 判断退款金额是否等于订单余额
+            if(r4_refundAmount.compareTo(price)==0){
+                BigDecimal refundAmount = order.getRefundAmount();
+//                order.setAltInfo("");
+                order.setProductNumber(1);
+                if(refundAmount!=null){
+                    order.setRefundAmount(refundAmount.add(r4_refundAmount));
+                    // 全部退完款重新加回已退款的金额
+                    order.setPrice(order.getPrice().add(refundAmount));
+                }else {
+                    // 退款金额
+                    order.setRefundAmount(r4_refundAmount);
+                }
+                order.setStatus(3);
+                if(order.getAltInfo()!=null) {
+                    TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
+                    String altInfo = altInfoReset(tEquipment.getId(), order.getRefundAmount());
+                    order.setAltInfo(altInfo);
+                }
+            }
+
+            // 支付平台产生的退款流水号
+            String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
+            order.setRefundTrxNo(r5_RefundTrxNo);
+            order.setRefundDate(new Date());
+            order.setModifyDate(new Date());
+//            orderService.updateById(order);
+            String orderStatus = order.getOrderStatus();
+            if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
+                if(order.getStatus().toString().equals("3")){
+                    TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
+                    JSONObject kindData = new JSONObject();
+                    String s = order.getId().toString();
+                    if(s.length()>6){
+                        s = s.substring(s.length()-6,s.length());
+                    }
+                    kindData.put("mealCode", s);
+                    equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
+
+                }
+            }
+            try {
+                esTOrderService.updateDataById(order);
+            }catch (Exception e) {
+                e.printStackTrace();
+            }finally {
+                orderService.updateById(order);
+            }
+            return "success";
+        }
+
+        return "success";
+    }
+
+    public String altInfoReset(Long equipmentId, BigDecimal price) {
+        //获取分销  关联设备
+        TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
+
+        Integer type = proportion.getType();
+        JSONArray altInfo = new JSONArray();
+        JSONArray altNewInfo = new JSONArray();
+
+        BigDecimal adminProportion = null, agencyProportion = null, merchantProportion = null, personageProportion = null, selfProportion = null;
+        Long agencyId = proportion.getAgencyId();
+        Long merchantId = proportion.getMerchantId();
+        Long personageId = proportion.getPersonageId();
+
+        String orderType = null;
+
+
+        BigDecimal agencyAmount = null;
+        BigDecimal merchantAmount = null;
+        BigDecimal personageAmount = null;
+        BigDecimal selfAmount = null;
+
+        TJoinpayMch agencyMch = null;
+        TJoinpayMch merchantMch = null;
+        TJoinpayMch personageMch = null;
+        TJoinpayMch selfMch = null;
+
+        JSONObject agencyJson = null;
+        JSONObject merchantJson = null;
+        JSONObject personageJson = null;
+        JSONObject selfJson = null;
+
+        // 砍掉千6手续费
+//        BigDecimal cutPrice = price.multiply(new BigDecimal(99.4)).divide(new BigDecimal(100));
+        //取消平台扣手续费
+        BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
+
+        switch (type) {
+
+            case 0:
+                agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
+
+                agencyProportion = proportion.getProportion();
+                adminProportion = proportion.getAdminProportion();
+                orderType = "1";
+                // 代理分销获得利润
+                agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                agencyJson = new JSONObject();
+                agencyJson.put("altMchNo", agencyMch.getAltMchNo());
+                agencyJson.put("altAmount", agencyAmount.toString());
+                agencyJson.put("isGuar", "12");
+                altInfo.add(agencyJson);
+                break;
+            case 1:
+                agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
+
+                selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
+
+                agencyProportion = proportion.getAgencyProportion();
+                adminProportion = proportion.getAdminProportion();
+                selfProportion = proportion.getProportion();
+                orderType = "2";
+
+                BigDecimal refuseAmount = new BigDecimal(0.00);
+                if(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null){
+//                System.out.println("a等于b");
+                }else {
+                    // 一级分销获得利润
+                    agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                    agencyJson = new JSONObject();
+                    agencyJson.put("altMchNo", agencyMch.getAltMchNo());
+                    agencyJson.put("altAmount", agencyAmount.toString());
+                    agencyJson.put("isGuar", "12");
+                    altInfo.add(agencyJson);
+                }
+                // 商家自己分销获得利润
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                merchantJson = new JSONObject();
+                merchantJson.put("altMchNo", selfMch.getAltMchNo());
+                merchantJson.put("altAmount", selfAmount.toString());
+                merchantJson.put("isGuar", "12");
+                altInfo.add(merchantJson);
+
+                break;
+            case 2:
+                agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
+
+                merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
+
+                selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
+
+                agencyProportion = proportion.getAgencyProportion();
+                adminProportion = proportion.getAdminProportion();
+                merchantProportion = proportion.getMerchantProportion();
+                personageProportion = proportion.getPersonageProportion();
+                selfProportion = proportion.getProportion();
+                orderType = "3";
+                BigDecimal refuseAmount1 = new BigDecimal(0.00);
+                if(agencyProportion.compareTo(refuseAmount1) == 0||agencyProportion==null){
+//                System.out.println("a等于b");
+                }else {
+                    // 代理分销获得利润
+                    agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                    agencyJson = new JSONObject();
+                    agencyJson.put("altMchNo", agencyMch.getAltMchNo());
+                    agencyJson.put("altAmount", agencyAmount.toString());
+                    agencyJson.put("isGuar", "12");
+                    altInfo.add(agencyJson);
+
+                }
+                if(merchantProportion.compareTo(refuseAmount1) == 0||merchantProportion==null){
+//                System.out.println("a等于b");
+                }else {
+                    // 经销商分销获得利润
+                    merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                    merchantJson = new JSONObject();
+                    merchantJson.put("altMchNo", merchantMch.getAltMchNo());
+                    merchantJson.put("altAmount", merchantAmount.toString());
+                    merchantJson.put("isGuar", "12");
+                    altInfo.add(merchantJson);
+                }
+
+                // 商家自己分销获得利润
+                selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
+                merchantJson = new JSONObject();
+                merchantJson.put("altMchNo", selfMch.getAltMchNo());
+                merchantJson.put("altAmount", selfAmount.toString());
+                merchantJson.put("isGuar", "12");
+                altInfo.add(merchantJson);
+                break;
+        }
+        return altInfo.toString();
+    }
+
 }
 

+ 42 - 2
src/main/java/com/szwl/controller/WebhookController.java

@@ -5,8 +5,13 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.szwl.model.entity.TAirwallexWallet;
 import com.szwl.model.entity.TCoinOrder;
 import com.szwl.model.utils.PushUtils;
+import com.szwl.service.TAirwallexWalletService;
 import com.szwl.service.TCoinOrderService;
 import com.szwl.service.TEquipmentService;
 import lombok.extern.slf4j.Slf4j;
@@ -18,6 +23,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.Objects;
 
 import static com.szwl.common.WebhooksCommon.WEBHOOKS_KEY_PAYMENT_INTENT;
@@ -32,6 +38,9 @@ public class WebhookController {
     TCoinOrderService tCoinOrderService;
 
     @Resource
+    TAirwallexWalletService tAirwallexWalletService;
+
+    @Resource
     TEquipmentService tEquipmentService;
 //    @Resource
 //    AirwallexService airwallexService;
@@ -99,7 +108,7 @@ public class WebhookController {
                     return "订单为空/error";
                 }
                 // 设置订单支付状态为 已退款
-                tCoinOrder.setStatus("3");
+                tCoinOrder.setStatus(3);
                 tCoinOrderService.updateById(tCoinOrder);
             }
 
@@ -159,6 +168,7 @@ public class WebhookController {
 //            QueryWrapper<TOrderAbroad> tOrderAbroadQueryWrapper = new QueryWrapper<>();
 //            tOrderAbroadQueryWrapper.eq("payment_intent_id",paymentIntentId);
             String paymentIntentId = JSON.parseObject(payload).getJSONObject("data").getJSONObject("object").getString("id");
+            String currency = JSON.parseObject(payload).getJSONObject("data").getJSONObject("object").getString("currency");
 //            JSONObject jsonObj = Optional.ofNullable(jsonObject)
 //                    .flatMap(jsonObject1 -> Optional.ofNullable(jsonObject1.getJSONObject("data")))
 //                    .flatMap(jsonObject1 -> Optional.ofNullable(jsonObject1.getJSONObject("object")))
@@ -183,8 +193,38 @@ public class WebhookController {
 
             System.out.println(coinOrder);
 
-            coinOrder.setStatus("1");
+            coinOrder.setStatus(1); // 订单状态设置为已支付
             tCoinOrderService.updateById(coinOrder);
+            // 然后再去分销,给每个账户钱包加钱
+            // 先获取订单信息中的 altInfo 字段,然后拆分,获取其中每个 adminId 和对应的金额
+            String altInfo = coinOrder.getAltInfo();
+            try {
+                ObjectMapper objectMapper = new ObjectMapper();
+                JsonNode jsonNode = objectMapper.readTree(altInfo);
+                for (JsonNode node : jsonNode) {
+                    String airBeneId = node.get("airBeneId").asText();
+                    String airAmountStr = node.get("airAmount").asText();
+                    BigDecimal airAmountBigDec = new BigDecimal(airAmountStr);
+                    // 获取 airBeneId 对应的账户钱包信息
+                    LambdaQueryWrapper<TAirwallexWallet> wrapper = Wrappers.lambdaQuery();
+                    wrapper.eq(TAirwallexWallet::getAdminId, airBeneId);
+                    TAirwallexWallet airwallexWallet = tAirwallexWalletService.getOne(wrapper);
+                    BigDecimal accountAmount = airwallexWallet.getAccountAmount();
+                    String accountCurrency = airwallexWallet.getAccountCurrency();
+                    if (currency.equals(accountCurrency)) {
+                        BigDecimal added = accountAmount.add(airAmountBigDec);
+                        airwallexWallet.setAccountAmount(added);
+                        tAirwallexWalletService.saveOrUpdate(airwallexWallet);
+                    } else {
+                        // 货币种类不一致,账户钱包金额统一是美元$,如果不一致,要先获取当前汇率,然后转换成对应的美元金额
+                        return "货币种类不一致";
+                    }
+
+                }
+            } catch (JsonProcessingException e) {
+                throw new RuntimeException(e);
+            }
+
 
             // 通知做糖
             JSONObject kindData = new JSONObject();

+ 32 - 10
src/main/java/com/szwl/feign/bean/SzwlFeign.java

@@ -6,6 +6,7 @@ import com.szwl.model.entity.*;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
@@ -13,6 +14,7 @@ import java.util.Date;
 
 
 @FeignClient(name = "szwl-server")
+//@FeignClient(name = "szwl-server", url = "http://127.0.0.1:49011/")
 public interface SzwlFeign {
 
     @GetMapping("/test/testGetAdmin")
@@ -20,46 +22,66 @@ public interface SzwlFeign {
 
     @GetMapping("/tEquipment/findEquipmentByClientId")
     ResponseModel<TEquipment> findEquipmentByClientId(@RequestParam String clientId);
+
     @GetMapping("/tEquipment/updateByEquipment")
     ResponseModel<TEquipment> updateByEquipment(@RequestBody TEquipment equipment);
+
     @GetMapping("/tPromoCode/getTPromoCode")
     ResponseModel<IPage<TPromoCode>> getTPromoCode(@RequestParam String code);
+
     @GetMapping("/tPromoCode/getPromoCode")
     ResponseModel<TPromoCode> getPromoCode(@RequestParam String code);
+
     @GetMapping("/tPromoCode/selectTPromoCode")
-    ResponseModel<TPromoCode> selectTPromoCode(@RequestParam String code,@RequestParam String adminId);
+    ResponseModel<TPromoCode> selectTPromoCode(@RequestParam String code, @RequestParam String adminId);
+
     @GetMapping("/tPromoCode/getYHJ")
     ResponseModel<TPromoCode> getYHJ(@RequestParam(value = "code") String code);
+
     @GetMapping("/tPromoCode/updatePromoCode")
-    void updatePromoCode(@RequestParam(value = "id")String id, @RequestParam(value = "type")String type);
+    void updatePromoCode(@RequestParam(value = "id") String id, @RequestParam(value = "type") String type);
+
     @GetMapping("/tPromoCode/useYHJ")
-    void useYHJ(@RequestParam String code,@RequestParam String adminId,@RequestParam String clentId);
+    void useYHJ(@RequestParam String code, @RequestParam String adminId, @RequestParam String clentId);
+
     @GetMapping("/tProduct/getProduct")
-    ResponseModel<TProduct> getProduct(@RequestParam(value = "equipmentId")String equipmentId, @RequestParam(value = "productName")String productName);
+    ResponseModel<TProduct> getProduct(@RequestParam(value = "equipmentId") String equipmentId, @RequestParam(value = "productName") String productName);
+
     @GetMapping("/tProportion/getProportion")
     ResponseModel<TProportion> getProportion(@RequestParam String equipmentId);
+
     @GetMapping("/tAdmin/getAdmin")
-    ResponseModel<TAdmin>  getAdmin(@RequestParam String id);
+    ResponseModel<TAdmin> getAdmin(@RequestParam String id);
+
+    @GetMapping("/tAdmin/getAdminOne/{adminId}")
+    ResponseModel<TAdmin> getAdminOne(@PathVariable Long adminId);
+
     @GetMapping("/tJoinpayMch/getMch")
-    ResponseModel<TJoinpayMch>  getMch(@RequestParam String id);
+    ResponseModel<TJoinpayMch> getMch(@RequestParam String id);
+
     @GetMapping("/tShandeMch/getShandeMch")
-    ResponseModel<TShandeMch>  getShandeMch(@RequestParam String id);
+    ResponseModel<TShandeMch> getShandeMch(@RequestParam String id);
+
     @GetMapping("/tShandeMch/updateShandeMch")
     void updateShandeMch(@RequestBody TShandeMch shandeMch);
+
     @GetMapping("/tEquipmentDesc/findEquipmentById")
     ResponseModel<TEquipmentDesc> findEquipmentById(@RequestParam Long id);
+
     @GetMapping("/tPrice/getPrice")
-    ResponseModel<TPrice>  getPrice(@RequestParam String name);
+    ResponseModel<TPrice> getPrice(@RequestParam String name);
+
     @GetMapping("/tPromoCode/addPromoCode")
-    void addPromoCode(@RequestParam(value = "adminId")String adminId, @RequestParam(value = "lastUseDate")Date lastUseDate, @RequestParam(value = "number")int number);
+    void addPromoCode(@RequestParam(value = "adminId") String adminId, @RequestParam(value = "lastUseDate") Date lastUseDate, @RequestParam(value = "number") int number);
     //同步订单到es中
 
     /**
      * 获取汇付商户号
+     *
      * @param adminId
      * @return
      */
     @GetMapping("/tHuifuMch/getHuifuId")
     ResponseModel<THuifuMch> getHuifuId(@RequestParam Long adminId);
-    
+
 }

+ 1 - 1
src/main/java/com/szwl/mapper/TCoinOrderMapper.java

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * </p>
  *
  * @author wuhs
- * @since 2023-08-28
+ * @since 2023-08-29
  */
 public interface TCoinOrderMapper extends BaseMapper<TCoinOrder> {
 

File diff suppressed because it is too large
+ 1 - 2
src/main/java/com/szwl/mapper/xml/TCoinOrderMapper.xml


+ 2 - 2
src/main/java/com/szwl/mapper/xml/TOrderDetailsMapper.xml

@@ -15,7 +15,7 @@
         <result column="price" property="price" />
         <result column="amount" property="amount" />
         <result column="refund_quantity" property="refundQuantity" />
-        <result column="refund_amout" property="refundAmout" />
+        <result column="refund_amount" property="refundAmount" />
         <result column="refund_status" property="refundStatus" />
         <result column="company_type" property="companyType" />
         <result column="machine_type" property="machineType" />
@@ -23,7 +23,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, admin_id, equipment_id, create_date, order_sn, product_no, product_name, product_number, price, amount, refund_quantity, refund_amout, refund_status, company_type, machine_type
+        id, admin_id, equipment_id, create_date, order_sn, product_no, product_name, product_number, price, amount, refund_quantity, refund_amount, refund_status, company_type, machine_type
     </sql>
 
 </mapper>

+ 10 - 1
src/main/java/com/szwl/model/bean/PaymentIntentRequestBody.java

@@ -1,25 +1,34 @@
 package com.szwl.model.bean;
 
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Date;
 
 @Data
 public class PaymentIntentRequestBody {
 
+    private String createDate;
+
+//    private Date modifyDate;
+
     private BigDecimal amount;
 
     private String currency;
 
     private String merchantOrderId;
 
-    // 这个不用前端传递
 //    private String requestId;
 
     private Long productId;
 
     private String productName;
 
+    // 每笔订单中一共有n个商品
+    private Integer productNumber;
+
     private String clientId;
 
     private Long equipmentId;

+ 3 - 0
src/main/java/com/szwl/model/bean/RefundRequestBody.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 @Data
 public class RefundRequestBody {
@@ -17,4 +18,6 @@ public class RefundRequestBody {
     private String paymentIntentId;
 
     private String reason;
+
+    private Date refundDate;
 }

+ 2 - 2
src/main/java/com/szwl/model/bo/JsonMessage.java

@@ -135,9 +135,9 @@ public final class JsonMessage {
     public static Object optimiseObj(Object bean, String... properties) {
         Map<String, Object> map = new HashMap<>();
         if (bean == null) {
-            //TODO 前端需要null
+            // 前端需要null
             return null;
-            // TODO 前端需要空对象
+            // 前端需要空对象
 //            return map;
         }
         // 判断是否列表

+ 2 - 2
src/main/java/com/szwl/model/entity/TAirwallexMch.java

@@ -12,7 +12,7 @@ import lombok.EqualsAndHashCode;
 
 /**
  * <p>
- * 
+ * Airwallex 用户收款信息表
  * </p>
  *
  * @author wuhs
@@ -41,7 +41,7 @@ public class TAirwallexMch implements Serializable {
     @ApiModelProperty(value = "公司名称")
     private String companyName;
 
-    @ApiModelProperty(value = "实体类型")
+    @ApiModelProperty(value = "实体类型:One of PERSONAL, COMPANY")
     private String entityType;
 
     @ApiModelProperty(value = "账户币种")

+ 2 - 5
src/main/java/com/szwl/model/entity/TCoinOrder.java

@@ -16,7 +16,7 @@ import lombok.EqualsAndHashCode;
  * </p>
  *
  * @author wuhs
- * @since 2023-08-28
+ * @since 2023-08-29
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -62,7 +62,7 @@ public class TCoinOrder implements Serializable {
     private Date payDate;
 
     @ApiModelProperty(value = "支付状态,0:未支付,1:已付款,2:退款中,3:已退款,代替airwallex中的pay_status")
-    private String status;
+    private Integer status;
 
     @ApiModelProperty(value = "商品编号,eg.A06")
     private String productNo;
@@ -145,9 +145,6 @@ public class TCoinOrder implements Serializable {
     @ApiModelProperty(value = "airwallex交易编号")
     private String paymentIntentId;
 
-    @ApiModelProperty(value = "商品数量,每笔订单中有几个商品")
-    private Integer productNum;
-
     @ApiModelProperty(value = "公司平台,0或空为申泽,1为七云")
     private String companyType;
 

+ 1 - 1
src/main/java/com/szwl/model/entity/TOrderDetails.java

@@ -60,7 +60,7 @@ public class TOrderDetails implements Serializable {
     private Integer refundQuantity;
 
     @ApiModelProperty(value = "退款金额")
-    private BigDecimal refundAmout;
+    private BigDecimal refundAmount;
 
     @ApiModelProperty(value = "退款状态,0:未支付,1:已支付,2:部分退款,3:全部退款,4:退款中")
     private String refundStatus;

+ 10 - 1
src/main/java/com/szwl/service/AirwallexService.java

@@ -1,5 +1,6 @@
 package com.szwl.service;
 
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.szwl.model.bo.R;
 import com.szwl.model.dto.BeneficiaryDTO;
 import com.szwl.model.dto.CaPaymentRequestDTO;
@@ -53,7 +54,7 @@ public interface AirwallexService  {
      * @param merchantOrderId
      * @return
      */
-    Map<String, Object> caPaymentIntent(BigDecimal amount, String currency, String requestId, String merchantOrderId);
+    Map<String, Object> caPaymentIntent(BigDecimal amount, String currency, String requestId, String merchantOrderId, ObjectNode order);
 
     /**
      * 创建一笔退款 Create a Refund
@@ -115,4 +116,12 @@ public interface AirwallexService  {
 //    void caWebhook(String[] envents, String requiredId, String url, String version);
 
 
+    /**
+     * 获取实时汇率
+     * @param buyCurrency
+     * @param sellCurrency
+     * @param buyAmount
+     * @return
+     */
+    Map<String, Object> getMarketFX(String buyCurrency, String sellCurrency, BigDecimal buyAmount);
 }

+ 7 - 0
src/main/java/com/szwl/service/TAirwallexMchService.java

@@ -1,5 +1,6 @@
 package com.szwl.service;
 
+import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.entity.TAirwallexMch;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -13,4 +14,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TAirwallexMchService extends IService<TAirwallexMch> {
 
+    /**
+     * 获取提现账户信息
+     * @param adminId
+     * @return
+     */
+    TAirwallexMch getAirMch(Long adminId);
 }

+ 7 - 0
src/main/java/com/szwl/service/TAirwallexWalletService.java

@@ -3,6 +3,7 @@ package com.szwl.service;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.szwl.model.entity.TAirwallexMch;
 import com.szwl.model.entity.TAirwallexWallet;
 import com.baomidou.mybatisplus.extension.service.IService;
 import io.swagger.annotations.ApiOperation;
@@ -21,4 +22,10 @@ import java.math.BigDecimal;
  */
 public interface TAirwallexWalletService extends IService<TAirwallexWallet> {
 
+    /**
+     * 获取 Air 钱包明细
+     * @param id
+     * @return
+     */
+    TAirwallexWallet getAirWallet(Long id);
 }

+ 5 - 1
src/main/java/com/szwl/service/TCoinOrderService.java

@@ -9,8 +9,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * </p>
  *
  * @author wuhs
- * @since 2023-08-28
+ * @since 2023-08-29
  */
 public interface TCoinOrderService extends IService<TCoinOrder> {
 
+    /**
+     * 生成订单号
+     */
+    String initSn(Long equipmentId);
 }

+ 9 - 2
src/main/java/com/szwl/service/THuifuMchService.java

@@ -28,9 +28,14 @@ public interface THuifuMchService extends IService<THuifuMch> {
      * @param openId 微信openId
      * @param appid 微信appId
      * @param acctSplitBunch 分账明细
+     * @param companyType 公司平台
      * @return
+     * @throws Exception
      */
-    String uniPay(String orderNo, BigDecimal amount, String productName, String productDesc, String notifyUrl, String frpCode, String openId, String appid, JSONObject acctSplitBunch) throws Exception;
+    String uniPay(String orderNo, BigDecimal amount, String productName,
+                  String productDesc, String notifyUrl, String frpCode,
+                  String openId, String appid, JSONObject acctSplitBunch,
+                  String companyType) throws Exception;
 
     /**
      * 汇付微信聚合正扫
@@ -49,5 +54,7 @@ public interface THuifuMchService extends IService<THuifuMch> {
      * @param acctSplitBunch
      * @return
      */
-    String cardPay(String orderNo, BigDecimal amount, String productName, String notifyUrl, String authCode, JSONObject acctSplitBunch) throws Exception;
+    String cardPay(String orderNo, BigDecimal amount, String productName,
+                   String notifyUrl, String authCode, JSONObject acctSplitBunch,
+                   String companyType) throws Exception;
 }

+ 58 - 5
src/main/java/com/szwl/service/impl/AirwallexServiceImpl.java

@@ -1,6 +1,10 @@
 package com.szwl.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.szwl.common.AccessTokenCommon;
 import com.szwl.constant.AirwallexConstant;
 import com.szwl.controller.TAreaController;
@@ -74,7 +78,7 @@ public class AirwallexServiceImpl implements AirwallexService {
      * @return
      */
     @Override
-    public Map<String, Object> caPaymentIntent(BigDecimal amount, String currency, String requestId, String merchantOrderId) {
+    public Map<String, Object> caPaymentIntent(BigDecimal amount, String currency, String requestId, String merchantOrderId, ObjectNode order) {
         String accessToken = AccessTokenCommon.ACCESS_TOKEN;
 
         if(accessToken == null || "".equals(accessToken)) {
@@ -87,12 +91,26 @@ public class AirwallexServiceImpl implements AirwallexService {
 //        new BasicHeader("Authorization", AirwallexConstant.BEARER + this.getAccessToken());
         BasicHeader header1 = new BasicHeader("Authorization",AirwallexConstant.BEARER + accessToken);
         headers.add(header1);
+
+        ArrayNode productList = (ArrayNode) order.get("products");
+        List<Map<String,Object>> productMapList = new ArrayList<>();
+        for (JsonNode product : productList) {
+            Map<String, Object> productMap = new HashMap<>();
+            productMap.put("desc", product.get("desc").textValue());
+            productMap.put("quantity", product.get("quantity").intValue());
+            productMapList.add(productMap);
+        }
+        ObjectNode orderNode = new ObjectMapper().createObjectNode();
+        orderNode.set("products", productList);
+
         // body参数
         Map<String, Object> bodyMap = new HashMap<>();
         bodyMap.put("amount", amount);
         bodyMap.put("currency", currency);
         bodyMap.put("request_id", requestId);
         bodyMap.put("merchant_order_id", merchantOrderId);
+        bodyMap.put("order", orderNode);
+
 
         String data = JSON.toJSONString(bodyMap);
         log.info("请求body参数:" +data);
@@ -384,10 +402,45 @@ public class AirwallexServiceImpl implements AirwallexService {
     }
 
 
-//    @Override
-//    public String refundWebhooks(HttpServletRequest request, HttpServletResponse response) {
-//        return null;
-//    }
+    /**
+     * 获取实时汇率
+     * @param buyCurrency
+     * @param sellCurrency
+     * @param buyAmount
+     * @return
+     */
+    @Override
+    public Map<String, Object> getMarketFX(String buyCurrency, String sellCurrency, BigDecimal buyAmount) {
+
+        // GET /api/v1/marketfx/quote
+        String accessToken = AccessTokenCommon.ACCESS_TOKEN;
+
+        if(accessToken == null || "".equals(accessToken)) {
+            accessToken = AccessTokenThreadUtil.getAccessToken();
+        }
+
+        String url = AirwallexConstant.url + "/api/v1/marketfx/quote?buy_amount=" + buyAmount + "&buy_currency=" + buyCurrency + "&sell_currency=" + sellCurrency;
+        // 请求头
+        List<BasicHeader> headers = new ArrayList<>();
+        BasicHeader header = new BasicHeader("Authorization", AirwallexConstant.BEARER + accessToken);
+        headers.add(header);
+
+        // body参数
+//        Map<String, Object> bodyMap = new HashMap<>();
+//        String data = JSON.toJSONString(bodyMap);
+
+        Map<String, Object> responseMap = new HashMap<>();
+        String resp = null;
+        try {
+            resp = HttpClientSslUtils.doGet(url, ContentType.APPLICATION_JSON, headers);
+            responseMap = JSON.parseObject(resp);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return responseMap;
+    }
+
 
 
     /**

+ 50 - 1
src/main/java/com/szwl/service/impl/TAirwallexMchServiceImpl.java

@@ -1,14 +1,23 @@
 package com.szwl.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.szwl.feign.bean.SzwlFeign;
+import com.szwl.model.bo.R;
+import com.szwl.model.entity.TAdmin;
 import com.szwl.model.entity.TAirwallexMch;
 import com.szwl.mapper.TAirwallexMchMapper;
 import com.szwl.service.TAirwallexMchService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.szwl.utils.AirwallexWalletException;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.List;
+
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author wuhs
@@ -17,4 +26,44 @@ import org.springframework.stereotype.Service;
 @Service
 public class TAirwallexMchServiceImpl extends ServiceImpl<TAirwallexMchMapper, TAirwallexMch> implements TAirwallexMchService {
 
+    @Resource
+    TAirwallexMchService airwallexMchService;
+    @Resource
+    SzwlFeign szwlFeign;
+
+    @Override
+    public TAirwallexMch getAirMch(Long adminId) {
+
+        String adminIdStr = String.valueOf(adminId);
+        // 根据 adminId 获取admin信息
+        TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(adminIdStr));
+
+        if (!admin.getIsAdmined()) {
+            if (admin.getType() <= 1) { // 公司人员
+                TAirwallexMch airwallexMch = new TAirwallexMch();
+                airwallexMch.setEntityType("PERSONAL"); // 商户类型,“PERSONAL”为个人,“COMPANY”为企业
+                return airwallexMch;
+            } else { // 商家
+//                TAdmin parentAdmin = adminService.getById();
+                TAdmin parentAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
+                LambdaQueryWrapper<TAirwallexMch> wrapper = Wrappers.lambdaQuery();
+                wrapper.eq(TAirwallexMch::getAdminId, Long.valueOf(parentAdmin.getId()));
+
+                List<TAirwallexMch> list = airwallexMchService.list(wrapper);
+                TAirwallexMch airwallexMch = list.get(0);
+                // 刷新
+//                TAirwallexMch tAirwallexMch = airwallexMchService.getById(airwallexMch.getId());
+                return airwallexMch;
+            }
+        } else {
+            LambdaQueryWrapper<TAirwallexMch> wrapper = Wrappers.lambdaQuery();
+            wrapper.eq(TAirwallexMch::getAdminId, Long.valueOf(adminId));
+            TAirwallexMch airwallexMch = airwallexMchService.getOne(wrapper);
+
+            if (airwallexMch == null) {
+                throw new AirwallexWalletException("未注册提现号");
+            }
+            return airwallexMch;
+        }
+    }
 }

+ 54 - 0
src/main/java/com/szwl/service/impl/TAirwallexWalletServiceImpl.java

@@ -1,11 +1,21 @@
 package com.szwl.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.szwl.feign.bean.SzwlFeign;
+import com.szwl.model.bo.R;
+import com.szwl.model.bo.ResponseModel;
+import com.szwl.model.entity.TAdmin;
 import com.szwl.model.entity.TAirwallexWallet;
 import com.szwl.mapper.TAirwallexWalletMapper;
 import com.szwl.service.TAirwallexWalletService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.szwl.utils.AirwallexWalletException;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +27,48 @@ import org.springframework.stereotype.Service;
 @Service
 public class TAirwallexWalletServiceImpl extends ServiceImpl<TAirwallexWalletMapper, TAirwallexWallet> implements TAirwallexWalletService {
 
+    @Resource
+    TAirwallexWalletService airwallexWalletService;
+    @Resource
+    SzwlFeign szwlFeign;
+
+    @Override
+    public TAirwallexWallet getAirWallet(Long id) {
+
+        // 根据 adminId 获取admin信息
+        TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdminOne(id));
+//        String adminId = String.valueOf(id);
+//        TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(adminId));
+        System.out.println("打印tAdmin" + admin);
+
+        if (!admin.getIsAdmined()) {
+            if (admin.getType() <= 1) { // 公司人员
+                TAirwallexWallet airwallexWallet = new TAirwallexWallet();
+//                airwallexWallet.setEntityType("PERSONAL"); // 商户类型,“PERSONAL”为个人,“COMPANY”为企业
+                return airwallexWallet;
+            } else { // 商家
+//                TAdmin parentAdmin = adminService.getById();
+                TAdmin parentAdmin = R.getDataIfSuccess(szwlFeign.getAdminOne(admin.getParentId()));
+//                String parentId = String.valueOf(admin.getParentId());
+//                TAdmin parentAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(parentId));
+                LambdaQueryWrapper<TAirwallexWallet> wrapper = Wrappers.lambdaQuery();
+                wrapper.eq(TAirwallexWallet::getAdminId, parentAdmin.getId());
+
+                List<TAirwallexWallet> list = airwallexWalletService.list(wrapper);
+                TAirwallexWallet airwallexWallet = list.get(0);
+                // 刷新
+//                TAirwallexWallet walletById = airwallexWalletService.getById(airwallexWallet.getAdminId());
+                return airwallexWallet;
+            }
+        } else {
+            LambdaQueryWrapper<TAirwallexWallet> wrapper = Wrappers.lambdaQuery();
+            wrapper.eq(TAirwallexWallet::getAdminId, id);
+            TAirwallexWallet airwallexWallet = airwallexWalletService.getOne(wrapper);
+
+            if (airwallexWallet == null) {
+                throw new AirwallexWalletException("未注册提现号");
+            }
+            return airwallexWallet;
+        }
+    }
 }

+ 27 - 1
src/main/java/com/szwl/service/impl/TCoinOrderServiceImpl.java

@@ -6,15 +6,41 @@ import com.szwl.service.TCoinOrderService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Random;
+
 /**
  * <p>
  *  服务实现类
  * </p>
  *
  * @author wuhs
- * @since 2023-08-28
+ * @since 2023-08-29
  */
 @Service
 public class TCoinOrderServiceImpl extends ServiceImpl<TCoinOrderMapper, TCoinOrder> implements TCoinOrderService {
 
+    @Override
+    public String initSn(Long equipmentId) {
+        StringBuilder number = new StringBuilder();
+        if (equipmentId != null) {
+            Random random = new Random();
+            /**
+             * 6位随机
+             */
+            for (int i = 0; i < 6; i++) {
+                number.append(String.valueOf(random.nextInt(10)));
+            }
+            /**
+             * 设备id
+             */
+            number.append(equipmentId.toString());
+            /**
+             * 日期
+             */
+            number.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
+        }
+        return number.toString();
+    }
 }

+ 45 - 14
src/main/java/com/szwl/service/impl/THuifuMchServiceImpl.java

@@ -1,6 +1,7 @@
 package com.szwl.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.huifu.bspay.sdk.opps.core.utils.DateTools;
@@ -57,13 +58,20 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
     SzwlFeign szwlFeign;
 
     @Override
-    public String uniPay(String orderNo, BigDecimal amount, String productName, String productDesc, String notifyUrl, String frpCode, String openId, String appid, JSONObject acctSplitBunch) throws Exception {
+    public String uniPay(String orderNo, BigDecimal amount, String productName,
+                         String productDesc, String notifyUrl, String frpCode,
+                         String openId, String appid, JSONObject acctSplitBunch,
+                         String companyType) throws Exception {
         String url = "https://api.huifu.com/v2/trade/payment/jspay";
         HuifuBaseCommon.doInit(OppsMerchantConfig.getMerchantConfig());
         JSONObject request = new JSONObject();
         request.put("req_seq_id", orderNo);
         request.put("req_date", DateTools.getCurrentDateYYYYMMDD());
-        request.put("huifu_id", HuifuConstant.DIV_HUIFU_ID);
+        if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+            request.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
+        } else {
+            request.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
+        }
         if(frpCode.equals("ALIPAY_NATIVE")) {
             request.put("trade_type", "A_NATIVE");
         }
@@ -112,7 +120,12 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
         String sn = HuifuUtils.initReqSeqId();
         request.put("req_seq_id", sn);
         request.put("req_date", DateTools.getCurrentDateYYYYMMDD());
-        request.put("huifu_id", HuifuConstant.DIV_HUIFU_ID);
+        String companyType = huifuTempOrder.getCompanyType();
+        if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+            request.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
+        } else {
+            request.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
+        }
         request.put("trade_type", "T_JSAPI");
         request.put("trans_amt", huifuTempOrder.getPrice());
         String clientId = huifuTempOrder.getClientId();
@@ -130,14 +143,17 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
             productName1 = productName + "-" + equipment.getName() + "-" + client6;
         }
         request.put("goods_desc", productName1);
-//        request.put("goods_desc", huifuTempOrder.getProductName());
         request.put("notify_url", HuifuConstant.Notify_Url);
         request.put("remark", huifuTempOrder.getId());
         // 分账明细
         request.put("acct_split_bunch", huifuTempOrder.getAcctSplitBunch());
         // 微信支付配置
         JSONObject wxData = new JSONObject();
-        wxData.put("sub_appid",HuifuConstant.WX_SUB_APP_ID);
+        if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+            wxData.put("sub_appid",HuifuConstant.SC_WX_SUB_APP_ID);
+        } else {
+            wxData.put("sub_appid",HuifuConstant.SZ_WX_SUB_APP_ID);
+        }
         wxData.put("open_id",openid);
         request.put("wx_data", wxData);
         // 签名:sign
@@ -167,12 +183,22 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
         // 获取paySign的值
         String paySign = payInfoJson.getString("paySign");
         // 测试链接:http://szwltest.sunzee.com.cn/shenze
-        String resultUrl = HuifuConstant.JUMP_URL+"/#/popPayment?" +
-                "sn=" + sn +
-                "&timeStamp=" + timeStamp +
-                "&nonceStr=" + nonceStr +
-                "&package=" + packageValue +
-                "&paySign=" + paySign;
+        String resultUrl = "";
+        if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+            resultUrl = HuifuConstant.SC_JUMP_URL+"/#/popPayment?" +
+                    "sn=" + sn +
+                    "&timeStamp=" + timeStamp +
+                    "&nonceStr=" + nonceStr +
+                    "&package=" + packageValue +
+                    "&paySign=" + paySign;
+        } else {
+            resultUrl = HuifuConstant.SZ_JUMP_URL+"/#/popPayment?" +
+                    "sn=" + sn +
+                    "&timeStamp=" + timeStamp +
+                    "&nonceStr=" + nonceStr +
+                    "&package=" + packageValue +
+                    "&paySign=" + paySign;
+        }
         log.info("微信支付链接:{}", resultUrl);
         // 保存订单到数据库
         TOrder tOrder = new TOrder();
@@ -232,14 +258,19 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
     }
 
     @Override
-    public String cardPay(String orderNo, BigDecimal amount, String productName, String notifyUrl, String authCode, JSONObject acctSplitBunch) throws Exception {
+    public String cardPay(String orderNo, BigDecimal amount, String productName,
+                          String notifyUrl, String authCode, JSONObject acctSplitBunch,
+                          String companyType) throws Exception {
         String url = "https://api.huifu.com/v2/trade/payment/micropay";
         HuifuBaseCommon.doInit(OppsMerchantConfig.getMerchantConfig());
         JSONObject request = new JSONObject();
-//        String sn = HuifuUtils.initReqSeqId();
         request.put("req_seq_id", orderNo);
         request.put("req_date", DateTools.getCurrentDateYYYYMMDD());
-        request.put("huifu_id", HuifuConstant.DIV_HUIFU_ID);
+        if(StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+            request.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
+        } else {
+            request.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
+        }
         request.put("auth_code", authCode);
         request.put("trans_amt", amount);
         request.put("goods_desc", productName);

+ 0 - 1
src/main/java/com/szwl/service/impl/TWeixinPayConfigServiceImpl.java

@@ -99,7 +99,6 @@ public class TWeixinPayConfigServiceImpl extends ServiceImpl<TWeixinPayConfigMap
         String nonce = resourceMap.get("nonce");
         // 附加数据
         String associatedData = resourceMap.get("associated_data");
-        //todo
         List<TWeixinPayConfig> list = list();
         AesUtil aesUtil = new
                 AesUtil(list.get(0).getApiV3key().getBytes(StandardCharsets.UTF_8));

+ 8 - 0
src/main/java/com/szwl/utils/AirwallexWalletException.java

@@ -0,0 +1,8 @@
+package com.szwl.utils;
+
+public class AirwallexWalletException extends RuntimeException{
+
+    public AirwallexWalletException(String msg) {
+        super(msg);
+    }
+}

+ 4 - 4
src/test/java/com/szwl/AutoGeneratorTests.java

@@ -35,18 +35,18 @@ class AutoGeneratorTests {
 				.setBaseColumnList(true)//设置基本的列
 				.setControllerName("%sController");
 
-		//配置数据源
-		//TODO:配置数据源
+		// 配置数据源
 		DataSourceConfig dataSourceConfig = new DataSourceConfig();
 		dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver")
+				// TODO: 数据库名称
 				.setUrl("jdbc:mysql://rm-wz995mu26a1479kz0so.mysql.rds.aliyuncs.com:3306/orderdb-test")
 				.setUsername("root").setPassword("sunzee@020");
 
-		//策略配置
-		//TODO:配置表名
+		// 策略配置
 		StrategyConfig strategyConfig = new StrategyConfig();
 		strategyConfig
 //				.setCapitalMode(true)//设置全局大写命名
+				// TODO: 表名
 				.setInclude(new String[]{
 						"t_coin_order"
 				})//只会生成该表