// Package cptrade 产能预售 package cptrade import ( "fmt" "mtp2_if/db" "mtp2_if/global/app" "mtp2_if/global/e" "mtp2_if/logger" "net/http" "time" "github.com/gin-gonic/gin" ) // QueryPresaleApplyReq 产能预售申请表请求参数 type QueryPresaleApplyReq struct { UserID int `form:"userid" binding:"required"` ApplyID int `form:"applyid"` AccountID int `form:"accountid"` } // Cptradepresaleapply CPTRADE_PRESALEAPPLY 产能预售申请表 type Cptradepresaleapply struct { Applyid int64 `json:"applyid" xorm:"'APPLYID'" binding:"required"` // 申请ID(181+Unix秒时间戳(10位)+xxxxxx) Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码 Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称 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'"` // 预售结束时间 Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址 Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销 Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态 Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间 Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd) Applyremark string `json:"applyremark" xorm:"'APPLYREMARK'"` // 申请备注 Relatedgoodscode string `json:"relatedgoodscode" xorm:"'RELATEDGOODSCODE'"` // 关联交易合约代码 Relatedgoodsname string `json:"relatedgoodsname" xorm:"'RELATEDGOODSNAME'"` // 关联交易合约名称 Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 预售市场名称 Trademode int64 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式 - 16:挂牌点选 21:大宗竞拍 Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位 Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID } // QueryPreasleApply 查询产能预售申请信息 // @Summary 查询产能预售申请信息 // @Produce json // @Security ApiKeyAuth // @Param userid query int true "账户ID" // @Param applyid query int false "申请ID" // @Param accountid query int false "资金账户ID" // @Success 200 {object} Cptradepresaleapply // @Failure 500 {object} app.Response // @Router /CPTrade/QueryPreasleApply [get] // @Tags 产能预售 func QueryPreasleApply(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryPresaleApplyReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 查询数据 engine := db.GetEngine() datas := make([]Cptradepresaleapply, 0) // s := engine.Where("userid=?", req.UserID) // if req.AccountID > 0 { // s = s.And("accountid=?", req.AccountID) // } // if req.ApplyID > 0 { // s = s.And("applyid=?", req.ApplyID) // } sql := fmt.Sprintf(`select t.ApplyID, t.UserID, t.AccountID, t.GoodsCode, t.GoodsName, t.RelatedGoodsID, t.PresaleQty, t.StartTime, t.EndTime, t.AttachmentUrl, t.ApplyStatus, t.HandleStatus, t.ApplyTime, t.CreatorID, t.CreateTime, t.MarketID, t.TradeDate, t.APPLYREMARK, g.goodscode RelatedGoodsCode, g.goodsname RelatedGoodsName, m.MarketName, m.TradeMode, e.enumdicname GoodUnit, g.GoodsID from CPTrade_PresaleApply t left join goods g on t.RelatedGoodsID = g.goodsid left join market m on t.MarketID = m.marketid left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit' where t.UserID = %d`, req.UserID) if req.AccountID > 0 { sql += fmt.Sprintf(` and t.AccountID = %d`, req.AccountID) } if req.ApplyID > 0 { sql += fmt.Sprintf(` and t.ApplyID = %d`, req.ApplyID) } if err := engine.SQL(sql).Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功 logger.GetLogger().Infof("QueryPreasleApply successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) } // QueryCPTradeUserGoodsDataReq 远期订单查询请求参数 type QueryCPTradeUserGoodsDataReq struct { AccountID int `form:"accountid" binding:"required"` } // Cptradeusergoodsdata 用户合约数据表 - 导历史 (远期订单数据) type Cptradeusergoodsdata struct { Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 仓单标准ID Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID Inqty int64 `json:"inqty" xorm:"'INQTY'"` // 转入量(总数量) Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销量 Deliveryqty int64 `json:"deliveryqty" xorm:"'DELIVERYQTY'"` // 交割量 Curpresaleqty int64 `json:"curpresaleqty" xorm:"'CURPRESALEQTY'"` // 当前预售量 Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量 Presaledamount int64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额 Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID Freezeamount float64 `json:"freezeamount" xorm:"'FREEZEAMOUNT'"` // 冻结金额 Hasspotfreeze int64 `json:"hasspotfreeze" xorm:"'HASSPOTFREEZE'"` // 是否有现货冻结 - 0:否 1:有 Goodscode string `json:"GoodsCode" xorm:"'GOODSCODE'"` // 订单商品代码 Goodsname string `json:"GoodsName" xorm:"'GOODSNAME'"` // 订单商品名称 Wrstandardcode string `json:"WRStandardCode" xorm:"'WRSTANDARDCODE'"` // 仓单标准代码 Wrstandardname string `json:"WRStandardName" xorm:"'WRSTANDARDNAME'"` // 仓单标准名称 Enabledqty int64 `json:"EnabledQty" xorm:"'ENABLEDQTY'"` // 可用量 Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位 } // TableName is CPTRADE_USERGOODSDATA // func (Cptradeusergoodsdata) TableName() string { // return "CPTRADE_USERGOODSDATA" // } // QueryUserGoodsData 查询远期订单信息 // @Summary 查询远期订单信息 // @Produce json // @Security ApiKeyAuth // @Param accountid query int true "资金账户ID" // @Success 200 {object} Cptradeusergoodsdata // @Failure 500 {object} app.Response // @Router /CPTrade/QueryUserGoodsData [get] // @Tags 产能预售 func QueryUserGoodsData(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryCPTradeUserGoodsDataReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryUserGoodsData failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 查询数据 engine := db.GetEngine() datas := make([]Cptradeusergoodsdata, 0) if err := engine.SQL(`select t.AccountID, t.GoodsID, t.WRStandardID, t.UserID, t.InQty, t.CancelQty, t.DeliveryQty, t.CurPresaleQty, t.PresaledQty, t.PresaledAmount, t.FreezeAmount, t.MarketID, t.HasSpotFreeze, g.GoodsCode, g.GoodsName, ws.WRStandardCode, ws.WRStandardName, (t.InQty - t.CancelQty - t.DeliveryQty - t.CurPresaleQty) EnabledQty, e.enumdicname GoodUnit from CPTrade_UserGoodsData t left join goods g on t.goodsid = g.goodsid left join WRStandard ws on t.wrstandardid = ws.wrstandardid left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit' where t.accountid = ?`, req.AccountID).Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryUserGoodsData failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功 logger.GetLogger().Infof("QueryUserGoodsData successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) } // QueryPositionCancelReq 查询远期订单注销申请请求参数 type QueryPositionCancelReq struct { UserID int `form:"userid" binding:"required"` AccountID int `form:"accountid"` CancelID int `form:"cancelid"` } // Cptradepositioncancel 远期订单注销申请表 type Cptradepositioncancel struct { Cancelid int64 `json:"cancelid" xorm:"'CANCELID'" binding:"required"` // 注销ID(SEQ_CPTRADE_POSITIONCANCEL) Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销数量 Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销 Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态 Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间 Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人ID Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd) Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 订单商品代码 Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 订单商品名称 Marketname string `json:"marketname" xorm:"'GOODSNAME'"` // 市场名称 Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位 Creatorname string `json:"creatorname" xorm:"CREATORNAME"` // 创建人 } // QueryPositionCancel 查询远期订单注销申请信息 // @Summary 查询远期订单注销申请信息 // @Produce json // @Security ApiKeyAuth // @Param userid query int true "账户ID" // @Param cancelid query int false "注销ID" // @Param accountid query int false "资金账户ID" // @Success 200 {object} Cptradepositioncancel // @Failure 500 {object} app.Response // @Router /CPTrade/QueryPositionCancel [get] // @Tags 产能预售 func QueryPositionCancel(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryPositionCancelReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryPositionCancel failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 查询数据 sql := fmt.Sprintf(`select t.CancelID, t.UserID, t.AccountID, t.GoodsID, t.CancelQty, t.ApplyStatus, t.HandleStatus, t.ApplyTime, t.CreatorID, t.CreateTime, t.TradeDate, t.MarketID, g.GoodsCode, g.GoodsName, m.MarketName, e.enumdicname GoodUnit, u.username CreatorName from CPTrade_PositionCancel t left join goods g on t.goodsid = g.goodsid left join market m on t.marketid = m.marketid left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit' left join systemmanager u on t.creatorid = u.autoid where t.userid = %d`, req.UserID) if req.AccountID > 0 { sql += fmt.Sprintf(` and t.AccountID= %d`, req.AccountID) } if req.CancelID > 0 { sql += fmt.Sprintf(` and t.CancelID= %d`, req.CancelID) } engine := db.GetEngine() datas := make([]Cptradepositioncancel, 0) if err := engine.SQL(sql).Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryPositionCancel failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功 logger.GetLogger().Infof("QueryPositionCancel successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) } // QueryPresaleGoodsExReq 查询产能预售商品扩展请求参数 type QueryPresaleGoodsExReq struct { GoodsID int `form:"goodsid"` MarketID int `form:"marketid"` PresaleMode int `form:"presalemode"` GoodsIDs string `form:"goodsids"` GoodsCode string `form:"goodscode"` } // QueryPresaleGoodsExRsp 产能预售商品扩展表 type QueryPresaleGoodsExRsp struct { Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(预售) 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'"` // 预售结束时间 Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址 Presalemode int64 `json:"presalemode" xorm:"'PRESALEMODE'"` // 预售模式 - 1:一口价 2:大宗式竞拍 Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID - 根据预售模式选择市场 Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价] Startprice float64 `json:"startprice" xorm:"'STARTPRICE'"` // 起拍价[大宗式竞拍] Floorprice float64 `json:"floorprice" xorm:"'FLOORPRICE'"` // 底价[大宗式竞拍] Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd) Relatedmarketid int64 `json:"relatedmarketid" xorm:"'RELATEDMARKETID'"` // 关联交易合约市场ID Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新) Sellstatus int64 `json:"sellstatus" xorm:"'SELLSTATUS'"` // 卖方处理状态 - 1:卖方头寸未处理 2:卖方头寸已处理 Presaledamount float64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额(预售结束时更新) Goodsdetail string `json:"goodsdetail" xorm:"'GOODSDETAIL'"` // 详情[大宗] Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价[大宗] Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位 } // QueryPresaleGoodsEx 查询产能预售商品扩展信息 // @Summary 查询产能预售商品扩展信息 // @Produce json // @Security ApiKeyAuth // @Param goodsid query int false "预售商品ID" // @Param marketid query int false "预售市场ID" // @Param presalemode query int false "预售模式 - 1:一口价 2:大宗式竞拍" // @Param goodsids query string false "预售商品ID列表 - 格式:1,2,3" // @Param goodscode query string false "预售商品代码" // @Success 200 {object} QueryPresaleGoodsExRsp // @Failure 500 {object} app.Response // @Router /CPTrade/QueryPresaleGoodsEx [get] // @Tags 产能预售 func QueryPresaleGoodsEx(c *gin.Context) { appG := app.Gin{C: c} // FIXME: 由于数据中包括[]int类型,会造成校验报错,故暂时不使用 // 获取请求参数 var req QueryPresaleGoodsExReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryPresaleGoodsEx failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 查询数据 engine := db.GetEngine() datas := make([]QueryPresaleGoodsExRsp, 0) sql := `select t.GoodsID, t.ApplyID, t.UserID, t.AccountID, t.RelatedGoodsID, t.PresaleQty, t.StartTime, t.EndTime, t.AttachmentUrl, t.PresaleMode, t.MarketID, t.RefPrice, t.StartPrice, t.FloorPrice, t.CreateTime, t.TradeDate, t.RelatedMarketID, t.PresaledQty, t.PresaledAmount, t.SellStatus, t.GoodsDetail, t.TradePrice, e.enumdicname GoodUnit from CPTrade_PresaleGoodsEx t left join goods g on t.GoodsID = g.goodsid left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit' where 1=1 ` if req.GoodsID > 0 { sql += fmt.Sprintf(" and t.GoodsID = %d", req.GoodsID) } if req.MarketID > 0 { sql += fmt.Sprintf(" and t.MarketID = %d", req.MarketID) } if req.PresaleMode > 0 { sql += fmt.Sprintf(" and t.PresaleMode = %d", req.PresaleMode) } if len(req.GoodsIDs) > 0 { // s = s.And("GoodsID in (?)", req.GoodsIDs) sql += fmt.Sprintf(" and t.GoodsID in (%s)", req.GoodsIDs) } if len(req.GoodsCode) > 0 { sql += fmt.Sprintf(" and g.GoodsCode = '%s'", req.GoodsCode) } if err := engine.SQL(sql).Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryPresaleGoodsEx failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功 logger.GetLogger().Infof("QueryPresaleGoodsEx successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) } // QueryCPTradeMyBidReq 我的出价信息查询请求参数 type QueryCPTradeMyBidReq struct { AccountID int `form:"accountid" binding:"required"` GoodsID int `form:"goodsid"` MarketID int `form:"marketid"` } // QueryCPTradeMyBidRsp 我的出价信息查询 type QueryCPTradeMyBidRsp struct { Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx) Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种] Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格 Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量 Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间 Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'" binding:"required"` // 成交价格 Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'" binding:"required"` // 成交数量 Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位 OrderTotalPrice float64 `json:"ordertotalprice" xorm:"'ORDERTOTALPRICE'"` // 货款金额(委托总价格=委托价格*委托数量*合约单位) OrderTotalWeight int64 `json:"ordertotalweight" xorm:"'ORDERTOTALWEIGHT'"` // 竞拍总重量(委托总重量=委托数量*合约单位) TotalTotalPrice float64 `json:"totaltotalprice" xorm:"'TOTALTOTALPRICE'"` // 成交货款金额(成交总价格=成交价格*成交数量*合约单位) } // QueryCPTradeMyBidInfos 查询产能预售我的出价信息 // @Summary 查询产能预售我的出价信息 // @Produce json // @Security ApiKeyAuth // @Param accountid query int true "资金账户" // @Param marketid query int false "预售市场ID" // @Param goodsid query int false "预售商品ID" // @Success 200 {object} QueryCPTradeMyBidRsp // @Failure 500 {object} app.Response // @Router /CPTrade/QueryCPTradeMyBidInfos [get] // @Tags 产能预售 func QueryCPTradeMyBidInfos(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryCPTradeMyBidReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryCPTradeMyBidInfos failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 查询数据 engine := db.GetEngine() datas := make([]QueryCPTradeMyBidRsp, 0) // 我的出价 -> 限价买建仓委托单 sql := fmt.Sprintf(`select t.OrderID, t.MarketID, t.GoodsID, t.AccountID, t.OrderPrice, t.OrderQty, t.OrderTime, td.TradePrice, td.TradeQty, e.enumdicname GoodUnit, (t.orderprice * t.orderqty * g.agreeunit) OrderTotalPrice, (t.orderqty * g.agreeunit) OrderTotalWeight, (td.tradeprice * td.tradeqty * g.agreeunit) TotalTotalPrice from Trade_OrderDetail t left join Trade_TradeDetail td on t.orderid = td.OrderID left join goods g on t.goodsid = g.goodsid left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit' where t.BuyOrSell = 0 and t.BuildType = 1 and t.PriceMode = 2 and t.AccountID = %d`, req.AccountID) if req.GoodsID > 0 { sql += fmt.Sprintf(" and t.GoodsID = %d", req.GoodsID) } if req.MarketID > 0 { sql += fmt.Sprintf(" and t.MarketID = %d", req.MarketID) } else { // 如果没有传市场ID,则肯定查询预售一口价挂牌(40)和预售大宗竞拍(41)两个市场的数据 // FIXME: 目前暂时直接写死市场ID sql += fmt.Sprintf(" and t.MarketID in (%s)", "40201,41201") } if err := engine.SQL(sql).Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryCPTradeMyBidInfos failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功 logger.GetLogger().Infof("QueryCPTradeMyBidInfos successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) } // QueryMyCPTradeGoodsReq 查询我的产能预售信息请求参数 type QueryMyCPTradeGoodsReq struct { AccountID int `form:"accountid" binding:"required"` } // QueryMyCPTradeGoodsRsp 我的产能预售信息 type QueryMyCPTradeGoodsRsp 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"` // 商品名称 Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID Currencyid int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID Goodunitid int64 `json:"goodunitid" xorm:"'GOODUNITID'"` // 报价单位ID Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位 Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位 Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 预售市场名称 Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位 Applyid int64 `json:"applyid" xorm:"'APPLYID'"` // 关联申请ID Userid int64 `json:"userid" xorm:"'USERID'"` // 卖方用户ID Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 卖方账户ID 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'"` // 预售结束时间 Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址 Presalemode int64 `json:"presalemode" xorm:"'PRESALEMODE'"` // 预售模式 - 1:一口价 2:大宗式竞拍 Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价] Startprice float64 `json:"startprice" xorm:"'STARTPRICE'"` // 起拍价[大宗式竞拍] Floorprice float64 `json:"floorprice" xorm:"'FLOORPRICE'"` // 底价[大宗式竞拍] Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd) Relatedmarketid int64 `json:"relatedmarketid" xorm:"'RELATEDMARKETID'"` // 关联交易合约市场ID Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新) Sellstatus int64 `json:"sellstatus" xorm:"'SELLSTATUS'"` // 卖方处理状态 - 1:卖方头寸未处理 2:卖方头寸已处理 Presaledamount float64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额(预售结束时更新) Goodsdetail string `json:"goodsdetail" xorm:"'GOODSDETAIL'"` // 详情[大宗] Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价[大宗] } // QueryMyCPTradeGoods 查询我的预售信息 // @Summary 查询我的预售信息 // @Produce json // @Security ApiKeyAuth // @Param accountid query int true "资金账户" // @Success 200 {object} QueryMyCPTradeGoodsRsp // @Failure 500 {object} app.Response // @Router /CPTrade/QueryMyCPTradeGoods [get] // @Tags 产能预售 func QueryMyCPTradeGoods(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryMyCPTradeGoodsReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryMyCPTradeGoods failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 查询数据 engine := db.GetEngine() datas := make([]QueryMyCPTradeGoodsRsp, 0) sql := fmt.Sprintf(`select t.Goodsid, t.Goodscode, t.Goodsname, t.Marketid, t.Currencyid, t.Goodunitid, t.Agreeunit, t.Decimalplace, m.Marketname, e.enumdicname GoodUnit, c.Applyid, c.Userid, c.Accountid, c.Relatedgoodsid, c.Presaleqty, c.Starttime, c.Endtime, c.Attachmenturl, c.Presalemode, c.Refprice, c.Startprice, c.Floorprice, c.Createtime, c.Tradedate, c.Relatedmarketid, c.Presaledqty, c.Sellstatus, c.Presaledamount, c.Goodsdetail, c.Tradeprice from goods t left join market m on t.marketid = m.marketid left join enumdicitem e on t.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit' left join CPTRADE_PRESALEGOODSEX c on t.goodsid = c.goodsid where m.trademode in (40,41) and c.Accountid = %d`, req.AccountID) if err := engine.SQL(sql).Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryMyCPTradeGoods failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功 logger.GetLogger().Infof("QueryMyCPTradeGoods successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) }