فهرست منبع

新增用户留言板相关接口

zhou.xiaoning 5 سال پیش
والد
کامیت
2db1dd421a
8فایلهای تغییر یافته به همراه356 افزوده شده و 0 حذف شده
  1. 77 0
      controllers/user/user.go
  2. 85 0
      docs/docs.go
  3. 85 0
      docs/swagger.json
  4. 53 0
      docs/swagger.yaml
  5. 1 0
      global/e/code.go
  6. 1 0
      global/e/msg.go
  7. 49 0
      models/account.go
  8. 5 0
      routers/router.go

+ 77 - 0
controllers/user/user.go

@@ -248,3 +248,80 @@ func RemoveUserFavoriteGoods(c *gin.Context) {
 	logger.GetLogger().Debugln("RemoveUserFavoriteGoods successed: %v", "ok")
 	appG.Response(http.StatusOK, e.SUCCESS, "")
 }
+
+// QueryMessageBoardReq 获取用户留言板信息请求参数
+type QueryMessageBoardReq struct {
+	UserID int `form:"userID" binding:"required"`
+}
+
+// QueryMessageBoard 获取用户留言板信息
+// @Summary 获取用户留言板信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userID query int true "用户ID"
+// @Success 200 {bool} models.Messageboard
+// @Failure 500 {object} app.Response
+// @Router /User/QueryMessageBoard [get]
+// @Tags 用户信息
+func QueryMessageBoard(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryMessageBoardReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	messageBoards, err := models.GetMessageBoard(req.UserID)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryMessageBoard failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功
+	logger.GetLogger().Debugln("QueryMessageBoard successed: %v", messageBoards)
+	appG.Response(http.StatusOK, e.SUCCESS, messageBoards)
+}
+
+// AddMessageBoardReq 添加用户留言板信息请求参数
+type AddMessageBoardReq struct {
+	UserID  int    `form:"userID" binding:"required"`
+	Message string `form:"message" binding:"required"`
+}
+
+// AddMessageBoard 添加用户留言板信息
+// @Summary 添加用户留言板信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userID query int true "用户ID"
+// @Param message query string true "留言信息"
+// @Success 200 {object} app.Response
+// @Failure 500 {object} app.Response
+// @Router /User/AddMessageBoard [post]
+// @Tags 用户信息
+func AddMessageBoard(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req AddMessageBoardReq
+	if err := appG.C.ShouldBind(&req); err != nil {
+		logger.GetLogger().Errorf("AddMessageBoard failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if errCode := models.InsertMessageBoard(req.UserID, req.Message); errCode != 0 {
+		// 执行失败
+		logger.GetLogger().Errorf("AddMessageBoard failed: %s", e.GetMsg(errCode))
+		appG.Response(http.StatusBadRequest, errCode, nil)
+		return
+	}
+
+	// 执行成功
+	logger.GetLogger().Debugln("AddMessageBoard successed: %v", "ok")
+	appG.Response(http.StatusOK, e.SUCCESS, "")
+}

+ 85 - 0
docs/docs.go

@@ -2054,6 +2054,52 @@ var doc = `{
                 }
             }
         },
+        "/User/AddMessageBoard": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "添加用户留言板信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "留言信息",
+                        "name": "message",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/User/AddUserFavoriteGoods": {
             "post": {
                 "security": [
@@ -2174,6 +2220,45 @@ var doc = `{
                 }
             }
         },
+        "/User/QueryMessageBoard": {
+            "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/QueryUserFavoriteGoodses": {
             "get": {
                 "security": [

+ 85 - 0
docs/swagger.json

@@ -2038,6 +2038,52 @@
                 }
             }
         },
+        "/User/AddMessageBoard": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户信息"
+                ],
+                "summary": "添加用户留言板信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "留言信息",
+                        "name": "message",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/User/AddUserFavoriteGoods": {
             "post": {
                 "security": [
@@ -2158,6 +2204,45 @@
                 }
             }
         },
+        "/User/QueryMessageBoard": {
+            "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/QueryUserFavoriteGoodses": {
             "get": {
                 "security": [

+ 53 - 0
docs/swagger.yaml

@@ -4827,6 +4827,35 @@ paths:
       summary: 资金流水查询(历史)
       tags:
       - 资金账户
+  /User/AddMessageBoard:
+    post:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userID
+        required: true
+        type: integer
+      - description: 留言信息
+        in: query
+        name: message
+        required: true
+        type: string
+      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/AddUserFavoriteGoods:
     post:
       parameters:
@@ -4903,6 +4932,30 @@ paths:
       summary: 获取用户实名认证状态
       tags:
       - 用户信息
+  /User/QueryMessageBoard:
+    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/QueryUserFavoriteGoodses:
     get:
       parameters:

+ 1 - 0
global/e/code.go

@@ -17,6 +17,7 @@ const (
 	ERROR_GET_MARKETRUN_FAILED     = 30013
 	ERROR_GET_RUNSTEP_FAILED       = 30014
 	ERROR_QUERY_TIME_FORMAT_FAIL   = 30015
+	ERROR_ADD_MAX_3                = 30016
 
 	ERROR_UPLOAD_SAVE_IMAGE_FAIL    = 40001
 	ERROR_UPLOAD_CHECK_IMAGE_FAIL   = 40002

+ 1 - 0
global/e/msg.go

@@ -17,6 +17,7 @@ var MsgFlags = map[int]string{
 	ERROR_GET_MARKETRUN_FAILED:     "获取市场运行参数失败",
 	ERROR_GET_RUNSTEP_FAILED:       "获取市场开休市计划失败",
 	ERROR_QUERY_TIME_FORMAT_FAIL:   "错误的时间格式",
+	ERROR_ADD_MAX_3:                "每日最多只能新增3条留言",
 
 	ERROR_UPLOAD_SAVE_IMAGE_FAIL:    "保存图片失败",
 	ERROR_UPLOAD_CHECK_IMAGE_FAIL:   "检查图片失败",

+ 49 - 0
models/account.go

@@ -2,7 +2,9 @@ package models
 
 import (
 	"encoding/hex"
+	"fmt"
 	"mtp2_if/db"
+	"mtp2_if/global/e"
 	"mtp2_if/utils"
 	"time"
 )
@@ -338,6 +340,19 @@ func (Userfavoritegoods) TableName() string {
 	return "USERFAVORITEGOODS"
 }
 
+// Messageboard 留言簿表
+type Messageboard struct {
+	Messageboardid int64     `json:"messageboardid"  xorm:"'MESSAGEBOARDID'" binding:"required"` // 留言簿ID(SEQ_MessageBoard)
+	Userid         int64     `json:"userid"  xorm:"'USERID'"`                                    // 用户ID
+	Message        string    `json:"message"  xorm:"'MESSAGE'"`                                  // 留言信息
+	Createtime     time.Time `json:"createtime"  xorm:"'CREATETIME'"`                            // 创建时间
+}
+
+// TableName is MESSAGEBOARD
+func (Messageboard) TableName() string {
+	return "MESSAGEBOARD"
+}
+
 // GetLoginAccountByLoginCode 通过登录代码查询登录账号信息
 func GetLoginAccountByLoginCode(loginCode string) (*Loginaccount, error) {
 	engine := db.GetEngine()
@@ -459,3 +474,37 @@ func DelUserFavoriteGoods(userID int, goodsID int) error {
 
 	return nil
 }
+
+// GetMessageBoard 获取用户留言板信息
+func GetMessageBoard(userID int) ([]Messageboard, error) {
+	engine := db.GetEngine()
+
+	messageBoards := make([]Messageboard, 0)
+	if err := engine.Where("USERID = ?", userID).Desc("CREATETIME").Find(&messageBoards); err != nil {
+		return nil, err
+	}
+
+	return messageBoards, nil
+}
+
+// InsertMessageBoard 新增用户留言板信息
+func InsertMessageBoard(userID int, message string) int {
+	engine := db.GetEngine()
+
+	// 一天最多只能新增3条留言
+	messageBoard := new(Messageboard)
+	total, err := engine.Where("CREATETIME >=TRUNC(SYSDATE) and CREATETIME < TRUNC(SYSDATE)+1").Count(messageBoard)
+	if err != nil {
+		return e.ERROR_OPERATION_FAILED
+	}
+	if total >= 3 {
+		return e.ERROR_ADD_MAX_3
+	}
+
+	sql := fmt.Sprintf("insert into MESSAGEBOARD (MESSAGEBOARDID, USERID, MESSAGE, CREATETIME) values (SEQ_MessageBoard.nextval, %d, '%s', (select sysdate from dual))", userID, message)
+	if _, err := engine.Exec(sql); err != nil {
+		return e.ERROR_OPERATION_FAILED
+	}
+
+	return 0
+}

+ 5 - 0
routers/router.go

@@ -65,6 +65,11 @@ func InitRouter() *gin.Engine {
 		userR.Use(token.Auth()).POST("/AddUserFavoriteGoods", user.AddUserFavoriteGoods)
 		// 移除用户商品收藏信息
 		userR.Use(token.Auth()).POST("/RemoveUserFavoriteGoods", user.RemoveUserFavoriteGoods)
+		// 获取用户留言板信息
+		userR.Use(token.Auth()).GET("/QueryMessageBoard", user.QueryMessageBoard)
+		// 添加用户留言板信息
+		userR.Use(token.Auth()).POST("/AddMessageBoard", user.AddMessageBoard)
+
 	}
 	// ************************ 资金账户 ************************
 	taAccountR := apiR.Group("TaAccount")