Kaynağa Gözat

增加“查询新品上市商品列表(一级市场产能预售)”接口

zhou.xiaoning 5 yıl önce
ebeveyn
işleme
aae85ea7ec
6 değiştirilmiş dosya ile 579 ekleme ve 33 silme
  1. 102 12
      controllers/hsby/hsby.go
  2. 147 4
      docs/docs.go
  3. 147 4
      docs/swagger.json
  4. 104 4
      docs/swagger.yaml
  5. 77 9
      models/hsby.go
  6. 2 0
      routers/router.go

+ 102 - 12
controllers/hsby/hsby.go

@@ -11,22 +11,22 @@ import (
 	"github.com/gin-gonic/gin"
 )
 
-// QueryTopGoodsReq 查询热门商品列表请求参数
-type QueryTopGoodsReq struct {
+// QueryTopGoodsesReq 查询热门商品列表请求参数
+type QueryTopGoodsesReq struct {
 	app.PageInfo
-	MarketID       int `form:"marketID" binding:"required"`
-	DescProvinceID int `form:"descProvinceID"`
-	DescCityID     int `form:"descCityID"`
+	MarketIDs      string `form:"marketIDs" binding:"required"`
+	DescProvinceID int    `form:"descProvinceID"`
+	DescCityID     int    `form:"descCityID"`
 }
 
-// QueryTopGoods 查询热门商品列表(二级市场,挂牌点选)
-// @Summary 查询热门商品列表(二级市场,挂牌点选)
+// QueryTopGoods 查询热卖商品列表(二级市场挂牌点选)
+// @Summary 查询热卖商品列表(二级市场挂牌点选)
 // @Description 说明:查询结果已按Hotindex(景点热度)从大到小排序
 // @Produce json
 // @Security ApiKeyAuth
 // @Param page query int false "页码"
 // @Param pagesize query int false "每页条数"
-// @Param marketID query int true "市场ID"
+// @Param marketIDs query string true "市场ID列表,格式:1,2,3"
 // @Param DescProvinceID query int false "目的地(省)ID"
 // @Param DescCityID query int false "目的地(市)ID"
 // @Success 200 {object} models.HsbyTopGoods
@@ -37,7 +37,7 @@ func QueryTopGoods(c *gin.Context) {
 	appG := app.Gin{C: c}
 
 	// 获取请求参数
-	var req QueryTopGoodsReq
+	var req QueryTopGoodsesReq
 	if err := appG.C.ShouldBindQuery(&req); err != nil {
 		logger.GetLogger().Errorf("QueryTopGoods failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
@@ -45,7 +45,7 @@ func QueryTopGoods(c *gin.Context) {
 	}
 
 	// 获取数据
-	topGoodses, err := models.GetHsbyTopGoods(req.MarketID, req.DescProvinceID, req.DescCityID)
+	topGoodses, err := models.GetHsbyTopGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QueryTopGoods failed: %s", err.Error())
@@ -168,7 +168,7 @@ func QueryHsbyGoodsOrderDetails(c *gin.Context) {
 
 	// 按时间和价格排序
 	sort.Slice(sellOrderDetails, func(i int, j int) bool {
-		// 时间价格一样则按时间顺序排
+		// 委托价格一样则按时间顺序排
 		if sellOrderDetails[i].Orderprice == sellOrderDetails[j].Orderprice {
 			return sellOrderDetails[i].Ordertime.Before(sellOrderDetails[j].Ordertime)
 		}
@@ -176,7 +176,7 @@ func QueryHsbyGoodsOrderDetails(c *gin.Context) {
 		return sellOrderDetails[i].Orderprice < sellOrderDetails[j].Orderprice
 	})
 	sort.Slice(buyOrderDetails, func(i int, j int) bool {
-		// 时间价格一样则按时间顺序排
+		// 委托价格一样则按时间顺序排
 		if buyOrderDetails[i].Orderprice == buyOrderDetails[j].Orderprice {
 			return buyOrderDetails[i].Ordertime.Before(buyOrderDetails[j].Ordertime)
 		}
@@ -295,3 +295,93 @@ func QueryHsbyMyGoods(c *gin.Context) {
 	logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
 	appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
 }
+
+// QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数
+type QueryHsbyPreGoodsesReq struct {
+	app.PageInfo
+	MarketIDs      string `form:"marketIDs" binding:"required"`
+	DescProvinceID int    `form:"descProvinceID"`
+	DescCityID     int    `form:"descCityID"`
+}
+
+// QueryHsbyPreGoodses 查询新品上市商品列表(一级市场产能预售)
+// @Summary 查询新品上市商品列表(一级市场产能预售)
+// @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param page query int false "页码"
+// @Param pagesize query int false "每页条数"
+// @Param marketIDs query string true "市场ID列表,格式:1,2,3"
+// @Param DescProvinceID query int false "目的地(省)ID"
+// @Param DescCityID query int false "目的地(市)ID"
+// @Success 200 {object} models.HsbyPreGoods
+// @Failure 500 {object} app.Response
+// @Router /HSBY/QueryHsbyPreGoodses [get]
+// @Tags 定制【海商报业】
+func QueryHsbyPreGoodses(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryHsbyPreGoodsesReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取数据
+	preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
+	sort.Slice(preGoodses, func(i int, j int) bool {
+		if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 {
+			// 先显示已开始商品
+			return true
+		} else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
+			// 已开始商品按结束时间顺序排
+			return preGoodses[i].Endtime.After(preGoodses[j].Endtime)
+		} else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
+			// 未开始商品按开始时间顺序排
+			return preGoodses[i].Starttime.After(preGoodses[j].Starttime)
+		}
+
+		return false
+	})
+
+	// 分页
+	total := len(preGoodses)
+	if req.PageSize > 0 {
+		rstByPage := make([]models.HsbyPreGoods, 0)
+		// 开始上标
+		start := req.Page * req.PageSize
+		// 结束下标
+		end := start + req.PageSize
+
+		if start <= len(preGoodses) {
+			// 判断结束下标是否越界
+			if end > len(preGoodses) {
+				end = len(preGoodses)
+			}
+			rstByPage = preGoodses[start:end]
+		} else {
+			rstByPage = preGoodses[0:0]
+		}
+
+		preGoodses = rstByPage
+	}
+
+	// 查询成功返回
+	if req.PageSize > 0 {
+		logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
+		appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
+	} else {
+		logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
+		appG.Response(http.StatusOK, e.SUCCESS, preGoodses)
+	}
+}

+ 147 - 4
docs/docs.go

@@ -926,6 +926,70 @@ var doc = `{
                 }
             }
         },
+        "/HSBY/QueryHsbyPreGoodses": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "description": "说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询新品上市商品列表(一级市场产能预售)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "市场ID列表,格式:1,2,3",
+                        "name": "marketIDs",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "目的地(省)ID",
+                        "name": "DescProvinceID",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "目的地(市)ID",
+                        "name": "DescCityID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.HsbyPreGoods"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryTopGoods": {
             "get": {
                 "security": [
@@ -940,7 +1004,7 @@ var doc = `{
                 "tags": [
                     "定制【海商报业】"
                 ],
-                "summary": "查询热门商品列表(二级市场,挂牌点选)",
+                "summary": "查询热卖商品列表(二级市场挂牌点选)",
                 "parameters": [
                     {
                         "type": "integer",
@@ -955,9 +1019,9 @@ var doc = `{
                         "in": "query"
                     },
                     {
-                        "type": "integer",
-                        "description": "市场ID",
-                        "name": "marketID",
+                        "type": "string",
+                        "description": "市场ID列表,格式:1,2,3",
+                        "name": "marketIDs",
                         "in": "query",
                         "required": true
                     },
@@ -3743,6 +3807,14 @@ var doc = `{
                     "description": "账号Id",
                     "type": "integer"
                 },
+                "agreeunit": {
+                    "description": "合约单位",
+                    "type": "number"
+                },
+                "buyaverageprice": {
+                    "description": "持仓均价",
+                    "type": "number"
+                },
                 "buycurholderamount": {
                     "description": "买当前持仓总金额[商品币种]",
                     "type": "number"
@@ -3777,6 +3849,77 @@ var doc = `{
                 }
             }
         },
+        "models.HsbyPreGoods": {
+            "type": "object",
+            "required": [
+                "goodscode",
+                "goodsid",
+                "goodsname",
+                "marketid"
+            ],
+            "properties": {
+                "currency": {
+                    "description": "货币",
+                    "type": "string"
+                },
+                "currencysign": {
+                    "description": "货币符号",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "报价小数位",
+                    "type": "integer"
+                },
+                "endtime": {
+                    "description": "预售结束时间",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID(自增ID SEQ_GOODS)",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "goodsstatus": {
+                    "description": "商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "所属市场ID",
+                    "type": "integer"
+                },
+                "picurls": {
+                    "description": "介绍图片[多张用逗号分隔]",
+                    "type": "string"
+                },
+                "presaleqty": {
+                    "description": "预售数量",
+                    "type": "integer"
+                },
+                "refprice": {
+                    "description": "参考价格[一口价]",
+                    "type": "number"
+                },
+                "relatedgoodsid": {
+                    "description": "关联交易合约ID",
+                    "type": "integer"
+                },
+                "starttime": {
+                    "description": "预售开始时间",
+                    "type": "string"
+                },
+                "videourls": {
+                    "description": "介绍视频[多张用逗号分隔]",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyTopGoods": {
             "type": "object",
             "required": [

+ 147 - 4
docs/swagger.json

@@ -910,6 +910,70 @@
                 }
             }
         },
+        "/HSBY/QueryHsbyPreGoodses": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "description": "说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询新品上市商品列表(一级市场产能预售)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "市场ID列表,格式:1,2,3",
+                        "name": "marketIDs",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "目的地(省)ID",
+                        "name": "DescProvinceID",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "目的地(市)ID",
+                        "name": "DescCityID",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.HsbyPreGoods"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryTopGoods": {
             "get": {
                 "security": [
@@ -924,7 +988,7 @@
                 "tags": [
                     "定制【海商报业】"
                 ],
-                "summary": "查询热门商品列表(二级市场,挂牌点选)",
+                "summary": "查询热卖商品列表(二级市场挂牌点选)",
                 "parameters": [
                     {
                         "type": "integer",
@@ -939,9 +1003,9 @@
                         "in": "query"
                     },
                     {
-                        "type": "integer",
-                        "description": "市场ID",
-                        "name": "marketID",
+                        "type": "string",
+                        "description": "市场ID列表,格式:1,2,3",
+                        "name": "marketIDs",
                         "in": "query",
                         "required": true
                     },
@@ -3727,6 +3791,14 @@
                     "description": "账号Id",
                     "type": "integer"
                 },
+                "agreeunit": {
+                    "description": "合约单位",
+                    "type": "number"
+                },
+                "buyaverageprice": {
+                    "description": "持仓均价",
+                    "type": "number"
+                },
                 "buycurholderamount": {
                     "description": "买当前持仓总金额[商品币种]",
                     "type": "number"
@@ -3761,6 +3833,77 @@
                 }
             }
         },
+        "models.HsbyPreGoods": {
+            "type": "object",
+            "required": [
+                "goodscode",
+                "goodsid",
+                "goodsname",
+                "marketid"
+            ],
+            "properties": {
+                "currency": {
+                    "description": "货币",
+                    "type": "string"
+                },
+                "currencysign": {
+                    "description": "货币符号",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "报价小数位",
+                    "type": "integer"
+                },
+                "endtime": {
+                    "description": "预售结束时间",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID(自增ID SEQ_GOODS)",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "goodsstatus": {
+                    "description": "商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "所属市场ID",
+                    "type": "integer"
+                },
+                "picurls": {
+                    "description": "介绍图片[多张用逗号分隔]",
+                    "type": "string"
+                },
+                "presaleqty": {
+                    "description": "预售数量",
+                    "type": "integer"
+                },
+                "refprice": {
+                    "description": "参考价格[一口价]",
+                    "type": "number"
+                },
+                "relatedgoodsid": {
+                    "description": "关联交易合约ID",
+                    "type": "integer"
+                },
+                "starttime": {
+                    "description": "预售开始时间",
+                    "type": "string"
+                },
+                "videourls": {
+                    "description": "介绍视频[多张用逗号分隔]",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyTopGoods": {
             "type": "object",
             "required": [

+ 104 - 4
docs/swagger.yaml

@@ -1340,6 +1340,12 @@ definitions:
       accountid:
         description: 账号Id
         type: integer
+      agreeunit:
+        description: 合约单位
+        type: number
+      buyaverageprice:
+        description: 持仓均价
+        type: number
       buycurholderamount:
         description: 买当前持仓总金额[商品币种]
         type: number
@@ -1370,6 +1376,59 @@ definitions:
     - goodsid
     - goodsname
     type: object
+  models.HsbyPreGoods:
+    properties:
+      currency:
+        description: 货币
+        type: string
+      currencysign:
+        description: 货币符号
+        type: string
+      decimalplace:
+        description: 报价小数位
+        type: integer
+      endtime:
+        description: 预售结束时间
+        type: string
+      goodscode:
+        description: 商品代码(内部)
+        type: string
+      goodsid:
+        description: 商品ID(自增ID SEQ_GOODS)
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+      goodsstatus:
+        description: 商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市
+        type: integer
+      marketid:
+        description: 所属市场ID
+        type: integer
+      picurls:
+        description: 介绍图片[多张用逗号分隔]
+        type: string
+      presaleqty:
+        description: 预售数量
+        type: integer
+      refprice:
+        description: 参考价格[一口价]
+        type: number
+      relatedgoodsid:
+        description: 关联交易合约ID
+        type: integer
+      starttime:
+        description: 预售开始时间
+        type: string
+      videourls:
+        description: 介绍视频[多张用逗号分隔]
+        type: string
+    required:
+    - goodscode
+    - goodsid
+    - goodsname
+    - marketid
+    type: object
   models.HsbyTopGoods:
     properties:
       currency:
@@ -3750,6 +3809,47 @@ paths:
       summary: 查询“我的商品”信息
       tags:
       - 定制【海商报业】
+  /HSBY/QueryHsbyPreGoodses:
+    get:
+      description: 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
+      parameters:
+      - description: 页码
+        in: query
+        name: page
+        type: integer
+      - description: 每页条数
+        in: query
+        name: pagesize
+        type: integer
+      - description: 市场ID列表,格式:1,2,3
+        in: query
+        name: marketIDs
+        required: true
+        type: string
+      - description: 目的地(省)ID
+        in: query
+        name: DescProvinceID
+        type: integer
+      - description: 目的地(市)ID
+        in: query
+        name: DescCityID
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.HsbyPreGoods'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询新品上市商品列表(一级市场产能预售)
+      tags:
+      - 定制【海商报业】
   /HSBY/QueryTopGoods:
     get:
       description: 说明:查询结果已按Hotindex(景点热度)从大到小排序
@@ -3762,11 +3862,11 @@ paths:
         in: query
         name: pagesize
         type: integer
-      - description: 市场ID
+      - description: 市场ID列表,格式:1,2,3
         in: query
-        name: marketID
+        name: marketIDs
         required: true
-        type: integer
+        type: string
       - description: 目的地(省)ID
         in: query
         name: DescProvinceID
@@ -3788,7 +3888,7 @@ paths:
             $ref: '#/definitions/app.Response'
       security:
       - ApiKeyAuth: []
-      summary: 查询热门商品列表(二级市场,挂牌点选)
+      summary: 查询热卖商品列表(二级市场挂牌点选)
       tags:
       - 定制【海商报业】
   /History/QueryTSData:

+ 77 - 9
models/hsby.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"mtp2_if/db"
 	"mtp2_if/utils"
+	"strconv"
 	"time"
 )
 
@@ -47,7 +48,7 @@ func (Hsbysupplierinfo) TableName() string {
 	return "HSBY_SUPPLIERINFO"
 }
 
-// HsbyTopGoods 热门商品列表
+// HsbyTopGoods 热卖商品(二级市场挂牌点选)
 type HsbyTopGoods struct {
 	Goodsid      int64  `json:"goodsid"  xorm:"'GOODSID'" binding:"required"`     // 商品ID(自增ID SEQ_GOODS)
 	Goodscode    string `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
@@ -65,13 +66,13 @@ type HsbyTopGoods struct {
 	Last float64 `json:"last" xorm:"-"` // 现价
 }
 
-// GetHsbyTopGoods 获取热门商品列表
-// 参数 marketID int 所属市场ID
+// GetHsbyTopGoodses 获取热门商品列表
+// 参数 marketIDs string 所属市场ID列表, 格式 1,2,3
 // 参数 descProvinceID int 目标省ID
 // 参数 descCityID int 目标城市ID
 // 返回 []TopGoods 热门商品列表
 // 返回 error error
-func GetHsbyTopGoods(marketID int, descProvinceID int, descCityID int) ([]HsbyTopGoods, error) {
+func GetHsbyTopGoodses(marketIDs string, descProvinceID, descCityID int) ([]HsbyTopGoods, error) {
 	// 热门商品为二级市场(挂牌点选)下的商品信息
 
 	engine := db.GetEngine()
@@ -84,7 +85,7 @@ func GetHsbyTopGoods(marketID int, descProvinceID int, descCityID int) ([]HsbyTo
 				ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN`).
 		Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
 		Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
-		Where("GOODS.MARKETID = ?", marketID)
+		Where(fmt.Sprintf("GOODS.GOODSSTATUS = 3 and GOODS.MARKETID in (%s)", marketIDs)) // 二级市场只获取 3:上市 状态的商品
 	if descProvinceID > 0 {
 		session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID)
 	}
@@ -413,13 +414,16 @@ type HsbyMyGoods struct {
 	Buycurpositionqty  int64   `json:"buycurpositionqty"  xorm:"'BUYCURPOSITIONQTY'"`    // 买当前持仓总数量
 	Buycurholderamount float64 `json:"buycurholderamount"  xorm:"'BUYCURHOLDERAMOUNT'"`  // 买当前持仓总金额[商品币种]
 
-	Goodscode    string `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
-	Goodsname    string `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"` // 商品名称
-	Decimalplace int64  `json:"decimalplace"  xorm:"'DECIMALPLACE'"`              // 报价小数位
+	Goodscode    string  `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
+	Goodsname    string  `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"` // 商品名称
+	Decimalplace int64   `json:"decimalplace"  xorm:"'DECIMALPLACE'"`              // 报价小数位
+	Agreeunit    float64 `json:"agreeunit"  xorm:"'AGREEUNIT'"`                    // 合约单位
 
 	Picurls string `json:"picurls"  xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
 
 	Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
+
+	Buyaverageprice float64 `json:"buyaverageprice" xorm:"-"` // 持仓均价
 }
 
 // GetHsbyMyGoods 获取“我的商品”信息
@@ -432,7 +436,7 @@ func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
 	hsbyMyGoodses := make([]HsbyMyGoods, 0)
 	if err := engine.Table("TRADEPOSITION").
 		Select(`TRADEPOSITION.*, 
-				GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, 
+				GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT, 
 				HSBY_GOODSEX.PICURLS, 
 				ENUMDICITEM.PARAM2 CURRENCYSIGN`).
 		Join("LEFT", "GOODS", "GOODS.GOODSID = TRADEPOSITION.GOODSID").
@@ -442,5 +446,69 @@ func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
 		return nil, err
 	}
 
+	// 计算持仓均价
+	for i := range hsbyMyGoodses {
+		myGoods := &hsbyMyGoodses[i]
+
+		averagePrice := myGoods.Buycurholderamount / float64(myGoods.Buycurpositionqty) / myGoods.Agreeunit
+		myGoods.Buyaverageprice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(myGoods.Decimalplace)), 64)
+	}
+
 	return hsbyMyGoodses, nil
 }
+
+// HsbyPreGoods 新品上市商品(一级市场产能预售)
+type HsbyPreGoods struct {
+	Goodsid      int64  `json:"goodsid"  xorm:"'GOODSID'" binding:"required"`     // 商品ID(自增ID SEQ_GOODS)
+	Goodscode    string `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
+	Goodsname    string `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"` // 商品名称
+	Decimalplace int64  `json:"decimalplace"  xorm:"'DECIMALPLACE'"`              // 报价小数位
+	Marketid     int64  `json:"marketid"  xorm:"'MARKETID'" binding:"required"`   // 所属市场ID
+	Goodsstatus  int64  `json:"goodsstatus"  xorm:"'GOODSSTATUS'"`                // 商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市
+
+	Relatedgoodsid int64     `json:"relatedgoodsid"  xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
+	Presaleqty     int64     `json:"presaleqty"  xorm:"'PRESALEQTY'"`         // 预售数量
+	Starttime      time.Time `json:"starttime"  xorm:"'STARTTIME'"`           // 预售开始时间
+	Endtime        time.Time `json:"endtime"  xorm:"'ENDTIME'"`               // 预售结束时间
+	Refprice       float64   `json:"refprice"  xorm:"'REFPRICE'"`             // 参考价格[一口价]
+
+	Currency     string `json:"currency" xorm:"'CURRENCY'"`         // 货币
+	Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
+
+	Videourls string `json:"videourls"  xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
+	Picurls   string `json:"picurls"  xorm:"'PICURLS'"`     // 介绍图片[多张用逗号分隔]
+}
+
+// GetHsbyPreGoodses 获取“新品上市”商品列表(一级市场产能预售)
+// 输入 marketIDs string 市场ID列表,格式 1,2,3
+// 输入 descProvinceID int 省ID
+// 输入 descCityID int 市ID
+// 输出 []HsbyPreGoods “新品上市”商品列表
+// 输出 error error
+func GetHsbyPreGoodses(marketIDs string, descProvinceID, descCityID int) ([]HsbyPreGoods, error) {
+	engine := db.GetEngine()
+
+	// 注意:一级产能预售市场使用的商品实际上是和二级市场有关系的,所以要使用 CPTRADE_PRESALEGOODSEX.RELATEDGOODSID 进行关联
+	preGoodses := make([]HsbyPreGoods, 0)
+	session := engine.Table("GOODS").
+		Select(`GOODS.*, 
+				CPTRADE_PRESALEGOODSEX.RELATEDGOODSID, CPTRADE_PRESALEGOODSEX.PRESALEQTY, 
+				CPTRADE_PRESALEGOODSEX.STARTTIME, CPTRADE_PRESALEGOODSEX.ENDTIME, CPTRADE_PRESALEGOODSEX.REFPRICE, 
+				ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN, 
+				HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS`).
+		Join("LEFT", "CPTRADE_PRESALEGOODSEX", "CPTRADE_PRESALEGOODSEX.GOODSID = GOODS.GOODSID").
+		Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
+		Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = CPTRADE_PRESALEGOODSEX.RELATEDGOODSID").
+		Where(fmt.Sprintf("GOODS.GOODSSTATUS in (2,3) and GOODS.MARKETID in (%s)", marketIDs)) // 一级市场获取 2:未上市 3:上市 状态的商品
+	if descProvinceID > 0 {
+		session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID)
+	}
+	if descCityID > 0 {
+		session = session.And("HSBY_GOODSEX.DESCCITYID = ?", descCityID)
+	}
+	if err := session.Find(&preGoodses); err != nil {
+		return nil, err
+	}
+
+	return preGoodses, nil
+}

+ 2 - 0
routers/router.go

@@ -172,6 +172,8 @@ func InitRouter() *gin.Engine {
 		hsbyR.GET("/QueryHsbyMyBuyOrderDetails", hsby.QueryHsbyMyBuyOrderDetails)
 		// 查询“我的商品”信息
 		hsbyR.GET("/QueryHsbyMyGoods", hsby.QueryHsbyMyGoods)
+		// 查询新品上市商品列表(一级市场产能预售)
+		hsbyR.GET("/QueryHsbyPreGoodses", hsby.QueryHsbyPreGoodses)
 	}
 
 	return r