Parcourir la source

优化爱签实名认证功能,事先判断身份证号码和手机号码是否已经在交易系统被占用

zhou.xiaoning il y a 1 an
Parent
commit
d856f7c1de
7 fichiers modifiés avec 247 ajouts et 4 suppressions
  1. 59 4
      controllers/asign/test.go
  2. 56 0
      docs/docs.go
  3. 56 0
      docs/swagger.json
  4. 37 0
      docs/swagger.yaml
  5. 16 0
      models/account.go
  6. 1 0
      routers/router.go
  7. 22 0
      services/asign/servcies.go

+ 59 - 4
controllers/asign/test.go

@@ -1,6 +1,7 @@
 package asign
 
 import (
+	"errors"
 	"mtp2_if/global/app"
 	"mtp2_if/global/e"
 	"mtp2_if/logger"
@@ -70,13 +71,13 @@ func TestCaptcaResend(c *gin.Context) {
 // CaptchaVerify 认证验证码校验(测试)
 // @Summary     认证验证码校验(测试)
 // @Description 验证码认证成功后会调用爱签添加用户接口,同时调用交易系统JAVA实名认证接口
-// @Produce     json
-// @accept      application/json
+// @Produce json
+// @accept  application/json
 // @Param       data body     asignService.APICaptchaVerifyReq true "入参"
 // @Success     200  {object} asignService.APICaptchaVerifyRsp
-// @Failure     500  {object} app.Response
+// @Failure 500  {object} app.Response
 // @Router      /Asign/TestCaptchaVerify [post]
-// @Tags        爱签
+// @Tags    爱签
 func TestCaptchaVerify(c *gin.Context) {
 	appG := app.Gin{C: c}
 
@@ -123,3 +124,57 @@ func TestAddEnterpriseUser(c *gin.Context) {
 		appG.ResponseByMsg(http.StatusBadRequest, e.ERROR, err.Error(), nil)
 	}
 }
+
+// TestGetUser 获取用户信息(测试)
+// @Summary 获取用户信息(测试)
+// @Produce     json
+// @accept      application/json
+// @Param   data body     asignService.APIGetUserReq true "入参"
+// @Success 200  {object} asignService.APIGetUserReq
+// @Failure     500  {object} app.Response
+// @Router  /Asign/TestGetUser [post]
+// @Tags        爱签
+func TestGetUser(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req asignService.APIGetUserReq
+	if err := appG.C.ShouldBindJSON(&req); err != nil {
+		logger.GetLogger().Errorf(err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 判断证件号码是否已经在爱签平台存在
+	// var getUserReq APIGetUserReq
+	// getUserReq.Account = strconv.Itoa(req.UserId)
+	getUserReq := asignService.APIReq[asignService.APIGetUserReq]{
+		Data: asignService.APIGetUserReq{Account: req.Account},
+	}
+	apiRsp, err := asignService.APIPost[asignService.APIGetUserReq, []asignService.APIGetUserRsp](getUserReq, asignService.APIURL_GetUser)
+	if err != nil {
+		appG.ResponseByMsg(http.StatusBadRequest, e.ERROR, err.Error(), nil)
+		return
+	}
+	if apiRsp.Code == asignService.CODE_SUCCESS {
+		err = errors.New("电子签平台用户编号已存在")
+		logger.GetLogger().Error("电子签平台用户编号已存在, apiRsp:", apiRsp)
+		appG.ResponseByMsg(http.StatusBadRequest, e.ERROR, err.Error(), nil)
+		return
+	}
+	getUserReq.Data.Account = ""
+	getUserReq.Data.IdCard = req.IdCard
+	apiRsp, err = asignService.APIPost[asignService.APIGetUserReq, []asignService.APIGetUserRsp](getUserReq, asignService.APIURL_GetUser)
+	if err != nil {
+		appG.ResponseByMsg(http.StatusBadRequest, e.ERROR, err.Error(), nil)
+		return
+	}
+	if apiRsp.Code == asignService.CODE_SUCCESS && len(apiRsp.Data) > 0 {
+		err = errors.New("电子签平台证件号码已存在")
+		logger.GetLogger().Error("电子签平台证件号码已存在, apiRsp:", apiRsp)
+		appG.ResponseByMsg(http.StatusBadRequest, e.ERROR, err.Error(), nil)
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, "")
+}

+ 56 - 0
docs/docs.go

@@ -507,6 +507,45 @@ const docTemplate = `{
                 }
             }
         },
+        "/Asign/TestGetUser": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "爱签"
+                ],
+                "summary": "获取用户信息(测试)",
+                "parameters": [
+                    {
+                        "description": "入参",
+                        "name": "data",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/asign.APIGetUserReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/asign.APIGetUserReq"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Bank/QueryBankBranChnumInfo": {
             "get": {
                 "security": [
@@ -23517,6 +23556,23 @@ const docTemplate = `{
                 }
             }
         },
+        "asign.APIGetUserReq": {
+            "type": "object",
+            "properties": {
+                "account": {
+                    "description": "用户唯一识别码",
+                    "type": "string"
+                },
+                "creditCode": {
+                    "description": "社会统一信用代码",
+                    "type": "string"
+                },
+                "idCard": {
+                    "description": "证件号码",
+                    "type": "string"
+                }
+            }
+        },
         "asign.BankCard4Req": {
             "type": "object",
             "required": [

+ 56 - 0
docs/swagger.json

@@ -498,6 +498,45 @@
                 }
             }
         },
+        "/Asign/TestGetUser": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "爱签"
+                ],
+                "summary": "获取用户信息(测试)",
+                "parameters": [
+                    {
+                        "description": "入参",
+                        "name": "data",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/asign.APIGetUserReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/asign.APIGetUserReq"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Bank/QueryBankBranChnumInfo": {
             "get": {
                 "security": [
@@ -23508,6 +23547,23 @@
                 }
             }
         },
+        "asign.APIGetUserReq": {
+            "type": "object",
+            "properties": {
+                "account": {
+                    "description": "用户唯一识别码",
+                    "type": "string"
+                },
+                "creditCode": {
+                    "description": "社会统一信用代码",
+                    "type": "string"
+                },
+                "idCard": {
+                    "description": "证件号码",
+                    "type": "string"
+                }
+            }
+        },
         "asign.BankCard4Req": {
             "type": "object",
             "required": [

+ 37 - 0
docs/swagger.yaml

@@ -143,6 +143,18 @@ definitions:
     - mobile
     - realName
     type: object
+  asign.APIGetUserReq:
+    properties:
+      account:
+        description: 用户唯一识别码
+        type: string
+      creditCode:
+        description: 社会统一信用代码
+        type: string
+      idCard:
+        description: 证件号码
+        type: string
+    type: object
   asign.BankCard4Req:
     properties:
       company:
@@ -31502,6 +31514,31 @@ paths:
       summary: 认证验证码校验(测试)
       tags:
       - 爱签
+  /Asign/TestGetUser:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: 入参
+        in: body
+        name: data
+        required: true
+        schema:
+          $ref: '#/definitions/asign.APIGetUserReq'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/asign.APIGetUserReq'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      summary: 获取用户信息(测试)
+      tags:
+      - 爱签
   /Bank/QueryBankBranChnumInfo:
     get:
       parameters:

+ 16 - 0
models/account.go

@@ -738,6 +738,22 @@ func GetUserInfoByLoginID(loginID int) (*Userinfo, error) {
 	return &userInfo, nil
 }
 
+// GetUserInfoByIdCardNo 通过身份证(加密后)获取用户信息的方法
+func GetUserInfoByIdCardNo(idCardNo string) ([]Userinfo, error) {
+	engine := db.GetEngine()
+	infos := make([]Userinfo, 0)
+	err := engine.Where("CARDNUM", idCardNo).In("USERSTATUS", []int64{1, 3}).Find(&infos)
+	return infos, err
+}
+
+// GetUserInfoByMobile 通过手机号码(加密后)获取用户信息的方法
+func GetUserInfoByMobile(mobile string) ([]Userinfo, error) {
+	engine := db.GetEngine()
+	infos := make([]Userinfo, 0)
+	err := engine.Where("MOBILE", mobile).In("USERSTATUS", []int64{1, 3}).Find(&infos)
+	return infos, err
+}
+
 // GetUserInfoByIDS 批量获取用户信息.
 func GetUserInfoByIDS(userids []int64) ([]Userinfo, error) {
 	engine := db.GetEngine()

+ 1 - 0
routers/router.go

@@ -857,6 +857,7 @@ func InitRouter() *gin.Engine {
 		asignR.Use().POST("TestCaptcaResend", asign.TestCaptcaResend)
 		asignR.Use().POST("TestCaptchaVerify", asign.TestCaptchaVerify)
 		asignR.Use().POST("TestAddEnterpriseUser", asign.TestAddEnterpriseUser)
+		asignR.Use().POST("TestGetUser", asign.TestGetUser)
 		asignR.Use().POST("CreateSeal", asign.CreateSeal)
 
 		asignR.Use(token.Auth()).POST("BankCard4", asign.BankCard4)

+ 22 - 0
services/asign/servcies.go

@@ -75,6 +75,28 @@ func BankCard4(req BankCard4Req) (rsp BankCard4Rsp, err error) {
 		return
 	}
 
+	if req.Type == 1 {
+		// 判断此身份证号已经已经被别的账户占用
+		if idCardNo, e := models.EncryptField(req.Person.IdCardNo); e == nil {
+			if u, e := models.GetUserInfoByIdCardNo(idCardNo); e == nil {
+				if len(u) > 0 {
+					err = errors.New("身份证号已被占用")
+					return
+				}
+			}
+		}
+
+		// 判断此手机号码已经已经被别的账户占用
+		if mobile, e := models.EncryptField(req.Person.Mobile); e == nil {
+			if u, e := models.GetUserInfoByMobile(mobile); e == nil {
+				if len(u) > 0 {
+					err = errors.New("手机号码已被占用")
+					return
+				}
+			}
+		}
+	}
+
 	// 判断证件号码是否已经在爱签平台存在
 	// var getUserReq APIGetUserReq
 	// getUserReq.Account = strconv.Itoa(req.UserId)