Browse Source

商户入驻

kongge 1 week ago
parent
commit
74bc794c0c
14 changed files with 142 additions and 33 deletions
  1. 2 2
      vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/AssetClient.java
  2. 8 1
      vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/MerchantClient.java
  3. 9 1
      vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/constant/TradeConstant.java
  4. 4 4
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/controller/AssetController.java
  5. 11 2
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/controller/MerchantController.java
  6. 1 1
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/entity/MerchantApplyRecord.java
  7. 2 2
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/AssetService.java
  8. 3 1
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantApplyRecordService.java
  9. 8 0
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantRelationService.java
  10. 3 1
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantService.java
  11. 16 12
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/AssetServiceImpl.java
  12. 56 4
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantApplyRecordServiceImpl.java
  13. 12 0
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantRelationServiceImpl.java
  14. 7 2
      vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantServiceImpl.java

+ 2 - 2
vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/AssetClient.java

@@ -17,10 +17,10 @@ public interface AssetClient {
     void withdrawApply(@RequestBody WithdrawParam param);
 
     @PostMapping(value = "/asset/withdraw/notify")
-    void withdrawNotify(@RequestBody SxyNotifyParam param);
+    String withdrawNotify(@RequestBody SxyNotifyParam param);
 
     @PostMapping(value = "/asset/transfer/notify")
-    void transferNotify(@RequestBody SxyNotifyParam param);
+    String transferNotify(@RequestBody SxyNotifyParam param);
 
     /**
      * 手动转账接口

+ 8 - 1
vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/MerchantClient.java

@@ -231,7 +231,14 @@ public interface MerchantClient {
      *
      */
     @PostMapping("/merchant/apply/notify")
-    void merchantApplyNotify(@RequestBody SxyNotifyParam param);
+    String merchantApplyNotify(@RequestBody SxyNotifyParam param);
+
+    /**
+     * 电子签回调接口
+     *
+     */
+    @PostMapping("/merchant/reSign/notify")
+    String merchantReSignNotify(@RequestParam("frequency") Integer frequency, @RequestBody SxyNotifyParam param);
 }
 
 

+ 9 - 1
vehicle-client/src/main/java/com/chelvc/cloud/vehicle/client/constant/TradeConstant.java

@@ -40,6 +40,11 @@ public interface TradeConstant {
      */
     static final String MERCHANT_NET_IN_NOTIFY_URL = "/maintain/merchant/apply/notify";
 
+    /**
+     * 商户入网电子签重签回调地址
+     */
+    static final String MERCHANT_RE_SIGN_NOTIFY_URL = "/maintain/merchant/reSign/notify?frequency=";
+
     /**
      * 被分账方入网
      */
@@ -75,5 +80,8 @@ public interface TradeConstant {
      * (非直连)
      */
     static final String MINIAPPS_WEIXIN_PAY = "";
-
+    /**
+     * 电子签重签请求地址
+     */
+    static final String RE_SIGN_URL = "https://apis.5upay.com/serviceprovider/declaration/electronicReSign";
 }

+ 4 - 4
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/controller/AssetController.java

@@ -37,8 +37,8 @@ public class AssetController {
      * @param param
      */
     @PostMapping("/asset/withdraw/notify")
-    public void withdrawNotify(@RequestBody SxyNotifyParam param) {
-        this.assetService.withdrawNotify(param);
+    public String withdrawNotify(@RequestBody SxyNotifyParam param) {
+        return this.assetService.withdrawNotify(param);
     }
 
     /**
@@ -46,8 +46,8 @@ public class AssetController {
      *
      */
     @PostMapping("/asset/transfer/notify")
-    public void transferNotify(@RequestBody SxyNotifyParam param) {
-        this.assetService.transferNotify(param);
+    public String transferNotify(@RequestBody SxyNotifyParam param) {
+        return this.assetService.transferNotify(param);
     }
 
     /**

+ 11 - 2
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/controller/MerchantController.java

@@ -285,8 +285,17 @@ public class MerchantController {
      *
      */
     @PostMapping("/merchant/apply/notify")
-    public void merchantApplyNotify(@RequestBody SxyNotifyParam param) {
-        merchantService.merchantApplyNotify(param);
+    public String merchantApplyNotify(@RequestBody SxyNotifyParam param) {
+        return merchantService.merchantApplyNotify(param);
+    }
+
+    /**
+     * 电子签回调接口
+     *
+     */
+    @PostMapping("/merchant/reSign/notify")
+    public String merchantReSignNotify(@RequestParam("frequency") Integer frequency, @RequestBody SxyNotifyParam param) {
+        return merchantService.merchantReSignNotify(frequency, param);
     }
 }
 

+ 1 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/entity/MerchantApplyRecord.java

@@ -37,7 +37,7 @@ public class MerchantApplyRecord implements Entity<Long> {
     private Integer type;
 
     /**
-     * 申请状态:0-申请中;1-成功;2-失败
+     * 申请状态:1-审核中;2-入网完成;3-审核通过;4-审核不通过;5-审核拒绝;6-待签约;7-签约中;8-签约失败;9-签约成功;
      */
     private Integer status;
 

+ 2 - 2
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/AssetService.java

@@ -34,9 +34,9 @@ public interface AssetService {
     MerchantAssetDTO getMerchantAsset(Long merchantId);
 
 
-    void withdrawNotify(SxyNotifyParam param);
+    String withdrawNotify(SxyNotifyParam param);
 
-    void transferNotify(SxyNotifyParam param);
+    String transferNotify(SxyNotifyParam param);
     void withdraw(Long userId, Integer type, BigDecimal amount);
 
     void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount, String remark);

+ 3 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantApplyRecordService.java

@@ -8,5 +8,7 @@ public interface MerchantApplyRecordService {
 
     int insert(MerchantApplyRecord record);
 
-    void updateSxyMerchantIdByNotify(SxyNotifyParam param);
+    String updateSxyMerchantIdByNotify(SxyNotifyParam param);
+
+    String updateStatusByReSignNotify(Integer frequency, SxyNotifyParam param);
 }

+ 8 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantRelationService.java

@@ -20,4 +20,12 @@ public interface MerchantRelationService {
     void registerMerchantId(UserAuth userAuth);
 
     int insert(Long userId, Integer type, String sxyMerchantId);
+
+    /**
+     * 电子签重签
+     * @param requestId
+     * @param subMerchantId
+     * @param frequency
+     */
+    void reSign(String requestId, String subMerchantId, int frequency);
 }

+ 3 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantService.java

@@ -236,7 +236,9 @@ public interface MerchantService extends IService<Merchant> {
 
     MerchantDTO queryCheck(Long merchantId, Long userId);
 
-    void merchantApplyNotify(SxyNotifyParam param);
+    String merchantApplyNotify(SxyNotifyParam param);
 
     Merchant queryByApplicant(Long applicant);
+
+    String merchantReSignNotify(Integer frequency, SxyNotifyParam param);
 }

+ 16 - 12
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/AssetServiceImpl.java

@@ -322,27 +322,28 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
     }
 
     @Override
-    public void withdrawNotify(SxyNotifyParam param) {
+    public String withdrawNotify(SxyNotifyParam param) {
+        String statusStr = "FAIL";
         JSONObject responseData = TradeHandle.decrypt(param);
         if(responseData == null){
-            return;
+            return statusStr;
         }
         log.info("提现回调参数:{}", responseData);
         String requestId = responseData.getString("requestId");
         Long id = Long.parseLong(requestId);
         OmsTransferWithdraw withdraw = transferWithdrawService.queryById(id);
         if(withdraw == null){
-            return;
+            return statusStr;
         }
         final Integer[] transferStatus = {withdraw.getStatus()};
         if(transferStatus[0] != 0){
-            return;
+            return "success";
         }
         String withdrawAmount = responseData.getString("withdrawAmount");
         BigDecimal amount = withdraw.getAmount();
         if(amount.multiply(new BigDecimal("100")).compareTo(new BigDecimal(withdrawAmount)) != 0){
             //金额不一致
-            return;
+            return statusStr;
         }
         String withdrawStatus = responseData.getString("withdrawStatus");
         final BigDecimal[] procedureAmount = {BigDecimal.ZERO};
@@ -355,7 +356,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
         } else if("FAIL".equals(withdrawStatus)){
             transferStatus[0] = 2;
         } else {
-            return;
+            return statusStr;
         }
         String errorMessage = responseData.getString("errorMessage");
         DatabaseContextHolder.transactional((Executor) () -> {
@@ -374,6 +375,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
                 }
             }
         });
+        return "success";
     }
 
     @Override
@@ -382,27 +384,28 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
     }
 
     @Override
-    public void transferNotify(SxyNotifyParam param) {
+    public String transferNotify(SxyNotifyParam param) {
+        String statusStr = "FAIL";
         JSONObject responseData = TradeHandle.decrypt(param);
         log.info("转账回调参数:{}", responseData);
         if(responseData == null){
-            return;
+            return statusStr;
         }
         String requestId = responseData.getString("requestId");
         Long id = Long.parseLong(requestId);
         OmsTransferWithdraw transfer = transferWithdrawService.queryById(id);
         if(transfer == null){
-            return;
+            return statusStr;
         }
         final Integer[] transferStatus = {transfer.getStatus()};
         if(transferStatus[0] != 0){
-            return;
+            return "success";
         }
         String transferAmount = responseData.getString("amount");
         BigDecimal amount = transfer.getAmount();
         if(amount.multiply(new BigDecimal("100")).compareTo(new BigDecimal(transferAmount)) != 0){
             //金额不一致
-            return;
+            return statusStr;
         }
         String transferResultStatus = responseData.getString("status");
         if("SUCCESS".equals(transferResultStatus)){
@@ -412,7 +415,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
         } else if("FAILED".equals(transferResultStatus)){
             transferStatus[0] = 2;
         } else {
-            return;
+            return statusStr;
         }
         String errorMessage = responseData.getString("errorMessage");
         DatabaseContextHolder.transactional((Executor) () -> {
@@ -444,5 +447,6 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
                 }
             }
         });
+        return "success";
     }
 }

+ 56 - 4
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantApplyRecordServiceImpl.java

@@ -38,21 +38,21 @@ public class MerchantApplyRecordServiceImpl extends
     }
 
     @Override
-    public void updateSxyMerchantIdByNotify(SxyNotifyParam param) {
+    public String updateSxyMerchantIdByNotify(SxyNotifyParam param) {
         JSONObject responseData = TradeHandle.decrypt(param);
         log.info("申请商户号回调参数:{}", responseData);
         String status = responseData.getString("subMerchantReviewStatus");
         if (Constants.ERROR.equals(status)) {
             //解密后报文,如果status=ERROR时,不需要验签
-            return;
+            return status;
         }
         String requestId = responseData.getString("requestId");
         LambdaQueryWrapper<MerchantApplyRecord> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(MerchantApplyRecord::getRequestId, requestId);
         MerchantApplyRecord record = baseMapper.selectOne(wrapper);
         Integer recordStatus = record.getStatus();
-        if(recordStatus != 0){
-            return;
+        if(MerchantApplyStatus.SUCCESS.getStatus().equals(recordStatus)){
+            return MerchantApplyStatus.SUCCESS.getType();
         }
         String subMerchantId = responseData.getString("subMerchantId");
         Integer type = record.getType();
@@ -86,5 +86,57 @@ public class MerchantApplyRecordServiceImpl extends
                 }
             }
         });
+        //判断状态是否是通过 通过调用电子签重签
+        if("PASS".equals(status)){
+            merchantRelationService.reSign(requestId, subMerchantId, 5);
+        }
+        return status;
+    }
+
+    @Override
+    public String updateStatusByReSignNotify(Integer frequency, SxyNotifyParam param) {
+        if(frequency == null || frequency > 5 || frequency < 1){
+            return "success";
+        }
+        JSONObject responseData = TradeHandle.decrypt(param);
+        log.info("电子签重签回调参数:{}", responseData);
+        String status = responseData.getString("status");
+        String subMerchantId = responseData.getString("subMerchantId");
+        String requestId = responseData.getString("requestId");
+        if (!Constants.SUCCESS.equals(status)) {
+            merchantRelationService.reSign(requestId, subMerchantId, --frequency);
+            return status;
+        }
+        LambdaQueryWrapper<MerchantApplyRecord> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(MerchantApplyRecord::getRequestId, requestId);
+        MerchantApplyRecord record = baseMapper.selectOne(wrapper);
+        if(record == null){
+            return "FAIL";
+        }
+        Integer type = record.getType();
+        Integer resultStatus = MerchantApplyStatus.getStatus(status);
+        record.setStatus(resultStatus);
+        record.setExamineStatus(status);
+        String errorMessage = responseData.getString("errorMessage");
+        DatabaseContextHolder.transactional((Executor) () -> {
+            baseMapper.updateById(record);
+            if(type == 1){
+                //更改个人认证状态
+                userAuthService.updateStatus(record.getUserId(), resultStatus, errorMessage);
+            }
+            if(type == 2){
+                //更改商家认证状态
+                merchantAuthService.updateStatus(record.getUserId(), resultStatus, errorMessage);
+            }
+            if("SUCCESS".equals(status)){
+                int i = merchantRelationService.insert(record.getUserId(), record.getType(), subMerchantId);
+                if(i == 1 && record.getType() == 1){
+                    //用户申请商户号成功,平台转账给用户
+                    BigDecimal total = assetService.queryTotal(record.getUserId(), 1);
+                    assetService.transfer(0L, record.getUserId(), 1, total, "0");
+                }
+            }
+        });
+        return status;
     }
 }

+ 12 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantRelationServiceImpl.java

@@ -273,4 +273,16 @@ public class MerchantRelationServiceImpl extends ServiceImpl<MerchantRelationMap
         relation.setSxyMerchantId(sxyMerchantId);
         return baseMapper.insert(relation);
     }
+
+    @Override
+    public void reSign(String requestId, String subMerchantId, int frequency) {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("requestId", requestId);
+        jsonObject.put("subMerchantId", subMerchantId);
+        jsonObject.put("eSignNotifyUrl", NOTIFY_DOMAIN + TradeConstant.MERCHANT_RE_SIGN_NOTIFY_URL + frequency);
+        jsonObject.put("merchantId", TradeConstant.PARTNER_ID);
+        JSONObject json = TradeHandle.handle(String.valueOf(jsonObject), TradeConstant.RE_SIGN_URL,
+                TradeConstant.PARTNER_ID, null);
+        log.info("子商户【{}】电子签重签返回信息:{}", subMerchantId, json);
+    }
 }

+ 7 - 2
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantServiceImpl.java

@@ -581,8 +581,8 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
     }
 
     @Override
-    public void merchantApplyNotify(SxyNotifyParam param) {
-        merchantApplyRecordService.updateSxyMerchantIdByNotify(param);
+    public String merchantApplyNotify(SxyNotifyParam param) {
+        return merchantApplyRecordService.updateSxyMerchantIdByNotify(param);
     }
 
     @Override
@@ -592,4 +592,9 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
                 .one();
     }
 
+    @Override
+    public String merchantReSignNotify(Integer frequency, SxyNotifyParam param) {
+        return merchantApplyRecordService.updateStatusByReSignNotify(frequency, param);
+    }
+
 }