Pārlūkot izejas kodu

增加获取登录账号有权限的商品信息接口

zhou.xiaoning 4 gadi atpakaļ
vecāks
revīzija
d2f94da250
7 mainītis faili ar 192 papildinājumiem un 0 dzēšanām
  1. 40 0
      controllers/market/market.go
  2. 45 0
      docs/docs.go
  3. 45 0
      docs/swagger.json
  4. 28 0
      docs/swagger.yaml
  5. 31 0
      models/goods.go
  6. 1 0
      models/market.go
  7. 2 0
      routers/router.go

+ 40 - 0
controllers/market/market.go

@@ -87,3 +87,43 @@ func QueryMarketsByLoginID(c *gin.Context) {
 	logger.GetLogger().Debugln("QueryMarketsByLoginID successed: %v", markets)
 	appG.Response(http.StatusOK, e.SUCCESS, markets)
 }
+
+// QueryGoodsesByLoginIDReq 获取登录账号有权限的商品信息请求参数
+type QueryGoodsesByLoginIDReq struct {
+	LoginID   int    `form:"loginID" binding:"required"`
+	MarketIDs string `form:"marketIDs"`
+}
+
+// QueryGoodsesByLoginID 获取登录账号有权限的商品信息
+// @Summary 获取登录账号有权限的商品信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param loginID query int true "登录账号"
+// @Param marketIDs query string false "市场ID列表,格式:1,2,3"
+// @Success 200 {object} models.Market
+// @Failure 500 {object} app.Response
+// @Router /Market/QueryGoodsesByLoginID [get]
+// @Tags 通用市场
+func QueryGoodsesByLoginID(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryGoodsesByLoginIDReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryGoodsesByLoginID failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	goodses, err := models.GetGoodsByLoginID(req.LoginID, req.MarketIDs)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryGoodsesByLoginID failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功返回
+	logger.GetLogger().Debugln("QueryGoodsesByLoginID successed: %v", goodses)
+	appG.Response(http.StatusOK, e.SUCCESS, goodses)
+}

+ 45 - 0
docs/docs.go

@@ -3152,6 +3152,51 @@ var doc = `{
                 }
             }
         },
+        "/Market/QueryGoodsesByLoginID": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用市场"
+                ],
+                "summary": "获取登录账号有权限的商品信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "登录账号",
+                        "name": "loginID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "市场ID列表,格式:1,2,3",
+                        "name": "marketIDs",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.Market"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Market/QueryMarketRun": {
             "get": {
                 "security": [

+ 45 - 0
docs/swagger.json

@@ -3136,6 +3136,51 @@
                 }
             }
         },
+        "/Market/QueryGoodsesByLoginID": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用市场"
+                ],
+                "summary": "获取登录账号有权限的商品信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "登录账号",
+                        "name": "loginID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "市场ID列表,格式:1,2,3",
+                        "name": "marketIDs",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.Market"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Market/QueryMarketRun": {
             "get": {
                 "security": [

+ 28 - 0
docs/swagger.yaml

@@ -8543,6 +8543,34 @@ paths:
       summary: 设置我的包裹已收货状态
       tags:
       - 定制【海商报业】
+  /Market/QueryGoodsesByLoginID:
+    get:
+      parameters:
+      - description: 登录账号
+        in: query
+        name: loginID
+        required: true
+        type: integer
+      - description: 市场ID列表,格式:1,2,3
+        in: query
+        name: marketIDs
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.Market'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 获取登录账号有权限的商品信息
+      tags:
+      - 通用市场
   /Market/QueryMarketRun:
     get:
       parameters:

+ 31 - 0
models/goods.go

@@ -4,6 +4,7 @@ package models
 import (
 	"fmt"
 	"mtp2_if/db"
+	"strings"
 	"time"
 )
 
@@ -164,3 +165,33 @@ func SearchGoodses(content, tradeModes string) ([]SearchGoods, error) {
 
 	return searchGoodses, nil
 }
+
+// GetGoodsByLoginID 获取登录账号有权限的商品信息
+func GetGoodsByLoginID(loginID int, marketIDs string) ([]Goods, error) {
+	// 获取此账号相关有权限的市场
+	markets, err := GetMarketsByLoginID(loginID)
+	if err != nil {
+		return nil, err
+	}
+
+	// 构建市场ID列表
+	ids := make([]int, 0)
+	reqIDs := fmt.Sprintf(",%s,", marketIDs)
+	for _, market := range markets {
+		if len(marketIDs) > 0 {
+			if !strings.Contains(reqIDs, fmt.Sprintf(",%d,", market.Marketid)) {
+				continue
+			}
+		}
+		ids = append(ids, int(market.Marketid))
+	}
+
+	// 获取对应商品信息
+	engine := db.GetEngine()
+	goodses := make([]Goods, 0)
+	if err := engine.Table("GOODS G").In("G.MARKETID", ids).Find(&goodses); err != nil {
+		return nil, err
+	}
+
+	return goodses, nil
+}

+ 1 - 0
models/market.go

@@ -373,6 +373,7 @@ func GetMarketsByLoginID(loginID int) ([]Market, error) {
 		}
 	}
 
+	// 获取市场信息
 	if len(marketIDs) > 0 {
 		if err := engine.Table("MARKET M").In("M.MARKETID", marketIDs).Find(&markets); err != nil {
 			return nil, err

+ 2 - 0
routers/router.go

@@ -116,6 +116,8 @@ func InitRouter() *gin.Engine {
 		marketR.GET("/QueryMarketRun", market.QueryMarketRun)
 		// 获取登录账号有权限的市场信息
 		marketR.GET("/QueryMarketsByLoginID", market.QueryMarketsByLoginID)
+		// 获取登录账号有权限的商品信息
+		marketR.GET("/QueryGoodsesByLoginID", market.QueryGoodsesByLoginID)
 	}
 	// ************************ 通用单据 ************************
 	orderR := apiR.Group("Order")