Переглянути джерело

修改查询好友的接口

zou.yingbin 4 роки тому
батько
коміт
688197e4de
5 змінених файлів з 35 додано та 37 видалено
  1. 2 2
      controllers/wrTrade2/qryWrTrade.go
  2. 7 8
      docs/docs.go
  3. 7 8
      docs/swagger.json
  4. 6 7
      docs/swagger.yaml
  5. 13 12
      models/wrTrade2.go

+ 2 - 2
controllers/wrTrade2/qryWrTrade.go

@@ -529,8 +529,8 @@ func QueryWrDeliveryAvalidHoldLB(c *gin.Context) {
 // @Summary 查询我的朋友
 // @Produce json
 // @Security ApiKeyAuth
-// @Param userid query int true "用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)"
-// @Param querytype query int true "查询类型 1-查我的朋友 2-查找新朋友"
+// @Param userid query int true "用户id"
+// @Param newuserid query int false "新朋友userid, 如果填写了此项则查找新朋友"
 // @Success 200 {array} models.WrUserFriend
 // @Failure 500 {object} app.Response
 // @Router /WrTrade2/QueryWrUserFriend [get]

+ 7 - 8
docs/docs.go

@@ -12527,17 +12527,16 @@ var doc = `{
                 "parameters": [
                     {
                         "type": "integer",
-                        "description": "用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)",
+                        "description": "用户id",
                         "name": "userid",
                         "in": "query",
                         "required": true
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-查我的朋友 2-查找新朋友",
-                        "name": "querytype",
-                        "in": "query",
-                        "required": true
+                        "description": "新朋友userid, 如果填写了此项则查找新朋友",
+                        "name": "newuserid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -33165,12 +33164,12 @@ var doc = `{
                     "description": "朋友id",
                     "type": "integer"
                 },
-                "querytype": {
-                    "description": "查询类型 1-查我的朋友 2-查找新朋友",
+                "isfriend": {
+                    "description": "是否好友 0-不是 1-是",
                     "type": "integer"
                 },
                 "userid": {
-                    "description": "用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)",
+                    "description": "用户id",
                     "type": "integer"
                 }
             }

+ 7 - 8
docs/swagger.json

@@ -12511,17 +12511,16 @@
                 "parameters": [
                     {
                         "type": "integer",
-                        "description": "用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)",
+                        "description": "用户id",
                         "name": "userid",
                         "in": "query",
                         "required": true
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-查我的朋友 2-查找新朋友",
-                        "name": "querytype",
-                        "in": "query",
-                        "required": true
+                        "description": "新朋友userid, 如果填写了此项则查找新朋友",
+                        "name": "newuserid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -33149,12 +33148,12 @@
                     "description": "朋友id",
                     "type": "integer"
                 },
-                "querytype": {
-                    "description": "查询类型 1-查我的朋友 2-查找新朋友",
+                "isfriend": {
+                    "description": "是否好友 0-不是 1-是",
                     "type": "integer"
                 },
                 "userid": {
-                    "description": "用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)",
+                    "description": "用户id",
                     "type": "integer"
                 }
             }

+ 6 - 7
docs/swagger.yaml

@@ -15359,11 +15359,11 @@ definitions:
       frienduserid:
         description: 朋友id
         type: integer
-      querytype:
-        description: 查询类型 1-查我的朋友 2-查找新朋友
+      isfriend:
+        description: 是否好友 0-不是 1-是
         type: integer
       userid:
-        description: 用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)
+        description: 用户id
         type: integer
     type: object
   order.QueryHisTradeDetailRsp:
@@ -25231,15 +25231,14 @@ paths:
   /WrTrade2/QueryWrUserFriend:
     get:
       parameters:
-      - description: 用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)
+      - description: 用户id
         in: query
         name: userid
         required: true
         type: integer
-      - description: 查询类型 1-查我的朋友 2-查找新朋友
+      - description: 新朋友userid, 如果填写了此项则查找新朋友
         in: query
-        name: querytype
-        required: true
+        name: newuserid
         type: integer
       produces:
       - application/json

+ 13 - 12
models/wrTrade2.go

@@ -2975,11 +2975,11 @@ func (r *WrDeliveryAvalidHoldLB) GetDataEx() (interface{}, error) {
 
 // WrUserFriend 我的朋友
 type WrUserFriend struct {
-	USERID       int64  `json:"userid"  xorm:"'USERID'" form:"userid"` // 用户id(查我的朋友时填自己的userid, 找新朋友时填写新朋友userid)
+	USERID       int64  `json:"userid"  xorm:"'USERID'" form:"userid"` // 用户id
 	FRIENDUSERID int64  `json:"frienduserid"  xorm:"'FRIENDUSERID'"`   // 朋友id
 	FRIENDNAME   string `json:"friendname"  xorm:"'FRIENDNAME'"`       // 朋友名称(已脱敏)
-
-	QueryType int32 `json:"querytype"` // 查询类型 1-查我的朋友 2-查找新朋友
+	ISFRIEND     int32  `json:"isfriend"  xorm:"'ISFRIEND'"`           // 是否好友 0-不是 1-是
+	NEWUSERID    int64  `json:"-" form:"newuserid"`                    // 新朋友id
 }
 
 func (r *WrUserFriend) calc() {
@@ -2988,19 +2988,21 @@ func (r *WrUserFriend) calc() {
 
 func (r *WrUserFriend) buildSql() string {
 	var sqlId utils.SQLVal
-	if r.QueryType == 1 {
-		sqlId = "select t.userid, t.frienduserid, u.accountname friendname" +
+	if r.NEWUSERID > 0 {
+		sqlId =
+			"select t.userid frienduserid, t.accountname friendname, nvl(f.userid-f.userid+1,0) isfriend" +
+				"  from useraccount t" +
+				"  left join userfriend f on t.userid=f.frienduserid and f.userid=%v" +
+				" where 1 = 1" +
+				"   and t.userid = %v"
+		sqlId.FormatParam(r.USERID, r.NEWUSERID)
+	} else {
+		sqlId = "select t.userid, t.frienduserid, u.accountname friendname, 1 as isfriend" +
 			"  from UserFriend t" +
 			"  left join useraccount u" +
 			"    on t.frienduserid = u.userid" +
 			" where 1 = 1"
 		sqlId.And("t.userid", r.USERID)
-	} else {
-		sqlId =
-			"select t.userid frienduserid, t.accountname friendname" +
-				"  from useraccount t" +
-				" where 1 = 1"
-		sqlId.And("t.userid", r.USERID)
 	}
 
 	return sqlId.String()
@@ -3012,7 +3014,6 @@ func (r *WrUserFriend) GetDataEx() (interface{}, error) {
 	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
 	for i := range sData {
 		sData[i].calc()
-		sData[i].QueryType = r.QueryType
 	}
 	return sData, err
 }