From f604f87781d7cdae5571465a3bafffff53313028 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 02 六月 2023 08:34:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/1.1' into 1.1

---
 management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 113 insertions(+), 4 deletions(-)

diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java
index 5e692d4..c2d7aba 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TAgentController.java
@@ -1,6 +1,8 @@
 package com.stylefeng.guns.modular.system.controller.general;
 
 import cn.hutool.crypto.SecureUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.stylefeng.guns.core.base.controller.BaseController;
 import com.stylefeng.guns.core.base.tips.SuccessTip;
@@ -16,6 +18,10 @@
 import com.stylefeng.guns.modular.system.enums.UserTypeEnum;
 import com.stylefeng.guns.modular.system.model.*;
 import com.stylefeng.guns.modular.system.service.*;
+import com.stylefeng.guns.modular.system.util.MallBook.model.BindAccount;
+import com.stylefeng.guns.modular.system.util.MallBook.model.InterfaceResponse;
+import com.stylefeng.guns.modular.system.util.MallBook.model.Register;
+import com.stylefeng.guns.modular.system.util.MallBook.util.TrhRequest;
 import com.stylefeng.guns.modular.system.util.RedisUtil;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -23,18 +29,16 @@
 import org.apache.poi.hdf.extractor.TC;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.stylefeng.guns.core.log.LogObjectHolder;
-import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.OutputStream;
@@ -70,6 +74,9 @@
     private IUserService userService;
     @Autowired
     private RedisUtil redisUtil;
+
+    @Value("${callbackPath}")
+    private String callbackPath;
 
 
     /**
@@ -214,9 +221,111 @@
         user.setSex(1);
         userService.insert(user);
 
+
+
         return SUCCESS_TIP;
     }
 
+
+
+    public void registeredMerchant(TAgent tAgent){
+        Register registerVO = new Register();
+        registerVO.setMerUserId("agent_" + tAgent.getId());
+        registerVO.setPhone(tAgent.getPrincipalPhone());
+        registerVO.setUserType(tAgent.getUserType().toString());
+        registerVO.setUserName(tAgent.getMerchantName());
+        registerVO.setCertId(tAgent.getMerchantIDCode());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+        registerVO.setCertIdExpires(sdf.format(tAgent.getCertIdExpires()));
+        registerVO.setBusinessScope(tAgent.getBusinessScope());
+        registerVO.setSocialCreditCode(tAgent.getSocialCreditCode());
+        registerVO.setSocialCreditCodeExpires(sdf.format(tAgent.getSocialCreditCodeExpires()));
+        registerVO.setLegalPhone(tAgent.getLegalPhone());
+        registerVO.setLegalPerson(tAgent.getLegalPerson());
+        registerVO.setAddress(tAgent.getAddress());
+        /**
+         * 省份编码(子商户类型非小微必填) 字段长度最长:4位
+         */
+        registerVO.setProvCode("0035");
+        /**
+         * 地区编码(子商户类型非小微必填) 字段长度最长:4位
+         */
+        registerVO.setAreaCode("3501");
+        registerVO.setFileNo(tAgent.getFileNo());
+        registerVO.setNotifyUrl(callbackPath + "/base/driver/microenterpriseCallback");
+        registerVO.setParameter1(tAgent.getId().toString());
+
+        TrhRequest<Register> request = new TrhRequest();
+        InterfaceResponse response = request.execute(registerVO, Register.SERVICE_CODE);
+        if("0000".equals(response.getCode())){
+            JSONObject jsonObject = JSON.parseObject(response.getResult());
+            String status = jsonObject.getString("status");
+            if("2".equals(status)){
+                tAgent.setMerchantStatus(2);
+                tAgentService.updateById(tAgent);
+                System.err.println("注册代理商子商户失败");
+            }
+            if("0".equals(status)){
+                tAgent.setMerchantStatus(0);
+                tAgentService.updateById(tAgent);
+                System.err.println("注册代理商子商户处理中");
+            }
+            if("1".equals(status)){
+                String userId = jsonObject.getString("userId");
+                tAgent.setMerchantNumber(userId);
+                tAgent.setMerchantStatus(1);
+                tAgentService.updateById(tAgent);
+
+                //开始绑定结算账户
+                BindAccount bindAccount = new BindAccount();
+                bindAccount.setUserId(tAgent.getMerchantNumber());
+                bindAccount.setCertId(tAgent.getMerchantIDCode());
+                bindAccount.setCardName(tAgent.getCardName());
+                bindAccount.setCardNo(tAgent.getCardNo());
+                bindAccount.setBankAcctType(tAgent.getBankAcctType().toString());
+                bindAccount.setPhone(tAgent.getPhone());
+                bindAccount.setBankCode(tAgent.getBankCode());
+                /**
+                 * 省份编码
+                 */
+                bindAccount.setProvCode("0035");
+                /**
+                 * 地区编码
+                 */
+                bindAccount.setAreaCode("3501");
+                TrhRequest<BindAccount> request1 = new TrhRequest();
+                InterfaceResponse execute = request1.execute(bindAccount, BindAccount.SERVICE_CODE);
+                if("0000".equals(execute.getCode())){
+                    JSONObject jsonObject1 = JSON.parseObject(execute.getResult());
+                    String status1 = jsonObject1.getString("status");
+                    if("2".equals(status1)){
+                        tAgent.setBankStatus(2);
+                        tAgentService.updateById(tAgent);
+                        System.err.println("绑定结算账户失败" );
+                    }
+                    if("1".equals(status1)){
+                        tAgent.setBankStatus(1);
+                        tAgentService.updateById(tAgent);
+                        System.err.println("绑定结算账户成功");
+                    }
+                    if("0".equals(status1)){
+                        tAgent.setBankStatus(0);
+                        tAgentService.updateById(tAgent);
+                        System.err.println("绑定结算账户处理中");
+                    }
+                }else{
+                    System.err.println("绑定结算账户失败:" + execute.getMsg());
+                }
+
+            }
+        }else{
+            System.err.println("注册代理商子商户异常:" + response.getMsg());
+        }
+    }
+
+
+
+
     /**
      * 删除
      */

--
Gitblit v1.7.1