Explorar el Código

goods tag revised

May1145 hace 1 año
padre
commit
0439a19bd5
Se han modificado 31 ficheros con 704 adiciones y 175 borrados
  1. 96 41
      trading-go/controller/chatcontroller.go
  2. 32 0
      trading-go/controller/goodscontroller.go
  3. 0 7
      trading-go/controller/piccontrller.go
  4. 2 1
      trading-go/controller/relationcontroller.go
  5. 28 7
      trading-go/controller/usercontroller.go
  6. 146 14
      trading-go/docs/docs.go
  7. 146 14
      trading-go/docs/swagger.json
  8. 98 12
      trading-go/docs/swagger.yaml
  9. 1 1
      trading-go/main.go
  10. 54 47
      trading-go/model/goods.go
  11. 49 3
      trading-go/model/message.go
  12. 17 13
      trading-go/model/pic.go
  13. 17 14
      trading-go/model/relation.go
  14. 12 0
      trading-go/model/user.go
  15. BIN
      trading-go/pics/1699375397UN3eFHEVeEtEb1493fda534929a5b5d05f80a8cf3d16.jpg
  16. BIN
      trading-go/pics/1699376791kDvVkMDqGaKjb1493fda534929a5b5d05f80a8cf3d16.jpg
  17. BIN
      trading-go/pics/1699376842DbDkdnl78sbBb1493fda534929a5b5d05f80a8cf3d16.jpg
  18. BIN
      trading-go/pics/1699377248GdPib7YWQsXAb1493fda534929a5b5d05f80a8cf3d16.jpg
  19. BIN
      trading-go/pics/1699378552vxHfGwZXkePTb1493fda534929a5b5d05f80a8cf3d16.jpg
  20. BIN
      trading-go/pics/1699378578JPJKVU20yj8xb1493fda534929a5b5d05f80a8cf3d16.jpg
  21. BIN
      trading-go/pics/1699378604WzGV4QEYsyqzb1493fda534929a5b5d05f80a8cf3d16.jpg
  22. BIN
      trading-go/pics/16993786734xio8nxv2TFNb1493fda534929a5b5d05f80a8cf3d16.jpg
  23. BIN
      trading-go/pics/1699378762ThBCYkhdz9zqb1493fda534929a5b5d05f80a8cf3d16.jpg
  24. BIN
      trading-go/pics/16993787821A2FjRLvVruhb1493fda534929a5b5d05f80a8cf3d16.jpg
  25. BIN
      trading-go/pics/1699378849dxutdmTao1rOb1493fda534929a5b5d05f80a8cf3d16.jpg
  26. BIN
      trading-go/pics/1699378868UNzjT86U9mZrb1493fda534929a5b5d05f80a8cf3d16.jpg
  27. BIN
      trading-go/pics/1699379040BxHIa2rdXr7Ab1493fda534929a5b5d05f80a8cf3d16.jpg
  28. BIN
      trading-go/pics/1699379135EcsSvbvLkVhTb1493fda534929a5b5d05f80a8cf3d16.jpg
  29. 4 0
      trading-go/routine/routine.go
  30. 1 0
      trading-go/util/error.go
  31. 1 1
      trading-go/util/search.go

+ 96 - 41
trading-go/controller/chatcontroller.go

@@ -7,7 +7,6 @@ import (
 	"github.com/gorilla/websocket"
 	"net/http"
 	"strconv"
-	"time"
 	"trading-go/model"
 	"trading-go/response"
 )
@@ -90,46 +89,46 @@ func reception(conn *websocket.Conn, uid uint) {
 	}
 }
 
-func broadcast(data model.Message) {
-	for _, conn := range Conns {
-		msg, err := json.Marshal(data)
-		if err != nil {
-			fmt.Println(err.Error())
-			break
-		}
-		err = conn.conn.WriteMessage(data.MsgType, msg)
-		if err != nil {
-			fmt.Println(err.Error())
-			break
-		}
-	}
-}
+//func broadcast(data model.Message) {
+//	for _, conn := range Conns {
+//		msg, err := json.Marshal(data)
+//		if err != nil {
+//			fmt.Println(err.Error())
+//			break
+//		}
+//		err = conn.conn.WriteMessage(data.MsgType, msg)
+//		if err != nil {
+//			fmt.Println(err.Error())
+//			break
+//		}
+//	}
+//}
 
-func heartBeat(conn *websocket.Conn, uid uint) {
-	defer func() {
-		delete(Conns, uid)
-	}()
-	for {
-		msg := model.Message{
-			MsgType: 4,
-			From:    0,
-			To:      uid,
-			Time:    uint(time.Now().Unix()),
-			Content: "alive",
-		}
-		data, err := json.Marshal(msg)
-		if err != nil {
-			fmt.Println(err.Error())
-			break
-		}
-		err = conn.WriteMessage(websocket.TextMessage, data)
-		if err != nil {
-			fmt.Println(err.Error())
-			break
-		}
-		time.Sleep(time.Second * 5)
-	}
-}
+//func heartBeat(conn *websocket.Conn, uid uint) {
+//	defer func() {
+//		delete(Conns, uid)
+//	}()
+//	for {
+//		msg := model.Message{
+//			MsgType: 4,
+//			From:    0,
+//			To:      uid,
+//			Time:    uint(time.Now().Unix()),
+//			Content: "alive",
+//		}
+//		data, err := json.Marshal(msg)
+//		if err != nil {
+//			fmt.Println(err.Error())
+//			break
+//		}
+//		err = conn.WriteMessage(websocket.TextMessage, data)
+//		if err != nil {
+//			fmt.Println(err.Error())
+//			break
+//		}
+//		time.Sleep(time.Second * 5)
+//	}
+//}
 
 func Chat(w http.ResponseWriter, rq *http.Request, uid uint) {
 	// 升级为websocket
@@ -149,7 +148,7 @@ func Chat(w http.ResponseWriter, rq *http.Request, uid uint) {
 
 	go send(conn, uid)
 	go reception(conn, uid)
-	go heartBeat(conn, uid)
+	//go heartBeat(conn, uid)
 
 	response.Success(w, "success", nil)
 }
@@ -231,3 +230,59 @@ func GetMsgToPaged(c *gin.Context) {
 	}
 	response.Success(c.Writer, "success", rsp)
 }
+
+// GetMsg
+// @Tags 聊天模块
+// @Summary 获取与特定用户相关的所有聊天记录
+// @Param uid query string true "用户id"
+// @Success 200 {object} response.Response
+// @Router /chat/msg/ [get]
+func GetMsg(c *gin.Context) {
+	var ms model.Message
+	id := c.Query("uid")
+	uid, err := strconv.ParseUint(id, 10, 64)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	msgs, err := ms.GetMsg(uint(uid))
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	response.Success(c.Writer, "success", msgs)
+}
+
+// GetMsgLatest
+// @Tags 聊天模块
+// @Summary 获取与特定用户相关的最后一条聊天记录
+// @Param uid query string true "用户id"
+// @Param target query string true "对象id"
+// @Success 200 {object} response.Response
+// @Router /chat/latest [get]
+func GetMsgLatest(c *gin.Context) {
+	var ms model.Message
+	id := c.Query("uid")
+	uid, err := strconv.ParseUint(id, 10, 64)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	t := c.Query("target")
+	target, err := strconv.ParseUint(t, 10, 64)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	msg, err := ms.GetLatestMsg(uint(uid), uint(target))
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 400)
+		return
+	}
+	response.Success(c.Writer, "success", msg)
+}

+ 32 - 0
trading-go/controller/goodscontroller.go

@@ -31,6 +31,7 @@ import (
 // @Success 200 {object} response.Response
 // @Router /goods/create [post]
 func CreatGoods(c *gin.Context) {
+	var pic model.Pic
 	var goodsJson model.GoodsJson
 	var category model.CategoryOfGoods
 	err := c.ShouldBindJSON(&goodsJson)
@@ -49,6 +50,7 @@ func CreatGoods(c *gin.Context) {
 	go util.NewItem(id, uint(time.Now().Unix()), goodsJson.Title, goodsJson.Desc)
 	go util.NewIndex(id, goodsJson.Desc+goodsJson.Title)
 	err = category.Save(id, goodsJson.Categories)
+	err = pic.Save(id, goodsJson.Pic)
 	if err != nil {
 		msg := err.Error()
 		response.Fail(c.Writer, msg, 500)
@@ -193,6 +195,7 @@ func ReviseGoods(c *gin.Context) {
 // @Router /goods/detail/{id} [get]
 func GetGoodDetail(c *gin.Context) {
 	var goods model.Goods
+	var pic model.Pic
 	ids := c.Param("id")
 	uids := c.Query("uid")
 	ts := c.Query("date")
@@ -205,6 +208,8 @@ func GetGoodDetail(c *gin.Context) {
 	}
 	goods.Id = uint(id)
 	err = goods.GetDetail()
+	pics, err := pic.GetGoodsPic(uint(id))
+	goods.Pic = pics
 	if err != nil {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
@@ -305,3 +310,30 @@ func GetGoodsCategory(c *gin.Context) {
 	}
 	response.Success(c.Writer, "success", rsp)
 }
+
+// GetGoodsList
+// @Tags 商品模块
+// @Summary 批量获取商品信息
+// @Produce application/json
+// @Param id body []string true "商品id列表"
+// @Success 200 {object} response.Response
+// @Router /goods/list [post]
+func GetGoodsList(c *gin.Context) {
+	var g model.GoodsSurface
+	jsonData := struct {
+		Id []uint `json:"id"`
+	}{}
+	err := c.ShouldBindJSON(&jsonData)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	goodsInfo, err := g.GetGoodsList(jsonData.Id)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	response.Success(c.Writer, "success", gin.H{"goods": goodsInfo})
+}

+ 0 - 7
trading-go/controller/piccontrller.go

@@ -47,14 +47,7 @@ func Upload(c *gin.Context) {
 		return
 	}
 	url := "http://" + c.Request.Host + path
-	pic.Name = file.Filename
 	pic.Url = url
-	err = pic.Save()
-	if err != nil {
-		msg := err.Error()
-		response.Fail(c.Writer, msg, 500)
-		return
-	}
 	response.Success(c.Writer, "success", pic)
 }
 

+ 2 - 1
trading-go/controller/relationcontroller.go

@@ -19,6 +19,7 @@ import (
 func RCreat(c *gin.Context) {
 	var relationJson model.RelationJson
 	err := c.ShouldBindJSON(&relationJson)
+	fmt.Println(relationJson)
 	if err != nil {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
@@ -53,7 +54,7 @@ func GetFriend(c *gin.Context) {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
 	}
-	response.Success(c.Writer, "success", friends)
+	response.Success(c.Writer, "success", gin.H{"fUid": friends})
 }
 
 // GetBadRelation

+ 28 - 7
trading-go/controller/usercontroller.go

@@ -2,7 +2,6 @@ package controller
 
 import (
 	"errors"
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"strconv"
 	"trading-go/model"
@@ -21,7 +20,6 @@ import (
 func Register(c *gin.Context) {
 	var userJ model.UserJson
 	err := c.ShouldBindJSON(&userJ)
-	fmt.Println(userJ)
 	if err != nil {
 		msg := err.Error()
 		response.Fail(c.Writer, msg, 500)
@@ -75,7 +73,6 @@ func Login(c *gin.Context) {
 	var user model.User
 	user.Vid = c.PostForm("vid")
 	err, nu := user.Login()
-	fmt.Printf("%v", user.Vid)
 	if err != nil && err.Error() == "sql: no rows in result set" {
 		err = util.NoSuchUserError
 		msg := err.Error()
@@ -97,7 +94,6 @@ func Login(c *gin.Context) {
 		"token":     token,
 		"user_info": nu,
 	}
-	fmt.Println(data)
 	response.Success(c.Writer, "success", data)
 }
 
@@ -112,7 +108,6 @@ func Login(c *gin.Context) {
 func ModifyUser(c *gin.Context) {
 	var userJ model.UserJson
 	err := c.ShouldBindJSON(&userJ)
-	fmt.Printf("%#v", userJ)
 	user := userJ.Change()
 	if err != nil {
 		msg := err.Error()
@@ -154,7 +149,6 @@ func ModifyUser(c *gin.Context) {
 func UserInfo(c *gin.Context) {
 	var u model.User
 	token := c.GetHeader("Authorization")
-	fmt.Println(token)
 	t, claim, err := util.ParseToken(token)
 	if err != nil {
 		response.Fail(c.Writer, "failed to parse token", 500)
@@ -166,7 +160,6 @@ func UserInfo(c *gin.Context) {
 	}
 	u.Uid = claim.UserId
 	nu, err := u.Info()
-	fmt.Printf("%v", nu)
 	if err != nil || nu.Vid == "" {
 		response.Fail(c.Writer, "failed", 500)
 	}
@@ -208,3 +201,31 @@ func GetUserPaged(c *gin.Context) {
 	}
 	response.Success(c.Writer, "success", rsp)
 }
+
+// GetUserList
+// @Tags 用户模块
+// @Summary 批量获取用户信息
+// @Produce application/json
+// @Param uid body []string true "用户id列表"
+// @Success 200 {object} response.Response
+// @Router /user/list [post]
+func GetUserList(c *gin.Context) {
+	var u model.User
+	jsonData := struct {
+		Uid []string `json:"uid"`
+	}{}
+	err := c.ShouldBindJSON(&jsonData)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	userInfo, err := u.GetUserList(jsonData.Uid)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+
+		return
+	}
+	response.Success(c.Writer, "success", gin.H{"users": userInfo})
+}

+ 146 - 14
trading-go/docs/docs.go

@@ -310,6 +310,63 @@ const docTemplate = `{
                 }
             }
         },
+        "/chat/latest": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取与特定用户相关的最后一条聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "对象id",
+                        "name": "target",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/msg/": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取与特定用户相关的所有聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/chat/to/{page}/{pageSize}": {
             "get": {
                 "tags": [
@@ -494,6 +551,39 @@ const docTemplate = `{
                 }
             }
         },
+        "/goods/list": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "批量获取商品信息",
+                "parameters": [
+                    {
+                        "description": "商品id列表",
+                        "name": "id",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "type": "string"
+                            }
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/goods/recommend": {
             "get": {
                 "produces": [
@@ -1123,6 +1213,39 @@ const docTemplate = `{
                 }
             }
         },
+        "/user/list": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "批量获取用户信息",
+                "parameters": [
+                    {
+                        "description": "用户id列表",
+                        "name": "uid",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "type": "string"
+                            }
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/user/login": {
             "post": {
                 "produces": [
@@ -1316,14 +1439,14 @@ const docTemplate = `{
                 "id": {
                     "type": "integer"
                 },
-                "integrity": {
-                    "type": "integer"
-                },
                 "ownerId": {
                     "type": "integer"
                 },
-                "picId": {
-                    "type": "integer"
+                "pic": {
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
                 },
                 "place": {
                     "type": "string"
@@ -1351,14 +1474,14 @@ const docTemplate = `{
                 "desc": {
                     "type": "string"
                 },
-                "integrity": {
-                    "type": "integer"
-                },
                 "ownerId": {
                     "type": "integer"
                 },
-                "pic_id": {
-                    "type": "integer"
+                "pic": {
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
                 },
                 "place": {
                     "type": "string"
@@ -1400,11 +1523,16 @@ const docTemplate = `{
         "model.RelationJson": {
             "type": "object",
             "properties": {
-                "owner": {
+                "goodsId": {
                     "type": "integer"
                 },
+                "owner": {
+                    "type": "string",
+                    "example": "0"
+                },
                 "target": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "type": {
                     "type": "integer"
@@ -1427,7 +1555,8 @@ const docTemplate = `{
                     "type": "string"
                 },
                 "uid": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "vid": {
                     "type": "string"
@@ -1449,6 +1578,9 @@ const docTemplate = `{
                 "sign": {
                     "type": "string"
                 },
+                "uid": {
+                    "type": "string"
+                },
                 "vid": {
                     "type": "string"
                 }
@@ -1472,7 +1604,7 @@ const docTemplate = `{
 // SwaggerInfo holds exported Swagger Info so clients can modify it
 var SwaggerInfo = &swag.Spec{
 	Version:          "1.0",
-	Host:             "192.168.31.28:8084",
+	Host:             "192.168.31.30:8084",
 	BasePath:         "/WeChatTrading/trading-go",
 	Schemes:          []string{},
 	Title:            "二手交易",

+ 146 - 14
trading-go/docs/swagger.json

@@ -11,7 +11,7 @@
         },
         "version": "1.0"
     },
-    "host": "192.168.31.28:8084",
+    "host": "192.168.31.30:8084",
     "basePath": "/WeChatTrading/trading-go",
     "paths": {
         "/appraise/create": {
@@ -303,6 +303,63 @@
                 }
             }
         },
+        "/chat/latest": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取与特定用户相关的最后一条聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "对象id",
+                        "name": "target",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/chat/msg/": {
+            "get": {
+                "tags": [
+                    "聊天模块"
+                ],
+                "summary": "获取与特定用户相关的所有聊天记录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/chat/to/{page}/{pageSize}": {
             "get": {
                 "tags": [
@@ -487,6 +544,39 @@
                 }
             }
         },
+        "/goods/list": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "商品模块"
+                ],
+                "summary": "批量获取商品信息",
+                "parameters": [
+                    {
+                        "description": "商品id列表",
+                        "name": "id",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "type": "string"
+                            }
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/goods/recommend": {
             "get": {
                 "produces": [
@@ -1116,6 +1206,39 @@
                 }
             }
         },
+        "/user/list": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "批量获取用户信息",
+                "parameters": [
+                    {
+                        "description": "用户id列表",
+                        "name": "uid",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "type": "string"
+                            }
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/user/login": {
             "post": {
                 "produces": [
@@ -1309,14 +1432,14 @@
                 "id": {
                     "type": "integer"
                 },
-                "integrity": {
-                    "type": "integer"
-                },
                 "ownerId": {
                     "type": "integer"
                 },
-                "picId": {
-                    "type": "integer"
+                "pic": {
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
                 },
                 "place": {
                     "type": "string"
@@ -1344,14 +1467,14 @@
                 "desc": {
                     "type": "string"
                 },
-                "integrity": {
-                    "type": "integer"
-                },
                 "ownerId": {
                     "type": "integer"
                 },
-                "pic_id": {
-                    "type": "integer"
+                "pic": {
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
                 },
                 "place": {
                     "type": "string"
@@ -1393,11 +1516,16 @@
         "model.RelationJson": {
             "type": "object",
             "properties": {
-                "owner": {
+                "goodsId": {
                     "type": "integer"
                 },
+                "owner": {
+                    "type": "string",
+                    "example": "0"
+                },
                 "target": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "type": {
                     "type": "integer"
@@ -1420,7 +1548,8 @@
                     "type": "string"
                 },
                 "uid": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "vid": {
                     "type": "string"
@@ -1442,6 +1571,9 @@
                 "sign": {
                     "type": "string"
                 },
+                "uid": {
+                    "type": "string"
+                },
                 "vid": {
                     "type": "string"
                 }

+ 98 - 12
trading-go/docs/swagger.yaml

@@ -41,12 +41,12 @@ definitions:
         type: string
       id:
         type: integer
-      integrity:
-        type: integer
       ownerId:
         type: integer
-      picId:
-        type: integer
+      pic:
+        items:
+          type: string
+        type: array
       place:
         type: string
       price:
@@ -64,12 +64,12 @@ definitions:
         type: array
       desc:
         type: string
-      integrity:
-        type: integer
       ownerId:
         type: integer
-      pic_id:
-        type: integer
+      pic:
+        items:
+          type: string
+        type: array
       place:
         type: string
       price:
@@ -96,10 +96,14 @@ definitions:
     type: object
   model.RelationJson:
     properties:
-      owner:
+      goodsId:
         type: integer
+      owner:
+        example: "0"
+        type: string
       target:
-        type: integer
+        example: "0"
+        type: string
       type:
         type: integer
     type: object
@@ -114,7 +118,8 @@ definitions:
       sign:
         type: string
       uid:
-        type: integer
+        example: "0"
+        type: string
       vid:
         type: string
     type: object
@@ -128,6 +133,8 @@ definitions:
         type: string
       sign:
         type: string
+      uid:
+        type: string
       vid:
         type: string
     type: object
@@ -139,7 +146,7 @@ definitions:
       message:
         type: string
     type: object
-host: 192.168.31.28:8084
+host: 192.168.31.30:8084
 info:
   contact: {}
   description: 一个基于微信小程序的校园二手交易平台的api文档
@@ -336,6 +343,43 @@ paths:
       summary: 获取未过期且来源为特定用户的聊天记录
       tags:
       - 聊天模块
+  /chat/latest:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: string
+      - description: 对象id
+        in: query
+        name: target
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取与特定用户相关的最后一条聊天记录
+      tags:
+      - 聊天模块
+  /chat/msg/:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: uid
+        required: true
+        type: string
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 获取与特定用户相关的所有聊天记录
+      tags:
+      - 聊天模块
   /chat/to/{page}/{pageSize}:
     get:
       parameters:
@@ -480,6 +524,27 @@ paths:
       summary: 获取商品详细信息
       tags:
       - 商品模块
+  /goods/list:
+    post:
+      parameters:
+      - description: 商品id列表
+        in: body
+        name: id
+        required: true
+        schema:
+          items:
+            type: string
+          type: array
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 批量获取商品信息
+      tags:
+      - 商品模块
   /goods/recommend:
     get:
       parameters:
@@ -887,6 +952,27 @@ paths:
       summary: 获取用户信息
       tags:
       - 用户模块
+  /user/list:
+    post:
+      parameters:
+      - description: 用户id列表
+        in: body
+        name: uid
+        required: true
+        schema:
+          items:
+            type: string
+          type: array
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 批量获取用户信息
+      tags:
+      - 用户模块
   /user/login:
     post:
       parameters:

+ 1 - 1
trading-go/main.go

@@ -15,7 +15,7 @@ import (
 // @license.name Apache 2.0
 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
 
-// @host 192.168.31.28:8084
+// @host 192.168.31.30:8084
 // @BasePath /WeChatTrading/trading-go
 func main() {
 

+ 54 - 47
trading-go/model/goods.go

@@ -9,70 +9,65 @@ import (
 )
 
 type Goods struct {
-	Id        uint   `db:"id"`
-	Pic       string `db:"pic"`
-	OwnerId   uint   `db:"owner_id"`
-	Desc      string `db:"desc"`
-	Title     string `db:"title"`
-	Price     uint   `db:"price"`
-	Integrity int    `db:"integrity"`
-	Place     string `db:"place"`
-	State     int    `db:"state"`
+	Id      uint   `db:"id"`
+	OwnerId uint   `db:"owner_id"`
+	Desc    string `db:"desc"`
+	Title   string `db:"title"`
+	Price   uint   `db:"price"`
+	Place   string `db:"place"`
+	State   int    `db:"state"`
+	Pic     []string
 }
 
 type GoodsJson struct {
-	Pic        string `json:"pic"`
-	OwnerId    uint   `json:"ownerId"`
-	Desc       string `json:"desc"`
-	Title      string `json:"title"`
-	Price      uint   `json:"price"`
-	Integrity  int    `json:"integrity"`
-	Place      string `json:"place"`
-	Categories []uint `json:"categories"`
-	State      int    `json:"state"`
+	OwnerId    uint     `json:"ownerId"`
+	Desc       string   `json:"desc"`
+	Title      string   `json:"title"`
+	Price      uint     `json:"price"`
+	Place      string   `json:"place"`
+	Categories []uint   `json:"categories"`
+	State      int      `json:"state"`
+	Pic        []string `json:"pic"`
 }
 
 type GoodsSurfaceJson struct {
-	Pic       string `json:"pic"`
-	OwnerId   uint   `json:"ownerId"`
-	Title     string `json:"title"`
-	Price     uint   `json:"price"`
-	Integrity int    `json:"integrity"`
-	State     int    `json:"state"`
+	Pic     string `json:"pic"`
+	OwnerId uint   `json:"ownerId"`
+	Title   string `json:"title"`
+	Price   uint   `json:"price"`
+	State   int    `json:"state"`
 }
 
 type GoodsSurface struct {
-	Id        uint   `db:"id"`
-	Pic       string `db:"pic"`
-	OwnerId   uint   `db:"owner_id"`
-	Title     string `db:"title"`
-	Price     uint   `db:"price"`
-	Integrity int    `db:"integrity"`
-	State     int    `db:"state"`
+	Id      uint   `db:"id"`
+	Pic     string `db:"pic"`
+	OwnerId uint   `db:"owner_id"`
+	Title   string `db:"title"`
+	Price   uint   `db:"price"`
+	State   int    `db:"state"`
 }
 
 func (g *GoodsJson) Change() Goods {
 	return Goods{
-		Pic:       g.Pic,
-		OwnerId:   g.OwnerId,
-		Desc:      g.Desc,
-		Title:     g.Title,
-		Price:     g.Price,
-		Integrity: g.Integrity,
-		Place:     g.Place,
-		State:     g.State,
+		Pic:     g.Pic,
+		OwnerId: g.OwnerId,
+		Desc:    g.Desc,
+		Title:   g.Title,
+		Price:   g.Price,
+		Place:   g.Place,
+		State:   g.State,
 	}
 }
 
 func (g *Goods) Create() (id uint, err error) {
 	db := common.DB
-	sqlStr := "INSERT INTO goods(pic, owner_id, `desc`, title, price, integrity, place, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
-	_, err = db.Exec(sqlStr, g.Pic, g.OwnerId, g.Desc, g.Title, g.Price, g.Integrity, g.Place, g.State)
+	sqlStr := "INSERT INTO goods(owner_id, `desc`, title, price, place, state) VALUES (?, ?, ?, ?, ?, ?)"
+	_, err = db.Exec(sqlStr, g.OwnerId, g.Desc, g.Title, g.Price, g.Place, g.State)
 	if err != nil {
 		return
 	}
-	sqlStr = "INSERT INTO goods_surfaces(pic, owner_id, title, price, integrity, state) VALUES (?, ?, ?, ?, ?, ?)"
-	exec, err := db.Exec(sqlStr, g.Pic, g.OwnerId, g.Title, g.Price, g.Integrity, g.State)
+	sqlStr = "INSERT INTO goods_surfaces(pic, owner_id, title, price, state) VALUES (?, ?, ?, ?, ?)"
+	exec, err := db.Exec(sqlStr, g.Pic[0], g.OwnerId, g.Title, g.Price, g.State)
 	if err != nil {
 		return
 	}
@@ -119,13 +114,13 @@ func (g *GoodsSurface) GetCnt() (cnt int, err error) {
 
 func (g *Goods) Revise() error {
 	db := common.DB
-	sqlStr := "UPDATE goods SET pic = ?, owner_id = ?, `desc` = ?, title = ?, price = ?, integrity = ?, place = ?, state = ? WHERE id = ?"
-	_, err := db.Exec(sqlStr, g.Pic, g.OwnerId, g.Desc, g.Title, g.Price, g.Integrity, g.Place, g.State, g.Id)
+	sqlStr := "UPDATE goods SET pic = ?, owner_id = ?, `desc` = ?, title = ?, price = ?, place = ?, state = ? WHERE id = ?"
+	_, err := db.Exec(sqlStr, g.Pic, g.OwnerId, g.Desc, g.Title, g.Price, g.Place, g.State, g.Id)
 	if err != nil {
 		return err
 	}
-	sqlStr = "UPDATE goods_surfaces SET pic = ?, owner_id = ?, title = ?, price = ?, integrity = ?, state = ? WHERE id = ?"
-	_, err = db.Exec(sqlStr, g.Pic, g.OwnerId, g.Title, g.Price, g.Integrity, g.State, g.Id)
+	sqlStr = "UPDATE goods_surfaces SET pic = ?, owner_id = ?, title = ?, price = ?, state = ? WHERE id = ?"
+	_, err = db.Exec(sqlStr, g.Pic, g.OwnerId, g.Title, g.Price, g.State, g.Id)
 	return err
 }
 
@@ -152,6 +147,7 @@ func (g *GoodsSurface) GetCategoryPaged(page, pageSize int, category uint) (rsp
 	rsp.PageSize = pageSize
 	sqlStr := "SELECT goods_id FROM category_of_goods WHERE category_id = ?"
 	err = db.Select(&goodsIds, sqlStr, category)
+	fmt.Println(goodsIds)
 	if err != nil {
 		return
 	}
@@ -214,3 +210,14 @@ func (g *GoodsSurface) GetRecommend(id uint, size int) (goods []GoodsSurface, er
 	err = db.Select(&goods, query, args...)
 	return
 }
+
+func (g *GoodsSurface) GetGoodsList(id []uint) (goods []GoodsSurface, err error) {
+	db := common.DB
+	sqlStr := "SELECT * FROM goods_surfaces WHERE id IN (?)"
+	query, args, err := sqlx.In(sqlStr, id)
+	if err != nil {
+		return nil, err
+	}
+	err = db.Select(&goods, query, args...)
+	return
+}

+ 49 - 3
trading-go/model/message.go

@@ -7,13 +7,14 @@ import (
 	"time"
 	"trading-go/common"
 	"trading-go/response"
+	"trading-go/util"
 )
 
 type Message struct {
 	MsgType int  `json:"msgType"`
-	From    uint `json:"from"`
-	To      uint `json:"to"`
-	Time    uint `json:"time"`
+	From    uint `json:"from,string"`
+	To      uint `json:"to,string"`
+	Time    uint `json:"time,string"`
 	Content any  `json:"content"`
 }
 
@@ -76,6 +77,20 @@ func (m Message) GetFrom(uid uint, page, pageSize int) (ms response.PageResponse
 	return
 }
 
+func (m Message) GetMsg(uid uint) (ms []Message, err error) {
+	mFrom, err := m.GetFrom(uid, 1, 10000000)
+	if err != nil {
+		return nil, err
+	}
+	mTo, err := m.GetTo(uid, 1, 10000000)
+	if err != nil {
+		return nil, err
+	}
+	s1, s2 := mFrom.Data.([]Message), mTo.Data.([]Message)
+	ms = append(s1, s2...)
+	return ms, nil
+}
+
 func (m Message) GetTo(uid uint, page, pageSize int) (ms response.PageResponse, err error) {
 	var mess []Message
 	if page == 1 {
@@ -112,3 +127,34 @@ func (m Message) GetTo(uid uint, page, pageSize int) (ms response.PageResponse,
 	ms.Page = page
 	return
 }
+
+func (m Message) GetLatestMsg(uid, target uint) (msg Message, err error) {
+	mFrom, err := m.GetFrom(uid, 1, 10000000)
+	if err != nil {
+		return Message{}, err
+	}
+	mTo, err := m.GetTo(uid, 1, 10000000)
+	if err != nil {
+		return Message{}, err
+	}
+	s1, s2 := mFrom.Data.([]Message), mTo.Data.([]Message)
+	ms := append(s1, s2...)
+	if len(ms) == 0 {
+		return Message{}, util.NoMessageError
+	}
+	last := -1
+	for i := range ms {
+		if ms[i].From != target && ms[i].To != target {
+			continue
+		}
+		if last == -1 {
+			last = i
+		} else if ms[i].Time > ms[last].Time {
+			last = i
+		}
+	}
+	if last == -1 {
+		return Message{}, util.NoMessageError
+	}
+	return ms[last], nil
+}

+ 17 - 13
trading-go/model/pic.go

@@ -6,23 +6,20 @@ import (
 )
 
 type Pic struct {
-	Id   uint   `db:"id"`
-	Name string `db:"name"`
-	Url  string `db:"url"`
+	Id      uint   `db:"id"`
+	Url     string `db:"url"`
+	GoodsId uint   `db:"goods_id"`
 }
 
-func (p *Pic) Save() error {
+func (p *Pic) Save(uid uint, pics []string) error {
 	db := common.DB
-	sqlStr := "INSERT INTO pics(name, url) VALUES (:name, :url)"
-	exec, err := db.NamedExec(sqlStr, p)
-	if err != nil {
-		return err
+	sqlStr := "INSERT INTO pics(url, goods_id) VALUES (?, ?)"
+	for _, pic := range pics {
+		_, err := db.Exec(sqlStr, uid, pic)
+		if err != nil {
+			return err
+		}
 	}
-	id, err := exec.LastInsertId()
-	if err != nil {
-		return err
-	}
-	p.Id = uint(id)
 	return nil
 }
 
@@ -57,3 +54,10 @@ func (p *Pic) GetCnt() (cnt int, err error) {
 	err = db.Get(&cnt, sqlStr)
 	return
 }
+
+func (p *Pic) GetGoodsPic(id uint) (pics []string, err error) {
+	db := common.DB
+	sqlStr := "SELECT url FROM pics WHERE goods_id = ?"
+	err = db.Select(&pics, sqlStr, id)
+	return
+}

+ 17 - 14
trading-go/model/relation.go

@@ -7,29 +7,32 @@ import (
 )
 
 type Relation struct {
-	Id     uint `db:"id"`
-	Owner  uint `db:"owner"`
-	Target uint `db:"target"`
-	Type   int  `db:"type"`
+	Id      uint `db:"id"`
+	Owner   uint `db:"owner"`
+	Target  uint `db:"target"`
+	GoodsId uint `db:"goods_id"`
+	Type    int  `db:"type"`
 }
 
 type RelationJson struct {
-	Owner  uint `json:"owner"`
-	Target uint `json:"target"`
-	Type   int  `json:"type"`
+	Owner   uint `json:"owner,string" db:"owner"`
+	Target  uint `json:"target,string" db:"target"`
+	GoodsId uint `json:"goodsId" db:"goods_id"`
+	Type    int  `json:"type" db:"type"`
 }
 
 func (r RelationJson) Change() Relation {
 	return Relation{
-		Owner:  r.Owner,
-		Target: r.Target,
-		Type:   r.Type,
+		Owner:   r.Owner,
+		Target:  r.Target,
+		Type:    r.Type,
+		GoodsId: r.GoodsId,
 	}
 }
 
 func (r Relation) Creat() error {
 	db := common.DB
-	sqlStr := "INSERT INTO relations(owner, target, type) VALUES (:owner, :target, :type)"
+	sqlStr := "INSERT INTO relations(owner, target, type, goods_id) VALUES (:owner, :target, :type, :goods_id)"
 	rows, err := db.NamedExec(sqlStr, r)
 	if err != nil {
 		return err
@@ -41,10 +44,10 @@ func (r Relation) Creat() error {
 	return err
 }
 
-func (r Relation) Friend(uid int) ([]int64, error) {
-	var friends []int64
+func (r Relation) Friend(uid int) ([]RelationJson, error) {
+	var friends []RelationJson
 	db := common.DB
-	sqlStr := "SELECT target From relations WHERE owner = ? AND type = 1"
+	sqlStr := "SELECT owner, target, type, goods_id From relations WHERE owner = ? AND type = 1"
 	err := db.Select(&friends, sqlStr, uid)
 	return friends, err
 }

+ 12 - 0
trading-go/model/user.go

@@ -2,6 +2,7 @@ package model
 
 import (
 	"fmt"
+	"github.com/jmoiron/sqlx"
 	"strconv"
 	"trading-go/common"
 	"trading-go/response"
@@ -170,3 +171,14 @@ func (u User) GetUser() (user User) {
 	_ = db.Get(&user, sqlStr, u.Uid)
 	return
 }
+
+func (u User) GetUserList(uid []string) (users []User, err error) {
+	db := common.DB
+	sqlStr := "SELECT * FROM users WHERE uid IN (?)"
+	query, args, err := sqlx.In(sqlStr, uid)
+	if err != nil {
+		return nil, err
+	}
+	err = db.Select(&users, query, args...)
+	return
+}

BIN
trading-go/pics/1699375397UN3eFHEVeEtEb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699376791kDvVkMDqGaKjb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699376842DbDkdnl78sbBb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699377248GdPib7YWQsXAb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699378552vxHfGwZXkePTb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699378578JPJKVU20yj8xb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699378604WzGV4QEYsyqzb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/16993786734xio8nxv2TFNb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699378762ThBCYkhdz9zqb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/16993787821A2FjRLvVruhb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699378849dxutdmTao1rOb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699378868UNzjT86U9mZrb1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699379040BxHIa2rdXr7Ab1493fda534929a5b5d05f80a8cf3d16.jpg


BIN
trading-go/pics/1699379135EcsSvbvLkVhTb1493fda534929a5b5d05f80a8cf3d16.jpg


+ 4 - 0
trading-go/routine/routine.go

@@ -28,6 +28,7 @@ func GetRoutine() *gin.Engine {
 		user.POST("modify", controller.ModifyUser)
 		user.POST("login", controller.Login)
 		user.POST("register", controller.Register)
+		user.POST("list", controller.GetUserList)
 	}
 
 	chat := r.Group("chat")
@@ -35,6 +36,8 @@ func GetRoutine() *gin.Engine {
 		chat.GET("", controller.LinkToServer)
 		chat.GET("from/:page/:pageSize", controller.GetMsgFromPaged)
 		chat.GET("to/:page/:pageSize", controller.GetMsgToPaged)
+		chat.GET("msg", controller.GetMsg)
+		chat.GET("latest", controller.GetMsgLatest)
 	}
 	relation := r.Group("relation")
 	{
@@ -71,6 +74,7 @@ func GetRoutine() *gin.Engine {
 		goods.GET("detail/:id", controller.GetGoodDetail)
 		goods.GET("user/:id", controller.GetUserGoods)
 		goods.GET("search/:page/:pageSize", controller.SearchGoods)
+		goods.POST("list", controller.GetGoodsList)
 		goods.GET("category/:page/:pageSize", controller.GetGoodsCategory)
 	}
 

+ 1 - 0
trading-go/util/error.go

@@ -9,6 +9,7 @@ var (
 	UpdateFailError  = errors.New("fail to update")
 	PhoneFormatError = errors.New("phone format error")
 	NoSuchGoodsError = errors.New("no such goods")
+	NoMessageError   = errors.New("no message")
 	NoRecommendError = errors.New("no recommend")
 	ImgFormatError   = errors.New("img format error")
 )

+ 1 - 1
trading-go/util/search.go

@@ -35,7 +35,7 @@ func init() {
 
 func NewIndex(ID uint, doc string) {
 	searcher.Index(fmt.Sprintf("%d", ID), types.DocData{Content: doc}, true)
-	fmt.Println("[search engine] ----->>> ok")
+	fmt.Println("[search engine] ----->>> " + doc + "ok")
 	searcher.Flush()
 }