Ver código fonte

海商接口增加最大开仓手数等字段返回

zhou.xiaoning 4 anos atrás
pai
commit
cd44708542
5 arquivos alterados com 111 adições e 11 exclusões
  1. 30 3
      controllers/hsby/hsby.go
  2. 18 0
      docs/docs.go
  3. 18 0
      docs/swagger.json
  4. 13 0
      docs/swagger.yaml
  5. 32 8
      models/hsby.go

+ 30 - 3
controllers/hsby/hsby.go

@@ -121,7 +121,7 @@ func QueryHsbyListingGoodsDetail(c *gin.Context) {
 	}
 
 	// 获取数据
-	goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID)
+	goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID, req.AccountID)
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
@@ -1140,7 +1140,8 @@ func QueryHsbyMarketGoodses(c *gin.Context) {
 
 // QueryHsbyMarketGoodsDetailReq 查询三级市场(商城)商品信息详情请求参数
 type QueryHsbyMarketGoodsDetailReq struct {
-	OrderID int `form:"orderID" binding:"required"`
+	OrderID   int `form:"orderID" binding:"required"`
+	AccountID int `form:"accountID"`
 }
 
 // QueryHsbyMarketGoodsDetail 查询三级市场(商城)商品信息详情
@@ -1148,6 +1149,7 @@ type QueryHsbyMarketGoodsDetailReq struct {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param orderID query int true "委托单号"
+// @Param accountID query int false "资金账户,主要用于判断商品最大开仓手数;如未登录可不传。"
 // @Success 200 {object} models.HsbyMarketGoodsDetail
 // @Failure 500 {object} app.Response
 // @Router /HSBY/QueryHsbyMarketGoodsDetail [get]
@@ -1164,7 +1166,7 @@ func QueryHsbyMarketGoodsDetail(c *gin.Context) {
 	}
 
 	// 获取数据
-	detail, err := models.GetHsbyMarketGoodsDetail(req.OrderID)
+	detail, err := models.GetHsbyMarketGoodsDetail(req.OrderID, req.AccountID)
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
@@ -1172,6 +1174,31 @@ func QueryHsbyMarketGoodsDetail(c *gin.Context) {
 		return
 	}
 
+	// 获取交易规则
+	rule, err := models.GetTodayAccountTradeRule(int(detail.Accountid), int(detail.Goodsid))
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+	if rule != nil {
+		tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
+		if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
+			// 查询失败
+			logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
+		// INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
+		for _, v := range tradeRuleInfoStruct.TradeRules {
+			if int(*v.RuleID) == 103 {
+				detail.LotSize = int(*v.ParamValue)
+				break
+			}
+		}
+	}
+
 	// 查询成功返回
 	logger.GetLogger().Debugln("QueryHsbyMarketGoodsDetail successed: %v", detail)
 	appG.Response(http.StatusOK, e.SUCCESS, detail)

+ 18 - 0
docs/docs.go

@@ -1887,6 +1887,12 @@ var doc = `{
                         "name": "orderID",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "资金账户,主要用于判断商品最大开仓手数;如未登录可不传。",
+                        "name": "accountID",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -7946,6 +7952,10 @@ var doc = `{
                     "description": "合约单位",
                     "type": "number"
                 },
+                "buymaxqty": {
+                    "description": "购买上限 [71] - 0为不限",
+                    "type": "integer"
+                },
                 "currency": {
                     "description": "货币",
                     "type": "string"
@@ -8169,6 +8179,10 @@ var doc = `{
                     "description": "合约单位",
                     "type": "number"
                 },
+                "buymaxqty": {
+                    "description": "购买上限 [71] - 0为不限",
+                    "type": "integer"
+                },
                 "buyorsell": {
                     "description": "买卖 - 0:买 1:卖",
                     "type": "integer"
@@ -8217,6 +8231,10 @@ var doc = `{
                     "description": "景点热度",
                     "type": "integer"
                 },
+                "lotsize": {
+                    "description": "手数最小变动单位",
+                    "type": "integer"
+                },
                 "marketid": {
                     "description": "市场ID",
                     "type": "integer"

+ 18 - 0
docs/swagger.json

@@ -1871,6 +1871,12 @@
                         "name": "orderID",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "资金账户,主要用于判断商品最大开仓手数;如未登录可不传。",
+                        "name": "accountID",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -7930,6 +7936,10 @@
                     "description": "合约单位",
                     "type": "number"
                 },
+                "buymaxqty": {
+                    "description": "购买上限 [71] - 0为不限",
+                    "type": "integer"
+                },
                 "currency": {
                     "description": "货币",
                     "type": "string"
@@ -8153,6 +8163,10 @@
                     "description": "合约单位",
                     "type": "number"
                 },
+                "buymaxqty": {
+                    "description": "购买上限 [71] - 0为不限",
+                    "type": "integer"
+                },
                 "buyorsell": {
                     "description": "买卖 - 0:买 1:卖",
                     "type": "integer"
@@ -8201,6 +8215,10 @@
                     "description": "景点热度",
                     "type": "integer"
                 },
+                "lotsize": {
+                    "description": "手数最小变动单位",
+                    "type": "integer"
+                },
                 "marketid": {
                     "description": "市场ID",
                     "type": "integer"

+ 13 - 0
docs/swagger.yaml

@@ -2810,6 +2810,9 @@ definitions:
       agreeunit:
         description: 合约单位
         type: number
+      buymaxqty:
+        description: 购买上限 [71] - 0为不限
+        type: integer
       currency:
         description: 货币
         type: string
@@ -2979,6 +2982,9 @@ definitions:
       agreeunit:
         description: 合约单位
         type: number
+      buymaxqty:
+        description: 购买上限 [71] - 0为不限
+        type: integer
       buyorsell:
         description: 买卖 - 0:买 1:卖
         type: integer
@@ -3015,6 +3021,9 @@ definitions:
       hotindex:
         description: 景点热度
         type: integer
+      lotsize:
+        description: 手数最小变动单位
+        type: integer
       marketid:
         description: 市场ID
         type: integer
@@ -7149,6 +7158,10 @@ paths:
         name: orderID
         required: true
         type: integer
+      - description: 资金账户,主要用于判断商品最大开仓手数;如未登录可不传。
+        in: query
+        name: accountID
+        type: integer
       produces:
       - application/json
       responses:

+ 32 - 8
models/hsby.go

@@ -301,18 +301,19 @@ type HsbyListingGoodsDetail struct {
 
 	Trademode int32 `json:"trademode"  xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
 
-	Last      float64 `json:"last" xorm:"-"`      // 现价
-	Limitup   float64 `json:"limitup" xorm:"-"`   // 涨停价
-	Limitdown float64 `json:"limitdown" xorm:"-"` // 跌停价
-	StepValue float64 `json:"stepvalue" xorm:"-"` // 价格最小变动单位
-	LotSize   int     `json:"lotsize" xorm:"-"`   // 手数最小变动单位
+	Last      float64 `json:"last" xorm:"-"`         // 现价
+	Limitup   float64 `json:"limitup" xorm:"-"`      // 涨停价
+	Limitdown float64 `json:"limitdown" xorm:"-"`    // 跌停价
+	StepValue float64 `json:"stepvalue" xorm:"-"`    // 价格最小变动单位
+	LotSize   int     `json:"lotsize" xorm:"-"`      // 手数最小变动单位
+	Buymaxqty int     `json:"buymaxqty"  xorm:"'-'"` // 购买上限 [71] - 0为不限
 }
 
 // GetHsbyListingGoodsDetail 获取二级市场(挂牌点选)商品信息详情
 // 参数 goodsID int 目标商品ID
 // 返回 *HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情,查询无结果返回nil
 // 返回 error error
-func GetHsbyListingGoodsDetail(goodsID int) (*HsbyListingGoodsDetail, error) {
+func GetHsbyListingGoodsDetail(goodsID, accountID int) (*HsbyListingGoodsDetail, error) {
 	engine := db.GetEngine()
 
 	details := make([]HsbyListingGoodsDetail, 0)
@@ -363,9 +364,18 @@ func GetHsbyListingGoodsDetail(goodsID int) (*HsbyListingGoodsDetail, error) {
 	stepValue := float64(hsbyListingGoodsDetail.Quoteminunit) * math.Pow(0.1, float64(hsbyListingGoodsDetail.Decimalplace))
 	hsbyListingGoodsDetail.StepValue, _ = strconv.ParseFloat(utils.FormatFloat(stepValue, int(hsbyListingGoodsDetail.Decimalplace)), 64)
 
-	// 计算手数最小变动单位
+	// 计算手数最小变动单位,改在上层进行设置,这里暂时设置成1
 	hsbyListingGoodsDetail.LotSize = 1
 
+	// 获取购买上限
+	if accountID != 0 {
+		buyMaxQty, err := GetCPTradeBuyLimit(goodsID, accountID)
+		if err != nil {
+			return nil, err
+		}
+		hsbyListingGoodsDetail.Buymaxqty = buyMaxQty
+	}
+
 	return &hsbyListingGoodsDetail, nil
 }
 
@@ -1627,10 +1637,13 @@ type HsbyMarketGoodsDetail struct {
 	Customername string `json:"customername"  xorm:"'CUSTOMERNAME'"` // 卖家名称
 
 	SellUserID int `json:"sellUserID" xorm:"SELLUSERID"` // 卖方UserID
+
+	LotSize   int `json:"lotsize" xorm:"-"`      // 手数最小变动单位
+	Buymaxqty int `json:"buymaxqty"  xorm:"'-'"` // 购买上限 [71] - 0为不限
 }
 
 // GetHsbyMarketGoodsDetail 获取商城商品详情(三级商城)
-func GetHsbyMarketGoodsDetail(orderID int) (*HsbyMarketGoodsDetail, error) {
+func GetHsbyMarketGoodsDetail(orderID, accountID int) (*HsbyMarketGoodsDetail, error) {
 	engine := db.GetEngine()
 
 	orders := make([]HsbyMarketGoodsDetail, 0)
@@ -1659,6 +1672,17 @@ func GetHsbyMarketGoodsDetail(orderID int) (*HsbyMarketGoodsDetail, error) {
 		return nil, nil
 	}
 	hsbyMarketGoodsDetail := orders[0]
+	// 最小交易手数在上层进行设置,这里暂设置为1
+	hsbyMarketGoodsDetail.LotSize = 1
+
+	// 获取购买上限
+	if accountID != 0 {
+		buyMaxQty, err := GetCPTradeBuyLimit(int(hsbyMarketGoodsDetail.Goodsid), accountID)
+		if err != nil {
+			return nil, err
+		}
+		hsbyMarketGoodsDetail.Buymaxqty = buyMaxQty
+	}
 
 	return &hsbyMarketGoodsDetail, nil
 }