May1145 1 жил өмнө
parent
commit
def2c64ff0
36 өөрчлөгдсөн 367 нэмэгдсэн , 201 устгасан
  1. 1 1
      trading-go/common/database.go
  2. 1 1
      trading-go/config/config.yml
  3. 6 13
      trading-go/controller/goodscontroller.go
  4. 1 1
      trading-go/controller/ordercontroller.go
  5. 29 2
      trading-go/controller/usercontroller.go
  6. 53 13
      trading-go/docs/docs.go
  7. 52 13
      trading-go/docs/swagger.json
  8. 35 10
      trading-go/docs/swagger.yaml
  9. 2 13
      trading-go/go.mod
  10. 3 30
      trading-go/go.sum
  11. 1 2
      trading-go/main.go
  12. 19 8
      trading-go/model/goods.go
  13. 7 5
      trading-go/model/orders.go
  14. 154 0
      trading-go/model/recommend.go
  15. 2 2
      trading-go/model/user.go
  16. BIN
      trading-go/pics/17026291282u3VVWKPLyQhdce75ebb26860c9184474d8244e28d16.png
  17. BIN
      trading-go/pics/1702629188lP06022RjVfJdce75ebb26860c9184474d8244e28d16.png
  18. BIN
      trading-go/pics/1702629267nl91VEi2eIpBdce75ebb26860c9184474d8244e28d16.png
  19. BIN
      trading-go/pics/1702629388JKUuDUAu1dQhdce75ebb26860c9184474d8244e28d16.png
  20. BIN
      trading-go/pics/1702629488YNp2BpoRCjzqdce75ebb26860c9184474d8244e28d16.png
  21. BIN
      trading-go/pics/1702629855KZ6cCG2WC0qSdce75ebb26860c9184474d8244e28d16.png
  22. BIN
      trading-go/pics/1702630145Nq4Mq8PD4vtedce75ebb26860c9184474d8244e28d16.png
  23. BIN
      trading-go/pics/1702630539J37Nz6WJaFNpdce75ebb26860c9184474d8244e28d16.png
  24. BIN
      trading-go/pics/17026309926EomSaZQMBYUdce75ebb26860c9184474d8244e28d16.png
  25. BIN
      trading-go/pics/1702631231Vw1S8D48tGkQdce75ebb26860c9184474d8244e28d16.png
  26. BIN
      trading-go/pics/1702631414awSmQm1CZSHZdce75ebb26860c9184474d8244e28d16.png
  27. BIN
      trading-go/pics/1702631790HkBcZtgzuyc0dce75ebb26860c9184474d8244e28d16.png
  28. BIN
      trading-go/pics/17027252157NtB9WS5RdaUdce75ebb26860c9184474d8244e28d16.png
  29. BIN
      trading-go/pics/1702725218R8pSJsY5DOxN7baafd97122013df4eefc138a9d491e4.png
  30. BIN
      trading-go/pics/1702725395BoEekRVVTjajdce75ebb26860c9184474d8244e28d16.png
  31. BIN
      trading-go/pics/1702725398gzg2s4VcPuUI7baafd97122013df4eefc138a9d491e4.png
  32. BIN
      trading-go/pics/170272852515dnT7auvXXQdce75ebb26860c9184474d8244e28d16.png
  33. BIN
      trading-go/pics/1702728654XzGWwMSLfVRVdce75ebb26860c9184474d8244e28d16.png
  34. BIN
      trading-go/pics/1702728775P2HKiUnquJttdce75ebb26860c9184474d8244e28d16.png
  35. 1 0
      trading-go/routine/routine.go
  36. 0 87
      trading-go/util/recommend.go

+ 1 - 1
trading-go/common/database.go

@@ -2,7 +2,7 @@ package common
 
 import (
 	"fmt"
-	"github.com/go-redis/redis/v8"
+	"github.com/go-redis/redis/v9"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/jmoiron/sqlx"
 	"github.com/spf13/viper"

+ 1 - 1
trading-go/config/config.yml

@@ -15,4 +15,4 @@ redis:
 time:
   time: 2023-8-16
 gorse:
-  addr: "http://47.109.143.151:8088"
+  addr: "http://127.0.0.1:8088"

+ 6 - 13
trading-go/controller/goodscontroller.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"strconv"
-	"time"
 	"trading-go/model"
 	"trading-go/response"
 	"trading-go/util"
@@ -49,7 +48,6 @@ func CreatGoods(c *gin.Context) {
 	fmt.Println(goodsJson)
 	goods := goodsJson.Change()
 	id, err := goods.Create()
-	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)
@@ -74,8 +72,6 @@ func DGoods(c *gin.Context) {
 	ids := c.Param("id")
 	id, err := strconv.Atoi(ids)
 
-	go util.DelItem(uint(id))
-
 	if err != nil {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
@@ -150,7 +146,7 @@ func GetGoodsPage(c *gin.Context) {
 // @Router /goods/recommend [get]
 func GetRecommend(c *gin.Context) {
 	var goods model.GoodsSurface
-	ids := c.Param("id")
+	ids := c.Query("id")
 	s := c.Query("size")
 	id, err := strconv.Atoi(ids)
 	size, err := strconv.Atoi(s)
@@ -201,10 +197,6 @@ func ReviseGoods(c *gin.Context) {
 		util.DelIndex(goods.Id)
 		util.NewIndex(goods.Id, goods.Desc+goods.Title)
 	}()
-	go func() {
-		util.DelItem(goods.Id)
-		util.NewItem(goods.Id, uint(time.Now().Unix()), goods.Title, goods.Desc)
-	}()
 	response.Success(c.Writer, "success", nil)
 }
 
@@ -214,7 +206,6 @@ func ReviseGoods(c *gin.Context) {
 // @Produce application/json
 // @Param id path int64 true "商品id"
 // @Param uid query int64 true "访问的用户id"
-// @Param date query int64 true "访问时间的时间戳"
 // @Success 200 {object} response.Response
 // @Router /goods/detail/{id} [get]
 func GetGoodDetail(c *gin.Context) {
@@ -222,10 +213,8 @@ func GetGoodDetail(c *gin.Context) {
 	var pic model.Pic
 	ids := c.Param("id")
 	uids := c.Query("uid")
-	ts := c.Query("date")
 	id, err := strconv.Atoi(ids)
 	uid, err := strconv.Atoi(uids)
-	date, err := strconv.Atoi(ts)
 	if err != nil {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
@@ -238,7 +227,11 @@ func GetGoodDetail(c *gin.Context) {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
 	}
-	go util.Recommend(uint(uid), uint(id), uint(date))
+	err = model.Recommend(uint(uid), uint(id))
+	if err != nil {
+		response.Fail(c.Writer, err.Error(), 500)
+		return
+	}
 	response.Success(c.Writer, "success", goods)
 }
 

+ 1 - 1
trading-go/controller/ordercontroller.go

@@ -28,7 +28,7 @@ func GetAllOrder(c *gin.Context) {
 // @Tags 订单模块
 // @Summary 获取用户的所有订单
 // @Produce application/json
-// @Param id query uint true "用户id"
+// @Param id query string true "用户id"
 // @Success 200 {object} response.Response
 // @Router /order/user [get]
 func GetUserOrder(c *gin.Context) {

+ 29 - 2
trading-go/controller/usercontroller.go

@@ -50,8 +50,6 @@ func Register(c *gin.Context) {
 
 	err = user.Register()
 
-	go util.NewUser(uint(id))
-
 	if err != nil {
 		msg := err.Error()
 		response.Fail(c.Writer, msg, 500)
@@ -62,6 +60,35 @@ func Register(c *gin.Context) {
 	}
 }
 
+type NewRec struct {
+	Uid  uint   `json:"uid"`
+	CIds []uint `json:"cIds"`
+}
+
+// NewRecommend
+// @Tags 用户模块
+// @Summary 初始化用户推荐数据
+// @Produce application/json
+// @param data body NewRec false "推荐信息"
+// @Success 200 {object} response.Response
+// @Router /user/rec/new [post]
+func NewRecommend(c *gin.Context) {
+	jsonData := NewRec{}
+	err := c.ShouldBind(&jsonData)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	err = model.NewRecommend(jsonData.Uid, jsonData.CIds)
+	if err != nil {
+		msg := err.Error()
+		response.Fail(c.Writer, msg, 500)
+		return
+	}
+	response.Success(c.Writer, "success", nil)
+}
+
 // Login
 // @Tags 用户模块
 // @Summary 登录

+ 53 - 13
trading-go/docs/docs.go

@@ -539,13 +539,6 @@ const docTemplate = `{
                         "name": "uid",
                         "in": "query",
                         "required": true
-                    },
-                    {
-                        "type": "integer",
-                        "description": "访问时间的时间戳",
-                        "name": "date",
-                        "in": "query",
-                        "required": true
                     }
                 ],
                 "responses": {
@@ -884,7 +877,7 @@ const docTemplate = `{
                 "summary": "获取用户的所有订单",
                 "parameters": [
                     {
-                        "type": "integer",
+                        "type": "string",
                         "description": "用户id",
                         "name": "id",
                         "in": "query",
@@ -1313,6 +1306,35 @@ const docTemplate = `{
                 }
             }
         },
+        "/user/rec/new": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "初始化用户推荐数据",
+                "parameters": [
+                    {
+                        "description": "推荐信息",
+                        "name": "data",
+                        "in": "body",
+                        "schema": {
+                            "$ref": "#/definitions/controller.NewRec"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/user/register": {
             "post": {
                 "consumes": [
@@ -1383,6 +1405,20 @@ const docTemplate = `{
         }
     },
     "definitions": {
+        "controller.NewRec": {
+            "type": "object",
+            "properties": {
+                "cIds": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "uid": {
+                    "type": "integer"
+                }
+            }
+        },
         "model.Appraise": {
             "type": "object",
             "properties": {
@@ -1447,7 +1483,8 @@ const docTemplate = `{
                     "type": "integer"
                 },
                 "ownerId": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "pic": {
                     "type": "array",
@@ -1482,7 +1519,8 @@ const docTemplate = `{
                     "type": "string"
                 },
                 "ownerId": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "pic": {
                     "type": "array",
@@ -1508,7 +1546,8 @@ const docTemplate = `{
             "type": "object",
             "properties": {
                 "buyerId": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "goodsId": {
                     "type": "integer"
@@ -1586,7 +1625,8 @@ const docTemplate = `{
                     "type": "string"
                 },
                 "uid": {
-                    "type": "string"
+                    "type": "string",
+                    "example": ""
                 },
                 "vid": {
                     "type": "string"
@@ -1611,7 +1651,7 @@ const docTemplate = `{
 // SwaggerInfo holds exported Swagger Info so clients can modify it
 var SwaggerInfo = &swag.Spec{
 	Version:          "1.0",
-	Host:             "192.168.31.27:8084",
+	Host:             "",
 	BasePath:         "/WeChatTrading/trading-go",
 	Schemes:          []string{},
 	Title:            "二手交易",

+ 52 - 13
trading-go/docs/swagger.json

@@ -11,7 +11,6 @@
         },
         "version": "1.0"
     },
-    "host": "192.168.31.27:8084",
     "basePath": "/WeChatTrading/trading-go",
     "paths": {
         "/appraise/create": {
@@ -532,13 +531,6 @@
                         "name": "uid",
                         "in": "query",
                         "required": true
-                    },
-                    {
-                        "type": "integer",
-                        "description": "访问时间的时间戳",
-                        "name": "date",
-                        "in": "query",
-                        "required": true
                     }
                 ],
                 "responses": {
@@ -877,7 +869,7 @@
                 "summary": "获取用户的所有订单",
                 "parameters": [
                     {
-                        "type": "integer",
+                        "type": "string",
                         "description": "用户id",
                         "name": "id",
                         "in": "query",
@@ -1306,6 +1298,35 @@
                 }
             }
         },
+        "/user/rec/new": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "用户模块"
+                ],
+                "summary": "初始化用户推荐数据",
+                "parameters": [
+                    {
+                        "description": "推荐信息",
+                        "name": "data",
+                        "in": "body",
+                        "schema": {
+                            "$ref": "#/definitions/controller.NewRec"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/response.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/user/register": {
             "post": {
                 "consumes": [
@@ -1376,6 +1397,20 @@
         }
     },
     "definitions": {
+        "controller.NewRec": {
+            "type": "object",
+            "properties": {
+                "cIds": {
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "uid": {
+                    "type": "integer"
+                }
+            }
+        },
         "model.Appraise": {
             "type": "object",
             "properties": {
@@ -1440,7 +1475,8 @@
                     "type": "integer"
                 },
                 "ownerId": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "pic": {
                     "type": "array",
@@ -1475,7 +1511,8 @@
                     "type": "string"
                 },
                 "ownerId": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "pic": {
                     "type": "array",
@@ -1501,7 +1538,8 @@
             "type": "object",
             "properties": {
                 "buyerId": {
-                    "type": "integer"
+                    "type": "string",
+                    "example": "0"
                 },
                 "goodsId": {
                     "type": "integer"
@@ -1579,7 +1617,8 @@
                     "type": "string"
                 },
                 "uid": {
-                    "type": "string"
+                    "type": "string",
+                    "example": ""
                 },
                 "vid": {
                     "type": "string"

+ 35 - 10
trading-go/docs/swagger.yaml

@@ -1,5 +1,14 @@
 basePath: /WeChatTrading/trading-go
 definitions:
+  controller.NewRec:
+    properties:
+      cIds:
+        items:
+          type: integer
+        type: array
+      uid:
+        type: integer
+    type: object
   model.Appraise:
     properties:
       buyerId:
@@ -42,7 +51,8 @@ definitions:
       id:
         type: integer
       ownerId:
-        type: integer
+        example: "0"
+        type: string
       pic:
         items:
           type: string
@@ -65,7 +75,8 @@ definitions:
       desc:
         type: string
       ownerId:
-        type: integer
+        example: "0"
+        type: string
       pic:
         items:
           type: string
@@ -82,7 +93,8 @@ definitions:
   model.OrderJson:
     properties:
       buyerId:
-        type: integer
+        example: "0"
+        type: string
       goodsId:
         type: integer
       phone:
@@ -134,6 +146,7 @@ definitions:
       sign:
         type: string
       uid:
+        example: ""
         type: string
       vid:
         type: string
@@ -146,7 +159,6 @@ definitions:
       message:
         type: string
     type: object
-host: 192.168.31.27:8084
 info:
   contact: {}
   description: 一个基于微信小程序的校园二手交易平台的api文档
@@ -514,11 +526,6 @@ paths:
         name: uid
         required: true
         type: integer
-      - description: 访问时间的时间戳
-        in: query
-        name: date
-        required: true
-        type: integer
       produces:
       - application/json
       responses:
@@ -740,7 +747,7 @@ paths:
         in: query
         name: id
         required: true
-        type: integer
+        type: string
       produces:
       - application/json
       responses:
@@ -1016,6 +1023,24 @@ paths:
       summary: 修改用户信息
       tags:
       - 用户模块
+  /user/rec/new:
+    post:
+      parameters:
+      - description: 推荐信息
+        in: body
+        name: data
+        schema:
+          $ref: '#/definitions/controller.NewRec'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/response.Response'
+      summary: 初始化用户推荐数据
+      tags:
+      - 用户模块
   /user/register:
     post:
       consumes:

+ 2 - 13
trading-go/go.mod

@@ -6,7 +6,7 @@ require (
 	github.com/gin-contrib/size v0.0.0-20230212012657-e14a14094dc4
 	github.com/gin-gonic/gin v1.9.1
 	github.com/go-ego/riot v0.0.0-20201013133145-f4c30acb3704
-	github.com/go-redis/redis/v8 v8.11.5
+	github.com/go-redis/redis/v9 v9.0.0-rc.1
 	github.com/go-sql-driver/mysql v1.7.1
 	github.com/golang-jwt/jwt v3.2.2+incompatible
 	github.com/gorilla/websocket v1.5.0
@@ -15,9 +15,6 @@ require (
 	github.com/swaggo/files v1.0.1
 	github.com/swaggo/gin-swagger v1.6.0
 	github.com/swaggo/swag v1.16.1
-	github.com/zhenghaoz/gorse v0.5.0-alpha.0.20230905121337-24d69b1426a0
-	gorm.io/driver/mysql v1.5.1
-	gorm.io/gorm v1.25.4
 )
 
 require (
@@ -34,7 +31,6 @@ require (
 	github.com/dgraph-io/ristretto v0.0.2 // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
 	github.com/dustin/go-humanize v1.0.0 // indirect
-	github.com/felixge/httpsnoop v1.0.3 // indirect
 	github.com/fsnotify/fsnotify v1.6.0 // indirect
 	github.com/gabriel-vasile/mimetype v1.4.2 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect
@@ -42,8 +38,6 @@ require (
 	github.com/go-ego/gpy v0.31.0 // indirect
 	github.com/go-ego/gse v0.50.3 // indirect
 	github.com/go-ego/murmur v0.10.0 // indirect
-	github.com/go-logr/logr v1.2.3 // indirect
-	github.com/go-logr/stdr v1.2.2 // indirect
 	github.com/go-ole/go-ole v1.2.4 // indirect
 	github.com/go-openapi/jsonpointer v0.20.0 // indirect
 	github.com/go-openapi/jsonreference v0.20.2 // indirect
@@ -58,12 +52,11 @@ require (
 	github.com/golang/protobuf v1.5.3 // indirect
 	github.com/golang/snappy v0.0.4 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
-	github.com/jinzhu/inflection v1.0.0 // indirect
-	github.com/jinzhu/now v1.1.5 // indirect
 	github.com/josharian/intern v1.0.0 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
 	github.com/klauspost/cpuid/v2 v2.2.5 // indirect
 	github.com/leodido/go-urn v1.2.4 // indirect
+	github.com/lib/pq v1.10.6 // indirect
 	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
 	github.com/mattn/go-isatty v0.0.19 // indirect
@@ -83,10 +76,6 @@ require (
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 	github.com/ugorji/go/codec v1.2.11 // indirect
 	go.etcd.io/bbolt v1.3.4 // indirect
-	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 // indirect
-	go.opentelemetry.io/otel v1.11.1 // indirect
-	go.opentelemetry.io/otel/metric v0.33.0 // indirect
-	go.opentelemetry.io/otel/trace v1.11.1 // indirect
 	golang.org/x/arch v0.4.0 // indirect
 	golang.org/x/crypto v0.11.0 // indirect
 	golang.org/x/net v0.12.0 // indirect

+ 3 - 30
trading-go/go.sum

@@ -111,8 +111,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
 github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
 github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
-github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
-github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
 github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -146,11 +144,6 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
-github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
-github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
-github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
-github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
-github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
 github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
 github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
 github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
@@ -180,11 +173,9 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91
 github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
 github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
 github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
-github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
-github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
 github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs=
+github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A=
 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
-github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
 github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
 github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@@ -283,11 +274,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
-github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
-github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
-github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
-github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
 github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
 github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
@@ -323,6 +310,7 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
 github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
 github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
+github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
 github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
@@ -357,7 +345,7 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
 github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
 github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
 github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
+github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM=
 github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
 github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
@@ -463,8 +451,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
-github.com/zhenghaoz/gorse v0.5.0-alpha.0.20230905121337-24d69b1426a0 h1:F2EDo6P92f6+wiYpP4N+g/w+Q3s2KE1AvT3Mdnf3E0s=
-github.com/zhenghaoz/gorse v0.5.0-alpha.0.20230905121337-24d69b1426a0/go.mod h1:JJucbAUvBHFPRoIJ+EOaStQsbn9NRPfx7dXh4jH1AEU=
 go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
 go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
 go.etcd.io/etcd v3.3.10+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI=
@@ -474,14 +460,6 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
-go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 h1:aUEBEdCa6iamGzg6fuYxDA8ThxvOG240mAvWDU+XLio=
-go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4/go.mod h1:l2MdsbKTocpPS5nQZscqTR9jd8u96VYZdcpF8Sye7mA=
-go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
-go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
-go.opentelemetry.io/otel/metric v0.33.0 h1:xQAyl7uGEYvrLAiV/09iTJlp1pZnQ9Wl793qbVvED1E=
-go.opentelemetry.io/otel/metric v0.33.0/go.mod h1:QlTYc+EnYNq/M2mNk1qDDMRLpqCOj2f/r5c7Fd5FYaI=
-go.opentelemetry.io/otel/trace v1.11.1 h1:ofxdnzsNrGBYXbP7t7zpUK281+go5rF7dvdIZXF8gdQ=
-go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk=
 go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
 go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
 go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
@@ -848,11 +826,6 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
-gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
-gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
-gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw=
-gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
 honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

+ 1 - 2
trading-go/main.go

@@ -15,12 +15,11 @@ import (
 // @license.name Apache 2.0
 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
 
-// @host 192.168.31.27:8084
 // @BasePath /WeChatTrading/trading-go
 func main() {
 
 	r := routine.GetRoutine()
 	port := viper.GetString("web.port")
-	fmt.Println("[api文档] =====>>> http://192.168.31.27:8084/swagger/index.html#/")
+	fmt.Println("[api文档] =====>>> http://124.222.126.172:8084/swagger/index.html#/")
 	r.Run(port)
 }

+ 19 - 8
trading-go/model/goods.go

@@ -10,7 +10,7 @@ import (
 
 type Goods struct {
 	Id      uint   `db:"id"`
-	OwnerId uint   `db:"owner_id"`
+	OwnerId uint   `db:"owner_id" json:"ownerId,string"`
 	Desc    string `db:"desc"`
 	Title   string `db:"title"`
 	Price   uint   `db:"price"`
@@ -20,7 +20,7 @@ type Goods struct {
 }
 
 type GoodsJson struct {
-	OwnerId    uint     `json:"ownerId"`
+	OwnerId    uint     `json:"ownerId,string"`
 	Desc       string   `json:"desc"`
 	Title      string   `json:"title"`
 	Price      uint     `json:"price"`
@@ -32,7 +32,7 @@ type GoodsJson struct {
 
 type GoodsSurfaceJson struct {
 	Pic     string `json:"pic"`
-	OwnerId uint   `json:"ownerId"`
+	OwnerId uint   `json:"ownerId,string"`
 	Title   string `json:"title"`
 	Price   uint   `json:"price"`
 	State   int    `json:"state"`
@@ -41,7 +41,7 @@ type GoodsSurfaceJson struct {
 type GoodsSurface struct {
 	Id      uint   `db:"id"`
 	Pic     string `db:"pic"`
-	OwnerId uint   `db:"owner_id"`
+	OwnerId uint   `db:"owner_id" json:"ownerId,string"`
 	Title   string `db:"title"`
 	Price   uint   `db:"price"`
 	State   int    `db:"state"`
@@ -62,12 +62,16 @@ func (g *GoodsJson) Change() Goods {
 func (g *Goods) Create() (id uint, err error) {
 	db := common.DB
 	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)
+	result, 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, state) VALUES (?, ?, ?, ?, ?)"
-	exec, err := db.Exec(sqlStr, g.Pic[0], g.OwnerId, g.Title, g.Price, g.State)
+	insertId, err := result.LastInsertId()
+	if err != nil {
+		return
+	}
+	sqlStr = "INSERT INTO goods_surfaces(id, pic, owner_id, title, price, state) VALUES (?, ?, ?, ?, ?, ?)"
+	exec, err := db.Exec(sqlStr, insertId, g.Pic[0], g.OwnerId, g.Title, g.Price, g.State)
 	if err != nil {
 		return
 	}
@@ -194,7 +198,7 @@ func (g *GoodsSurface) SearchPaged(key string, page, pageSize int) (rsp response
 }
 
 func (g *GoodsSurface) GetRecommend(id uint, size int) (goods []GoodsSurface, err error) {
-	ids, err := util.GetRecommend(id, size)
+	ids, err := GetRecommend(id, size)
 	db := common.DB
 	if err != nil {
 		return nil, err
@@ -221,3 +225,10 @@ func (g *GoodsSurface) GetGoodsList(id []uint) (goods []GoodsSurface, err error)
 	err = db.Select(&goods, query, args...)
 	return
 }
+
+func getGoodsIds() (ids []uint, err error) {
+	db := common.DB
+	sqlStr := "SELECT id FROM goods_surfaces"
+	err = db.Select(&ids, sqlStr)
+	return
+}

+ 7 - 5
trading-go/model/orders.go

@@ -8,7 +8,7 @@ import (
 type Order struct {
 	Id      uint   `db:"id"`
 	GoodsId uint   `db:"goods_id"`
-	BuyerId uint   `db:"buyer_id"`
+	BuyerId uint   `db:"buyer_id" json:"buyerId,string"`
 	Time    uint   `db:"time"`
 	Place   string `db:"place"`
 	Phone   string `db:"phone"`
@@ -17,7 +17,7 @@ type Order struct {
 
 type OrderJson struct {
 	GoodsId uint   `json:"goodsId"`
-	BuyerId uint   `json:"buyerId"`
+	BuyerId uint   `json:"buyerId,string"`
 	Time    uint   `json:"time"`
 	Place   string `json:"place"`
 	Phone   string `json:"phone"`
@@ -25,6 +25,8 @@ type OrderJson struct {
 }
 
 type OrderSurface struct {
+	OrderId  uint   `json:"orderId" db:"order_id"`
+	GoodsId  uint   `json:"goodsId" db:"goods_id"`
 	GoodsImg string `json:"goodsImg" db:"pic"`
 	Price    uint   `json:"price" db:"price"`
 	State    int    `json:"state" db:"state"`
@@ -53,9 +55,9 @@ func (o Order) GetAll() (orders []Order, err error) {
 
 func (o Order) GetOwner(ownerId uint) (orderSurface []OrderSurface, err error) {
 	db := common.DB
-	sqlStr := `SELECT g.pic, g.price, o.state, g.title, u.name, u.uid 
-			   FROM orders as o, goods_surfaces as g, users as u
-			   WHERE o.buyer_id = ? AND o.goods_id = g.id AND g.owner_id = u.uid ;`
+	sqlStr := `SELECT o.id as order_id, g.id as goods_id, g.pic as pic, g.price as price, o.state as state, g.title as title, u.name as name, u.uid as uid
+	FROM orders as o, goods_surfaces as g, users as u
+	WHERE o.buyer_id = ? AND o.goods_id = g.id AND g.owner_id = u.uid;`
 	err = db.Select(&orderSurface, sqlStr, ownerId)
 	return
 }

+ 154 - 0
trading-go/model/recommend.go

@@ -0,0 +1,154 @@
+package model
+
+import (
+	"math"
+	"trading-go/common"
+)
+
+type vector struct {
+	v []Pair
+}
+
+type recommendList struct {
+	list map[uint]float64
+}
+
+type Pair struct {
+	CategoryId uint `db:"category_id"`
+	Score      int  `db:"score"`
+}
+
+func Recommend(uid, goodsId uint) error {
+	db := common.DB
+	var cIds []int64
+	sqlStr := "SELECT category_id FROM category_of_goods WHERE goods_id = ?"
+	err := db.Select(&cIds, sqlStr, goodsId)
+	if err != nil {
+		return err
+	}
+	sqlStr = "INSERT INTO feedback(uid, category_id, score) VALUE (?, ?, 1) ON DUPLICATE KEY update  score=score + 1"
+	for _, id := range cIds {
+		_, err := db.Exec(sqlStr, uid, id)
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func NewRecommend(uid uint, categoryId []uint) error {
+	db := common.DB
+
+	sqlStr := "INSERT INTO feedback(uid, category_id, score) VALUE (?, ?, 1) ON DUPLICATE KEY update  score=score + 1"
+	for _, id := range categoryId {
+		_, err := db.Exec(sqlStr, uid, id)
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func GetRecommend(uid uint, cnt int) (goods []uint, err error) {
+	var rList recommendList
+	rList.list = make(map[uint]float64)
+	userV, err := getUserVector(uid)
+	if err != nil {
+		return nil, err
+	}
+	mx := userV.max()
+	goodsIds, err := getGoodsIds()
+	if err != nil {
+		return nil, err
+	}
+	for _, id := range goodsIds {
+		itemV, err := getItemVector(id, uint(mx))
+		if err != nil {
+			return nil, err
+		}
+		rList.list[id] = userV.similarity(itemV)
+	}
+	goods = rList.Sort(cnt)
+	return
+}
+
+func getUserVector(uid uint) (vector, error) {
+	var p []Pair
+	db := common.DB
+	sqlStr := "SELECT category_id, score FROM feedback WHERE uid = ? ORDER BY category_id DESC"
+	err := db.Select(&p, sqlStr, uid)
+	if err != nil {
+		return vector{}, err
+	}
+	return vector{v: p}, err
+}
+
+func getItemVector(id uint, maxId uint) (vector, error) {
+	var p []Pair
+	var cIds []uint
+	db := common.DB
+	sqlStr := "SELECT category_id FROM category_of_goods WHERE goods_id = ? AND category_id <= ?"
+	err := db.Select(&cIds, sqlStr, id, maxId)
+	if err != nil {
+		return vector{}, err
+	}
+	for i := 0; i < len(cIds); i++ {
+		p = append(p, Pair{
+			CategoryId: cIds[i],
+			Score:      1,
+		})
+	}
+	return vector{p}, err
+}
+
+func (v vector) similarity(other vector) float64 {
+	user, item := make(map[uint]int), make(map[uint]int)
+	for _, pair := range v.v {
+		user[pair.CategoryId] = pair.Score
+	}
+	for _, pair := range other.v {
+		item[pair.CategoryId] = 1
+	}
+
+	a, b, cnt := 0, 0, 0
+
+	for ke, va := range user {
+		if _, ok := item[ke]; ok {
+			cnt++
+			a += va
+		}
+		b += va * va
+	}
+
+	if cnt == 0 {
+		return 0
+	}
+
+	return float64(a) / (math.Sqrt(float64(b)) * math.Sqrt(float64(cnt)))
+}
+
+func (v vector) max() uint {
+	return v.v[0].CategoryId
+}
+
+func (r recommendList) Sort(n int) []uint {
+	ids := make([]uint, 0, len(r.list))
+	scores := make([]float64, 0, len(r.list))
+	result := make([]uint, 0, n)
+	for id, score := range r.list {
+		ids = append(ids, id)
+		scores = append(scores, score)
+	}
+	for i := 0; i < n; i++ {
+		mxid := uint(i)
+		for j := 0; j < len(ids); j++ {
+			if scores[j] > scores[mxid] {
+				mxid = uint(j)
+			}
+		}
+		scores[mxid] = -1
+		result = append(result, ids[mxid])
+	}
+
+	return result
+}

+ 2 - 2
trading-go/model/user.go

@@ -19,7 +19,7 @@ type User struct {
 }
 
 type UserJson struct {
-	Uid    string `json:"uid"`
+	Uid    string `json:"uid,string"`
 	Vid    string `json:"vid"`
 	Name   string `json:"name"`
 	Avatar string `json:"avatar"`
@@ -161,7 +161,7 @@ func (u User) CheckVid() bool {
 	db := common.DB
 	sqlStr := "SELECT COUNT(1) FROM users WHERE vid = ?"
 	cnt := 0
-	_ = db.Get(&cnt, sqlStr)
+	_ = db.Get(&cnt, sqlStr, u.Vid)
 	return cnt == 0
 }
 

BIN
trading-go/pics/17026291282u3VVWKPLyQhdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702629188lP06022RjVfJdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702629267nl91VEi2eIpBdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702629388JKUuDUAu1dQhdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702629488YNp2BpoRCjzqdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702629855KZ6cCG2WC0qSdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702630145Nq4Mq8PD4vtedce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702630539J37Nz6WJaFNpdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/17026309926EomSaZQMBYUdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702631231Vw1S8D48tGkQdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702631414awSmQm1CZSHZdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702631790HkBcZtgzuyc0dce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/17027252157NtB9WS5RdaUdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702725218R8pSJsY5DOxN7baafd97122013df4eefc138a9d491e4.png


BIN
trading-go/pics/1702725395BoEekRVVTjajdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702725398gzg2s4VcPuUI7baafd97122013df4eefc138a9d491e4.png


BIN
trading-go/pics/170272852515dnT7auvXXQdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702728654XzGWwMSLfVRVdce75ebb26860c9184474d8244e28d16.png


BIN
trading-go/pics/1702728775P2HKiUnquJttdce75ebb26860c9184474d8244e28d16.png


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

@@ -29,6 +29,7 @@ func GetRoutine() *gin.Engine {
 		user.POST("login", controller.Login)
 		user.POST("register", controller.Register)
 		user.POST("list", controller.GetUserList)
+		user.POST("rec/new", controller.NewRecommend)
 	}
 
 	chat := r.Group("chat")

+ 0 - 87
trading-go/util/recommend.go

@@ -1,87 +0,0 @@
-package util
-
-import (
-	"context"
-	"fmt"
-	"github.com/spf13/viper"
-	"github.com/zhenghaoz/gorse/client"
-	"time"
-)
-
-var gorse *client.GorseClient
-
-func init() {
-	gorse = client.NewGorseClient(viper.GetString("gorse.addr"), "")
-
-}
-
-func GetTime(tie uint) string {
-	t := time.Unix(int64(tie), 0)
-	date := t.Format("2006-01-02")
-	return date
-}
-
-func Recommend(uid, goodsId, tie uint) {
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*100)
-	defer cancel()
-	date := GetTime(tie)
-	aff, err := gorse.InsertFeedback(ctx, []client.Feedback{
-		{FeedbackType: "star",
-			UserId:    fmt.Sprintf("%d", uid),
-			ItemId:    fmt.Sprintf("%d", goodsId),
-			Timestamp: date},
-	})
-	if err != nil {
-		fmt.Println("[recommend] ======>>> " + err.Error())
-		return
-	}
-
-	fmt.Printf("[recommend] ======>>> %dfeedback success\n", aff)
-}
-
-func GetRecommend(uid uint, cnt int) (goods []string, err error) {
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
-	defer cancel()
-	category, err := gorse.GetItemRecommendWithCategory(ctx, fmt.Sprintf("%d", uid), "", "", "", 0, cnt)
-	return category, err
-}
-
-func NewUser(uid uint) {
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
-	defer cancel()
-	_, err := gorse.InsertUser(ctx, client.User{UserId: fmt.Sprintf("%d", uid)})
-	if err != nil {
-		fmt.Println("[recommend] ======>>> " + err.Error())
-		return
-	}
-	fmt.Println("[recommend] ======>>> user added")
-}
-
-func NewItem(id uint, t uint, title string, desc string) {
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
-	defer cancel()
-	_, err := gorse.InsertItem(ctx, client.Item{
-		ItemId:     fmt.Sprintf("%d", id),
-		IsHidden:   false,
-		Labels:     []string{title},
-		Categories: nil,
-		Timestamp:  GetTime(t),
-		Comment:    desc,
-	})
-	if err != nil {
-		fmt.Println("[recommend] ======>>> " + err.Error())
-		return
-	}
-	fmt.Println("[recommend] ======>>> item added")
-}
-
-func DelItem(id uint) {
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
-	defer cancel()
-	_, err := gorse.DeleteItem(ctx, fmt.Sprintf("%d", id))
-	if err != nil {
-		fmt.Println("[recommend] ======>>> " + err.Error())
-		return
-	}
-	fmt.Println("[recommend] ======>>> item deleted")
-}