소스 검색

增加商品收藏相关接口

zhou.xiaoning 5 년 전
부모
커밋
39405ed961
7개의 변경된 파일532개의 추가작업 그리고 9개의 파일을 삭제
  1. 2 2
      controllers/quote/history.go
  2. 110 0
      controllers/user/user.go
  3. 133 2
      docs/docs.go
  4. 133 2
      docs/swagger.json
  5. 84 2
      docs/swagger.yaml
  6. 64 1
      models/account.go
  7. 6 0
      routers/router.go

+ 2 - 2
controllers/quote/history.go

@@ -24,7 +24,7 @@ type HistoryData struct {
 	TotleTurnover float64   `json:"tt"` // 总金额
 	HoldVolume    int       `json:"hv"` // 持仓量
 	Settle        float64   `json:"s"`  // 结算价,日线周期(包括)以上才有
-	TimeStamp     time.Time `json:"ts"` // 开盘时间
+	TimeStamp     time.Time `json:"ts"` // 时间
 }
 
 // QueryHistoryDatasReq 查询行情历史数据请求参数
@@ -46,7 +46,7 @@ type QueryHistoryDatasReq struct {
 // @Param startTime query string false "开始时间,格式:yyyy-MM-dd HH:mm:ss"
 // @Param endTime query string false "结束时间,格式:yyyy-MM-dd HH:mm:ss"
 // @Param count query int false "条数"
-// @Param IsAsc query bool false "是否按时间顺序排序(默认为时间倒序排序)"
+// @Param isAsc query bool false "是否按时间顺序排序(默认为时间倒序排序)"
 // @Success 200 {object} HistoryData
 // @Failure 500 {object} app.Response
 // @Router /Quote/QueryHistoryDatas [get]

+ 110 - 0
controllers/user/user.go

@@ -138,3 +138,113 @@ func GetUserAuthStatus(c *gin.Context) {
 	logger.GetLogger().Debugln("GetUserAuthStatus successed: %v", isAuth)
 	appG.Response(http.StatusOK, e.SUCCESS, isAuth)
 }
+
+// QueryUserFavoriteGoodsesReq 获取用户商品收藏信息请求参数
+type QueryUserFavoriteGoodsesReq struct {
+	UserID int `form:"userID" binding:"required"`
+}
+
+// QueryUserFavoriteGoodses 获取用户商品收藏信息
+// @Summary 获取用户商品收藏信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userID query int true "用户ID"
+// @Success 200 {bool} models.Userfavoritegoods
+// @Failure 500 {object} app.Response
+// @Router /User/QueryUserFavoriteGoodses [get]
+// @Tags 用户信息
+func QueryUserFavoriteGoodses(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryUserFavoriteGoodsesReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryUserFavoriteGoodses failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	userFavoriteGoodses, err := models.GetUserFavoriteGoodses(req.UserID)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功
+	logger.GetLogger().Debugln("QueryUserFavoriteGoodses successed: %v", userFavoriteGoodses)
+	appG.Response(http.StatusOK, e.SUCCESS, userFavoriteGoodses)
+}
+
+// UpdateUserFavoriteGoodsReq 更新用户商品收藏信息请求参数
+type UpdateUserFavoriteGoodsReq struct {
+	UserID  int `form:"userID" binding:"required"`
+	GoodsID int `form:"goodsID" binding:"required"`
+}
+
+// AddUserFavoriteGoods 添加用户商品收藏信息
+// @Summary 添加用户商品收藏信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userID query int true "用户ID"
+// @Param goodsID query int true "商品ID"
+// @Success 200 {object} app.Response
+// @Failure 500 {object} app.Response
+// @Router /User/AddUserFavoriteGoods [post]
+// @Tags 用户信息
+func AddUserFavoriteGoods(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req UpdateUserFavoriteGoodsReq
+	if err := appG.C.ShouldBind(&req); err != nil {
+		logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if err := models.InsertUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
+		// 执行失败
+		logger.GetLogger().Errorf("AddUserFavoriteGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+		return
+	}
+
+	// 执行成功
+	logger.GetLogger().Debugln("AddUserFavoriteGoods successed: %v", "ok")
+	appG.Response(http.StatusOK, e.SUCCESS, "")
+}
+
+// RemoveUserFavoriteGoods 移除用户商品收藏信息
+// @Summary 移除用户商品收藏信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userID query int true "用户ID"
+// @Param goodsID query int true "商品ID"
+// @Success 200 {object} app.Response
+// @Failure 500 {object} app.Response
+// @Router /User/RemoveUserFavoriteGoods [post]
+// @Tags 用户信息
+func RemoveUserFavoriteGoods(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req UpdateUserFavoriteGoodsReq
+	if err := appG.C.ShouldBind(&req); err != nil {
+		logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if err := models.DelUserFavoriteGoods(req.UserID, req.GoodsID); err != nil {
+		// 执行失败
+		logger.GetLogger().Errorf("RemoveUserFavoriteGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+		return
+	}
+
+	// 执行成功
+	logger.GetLogger().Debugln("RemoveUserFavoriteGoods successed: %v", "ok")
+	appG.Response(http.StatusOK, e.SUCCESS, "")
+}

+ 133 - 2
docs/docs.go

@@ -1579,7 +1579,7 @@ var doc = `{
                     {
                         "type": "boolean",
                         "description": "是否按时间顺序排序(默认为时间倒序排序)",
-                        "name": "IsAsc",
+                        "name": "isAsc",
                         "in": "query"
                     }
                 ],
@@ -2054,6 +2054,52 @@ var doc = `{
                 }
             }
         },
+        "/User/AddUserFavoriteGoods": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "添加用户商品收藏信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID",
+                        "name": "goodsID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/User/GetLoginID": {
             "get": {
                 "description": "UserName 可传入“登录账号”、“登录代码”和“手机号码”",
@@ -2128,6 +2174,45 @@ var doc = `{
                 }
             }
         },
+        "/User/QueryUserFavoriteGoodses": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "获取用户商品收藏信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "bool"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/User/QueryUserInfo": {
             "get": {
                 "security": [
@@ -2201,6 +2286,52 @@ var doc = `{
                 }
             }
         },
+        "/User/RemoveUserFavoriteGoods": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "移除用户商品收藏信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID",
+                        "name": "goodsID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WRTrade/GetAllDeliveryGoods": {
             "get": {
                 "security": [
@@ -6247,7 +6378,7 @@ var doc = `{
                     "type": "number"
                 },
                 "ts": {
-                    "description": "开盘时间",
+                    "description": "时间",
                     "type": "string"
                 },
                 "tt": {

+ 133 - 2
docs/swagger.json

@@ -1563,7 +1563,7 @@
                     {
                         "type": "boolean",
                         "description": "是否按时间顺序排序(默认为时间倒序排序)",
-                        "name": "IsAsc",
+                        "name": "isAsc",
                         "in": "query"
                     }
                 ],
@@ -2038,6 +2038,52 @@
                 }
             }
         },
+        "/User/AddUserFavoriteGoods": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "添加用户商品收藏信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID",
+                        "name": "goodsID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/User/GetLoginID": {
             "get": {
                 "description": "UserName 可传入“登录账号”、“登录代码”和“手机号码”",
@@ -2112,6 +2158,45 @@
                 }
             }
         },
+        "/User/QueryUserFavoriteGoodses": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "获取用户商品收藏信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "bool"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/User/QueryUserInfo": {
             "get": {
                 "security": [
@@ -2185,6 +2270,52 @@
                 }
             }
         },
+        "/User/RemoveUserFavoriteGoods": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "移除用户商品收藏信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID",
+                        "name": "goodsID",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WRTrade/GetAllDeliveryGoods": {
             "get": {
                 "security": [
@@ -6231,7 +6362,7 @@
                     "type": "number"
                 },
                 "ts": {
-                    "description": "开盘时间",
+                    "description": "时间",
                     "type": "string"
                 },
                 "tt": {

+ 84 - 2
docs/swagger.yaml

@@ -3031,7 +3031,7 @@ definitions:
         description: 结算价,日线周期(包括)以上才有
         type: number
       ts:
-        description: 开盘时间
+        description: 时间
         type: string
       tt:
         description: 总金额
@@ -4521,7 +4521,7 @@ paths:
         type: integer
       - description: 是否按时间顺序排序(默认为时间倒序排序)
         in: query
-        name: IsAsc
+        name: isAsc
         type: boolean
       produces:
       - application/json
@@ -4827,6 +4827,35 @@ paths:
       summary: 资金流水查询(历史)
       tags:
       - 资金账户
+  /User/AddUserFavoriteGoods:
+    post:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userID
+        required: true
+        type: integer
+      - description: 商品ID
+        in: query
+        name: goodsID
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/app.Response'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 添加用户商品收藏信息
+      tags:
+      - 用户信息
   /User/GetLoginID:
     get:
       description: UserName 可传入“登录账号”、“登录代码”和“手机号码”
@@ -4874,6 +4903,30 @@ paths:
       summary: 获取用户实名认证状态
       tags:
       - 用户信息
+  /User/QueryUserFavoriteGoodses:
+    get:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userID
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            type: bool
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 获取用户商品收藏信息
+      tags:
+      - 用户信息
   /User/QueryUserInfo:
     get:
       parameters:
@@ -4920,6 +4973,35 @@ paths:
       summary: 获取用户邀请码
       tags:
       - 用户信息
+  /User/RemoveUserFavoriteGoods:
+    post:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userID
+        required: true
+        type: integer
+      - description: 商品ID
+        in: query
+        name: goodsID
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/app.Response'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 移除用户商品收藏信息
+      tags:
+      - 用户信息
   /WRTrade/GetAllDeliveryGoods:
     get:
       produces:

+ 64 - 1
models/account.go

@@ -325,6 +325,19 @@ func (Histaaccountlog) TableName() string {
 	return "HIS_TAACCOUNTLOG"
 }
 
+// Userfavoritegoods 用户商品收藏表
+type Userfavoritegoods struct {
+	Userid     int64     `json:"-"  xorm:"'USERID'" binding:"required"`        // 用户
+	Goodsid    int64     `json:"goodsid"  xorm:"'GOODSID'" binding:"required"` // 商品ID
+	Marketid   int32     `json:"-"  xorm:"'MARKETID'"`                         // 市场ID
+	Modifytime time.Time `json:"-"  xorm:"'MODIFYTIME'"`                       // 修改时间
+}
+
+// TableName is USERFAVORITEGOODS
+func (Userfavoritegoods) TableName() string {
+	return "USERFAVORITEGOODS"
+}
+
 // GetLoginAccountByLoginCode 通过登录代码查询登录账号信息
 func GetLoginAccountByLoginCode(loginCode string) (*Loginaccount, error) {
 	engine := db.GetEngine()
@@ -386,8 +399,8 @@ func GetUserAccount(userID int) (*Useraccount, error) {
 // GetUserInfo 获取用户信息
 func GetUserInfo(userID int) (*Userinfo, error) {
 	engine := db.GetEngine()
-	var userInfo *Userinfo
 
+	var userInfo *Userinfo
 	_, err := engine.Where("USERID = ?", userID).Get(userInfo)
 	if err != nil {
 		// 查询失败
@@ -396,3 +409,53 @@ func GetUserInfo(userID int) (*Userinfo, error) {
 
 	return userInfo, nil
 }
+
+// GetUserFavoriteGoodses 获取用户商品收藏信息
+func GetUserFavoriteGoodses(userID int) ([]Userfavoritegoods, error) {
+	engine := db.GetEngine()
+
+	favoriteGoodses := make([]Userfavoritegoods, 0)
+	if err := engine.Where("USERID = ?", userID).Find(&favoriteGoodses); err != nil {
+		return nil, err
+	}
+
+	return favoriteGoodses, nil
+}
+
+// InsertUserFavoriteGoods 新增用户商品收藏信息
+func InsertUserFavoriteGoods(userID int, goodsID int) error {
+	engine := db.GetEngine()
+
+	userfavoritegoods := &Userfavoritegoods{
+		Userid:  int64(userID),
+		Goodsid: int64(goodsID),
+	}
+	has, err := engine.Get(userfavoritegoods)
+	if err != nil {
+		return err
+	}
+	if !has {
+		// 不存在时则插入一条新记录
+		// userfavoritegoods.Modifytime = time.Now()
+		if _, err := engine.Insert(userfavoritegoods); err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
+// DelUserFavoriteGoods 删除用户商品收藏信息
+func DelUserFavoriteGoods(userID int, goodsID int) error {
+	engine := db.GetEngine()
+
+	userfavoritegoods := &Userfavoritegoods{
+		Userid:  int64(userID),
+		Goodsid: int64(goodsID),
+	}
+	if _, err := engine.Delete(userfavoritegoods); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 6 - 0
routers/router.go

@@ -59,6 +59,12 @@ func InitRouter() *gin.Engine {
 		userR.Use(token.Auth()).GET("/QueryUserInfo", user.QueryUserInfo)
 		// 获取用户实名认证状态
 		userR.Use(token.Auth()).GET("/GetUserAuthStatus", user.GetUserAuthStatus)
+		// 获取用户商品收藏信息
+		userR.Use(token.Auth()).GET("/QueryUserFavoriteGoodses", user.QueryUserFavoriteGoodses)
+		// 添加用户商品收藏信息
+		userR.Use(token.Auth()).POST("/AddUserFavoriteGoods", user.AddUserFavoriteGoods)
+		// 移除用户商品收藏信息
+		userR.Use(token.Auth()).POST("/RemoveUserFavoriteGoods", user.RemoveUserFavoriteGoods)
 	}
 	// ************************ 资金账户 ************************
 	taAccountR := apiR.Group("TaAccount")