cpTrade.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // Package cptrade 产能预售
  2. package cptrade
  3. import (
  4. "fmt"
  5. "mtp2_if/db"
  6. "mtp2_if/global/app"
  7. "mtp2_if/global/e"
  8. "mtp2_if/logger"
  9. "net/http"
  10. "time"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // QueryPresaleApplyReq 产能预售申请表请求参数
  14. type QueryPresaleApplyReq struct {
  15. UserID int `form:"userid" binding:"required"`
  16. ApplyID int `form:"applyid"`
  17. AccountID int `form:"accountid"`
  18. }
  19. // Cptradepresaleapply CPTRADE_PRESALEAPPLY 产能预售申请表
  20. type Cptradepresaleapply struct {
  21. Applyid int64 `json:"applyid" xorm:"'APPLYID'" binding:"required"` // 申请ID(181+Unix秒时间戳(10位)+xxxxxx)
  22. Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID
  23. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID
  24. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  25. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  26. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  27. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  28. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  29. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  30. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  31. Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
  32. Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  33. Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  34. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID
  35. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  36. Applyremark string `json:"applyremark" xorm:"'APPLYREMARK'"` // 申请备注
  37. Relatedgoodscode string `json:"relatedgoodscode" xorm:"'RELATEDGOODSCODE'"` // 关联交易合约代码
  38. Relatedgoodsname string `json:"relatedgoodsname" xorm:"'RELATEDGOODSNAME'"` // 关联交易合约名称
  39. Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 预售市场名称
  40. Trademode int64 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式 - 16:挂牌点选 21:大宗竞拍
  41. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  42. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  43. }
  44. // QueryPreasleApply 查询产能预售申请信息
  45. // @Summary 查询产能预售申请信息
  46. // @Produce json
  47. // @Security ApiKeyAuth
  48. // @Param userid query int true "账户ID"
  49. // @Param applyid query int false "申请ID"
  50. // @Param accountid query int false "资金账户ID"
  51. // @Success 200 {object} Cptradepresaleapply
  52. // @Failure 500 {object} app.Response
  53. // @Router /CPTrade/QueryPreasleApply [get]
  54. // @Tags 产能预售
  55. func QueryPreasleApply(c *gin.Context) {
  56. appG := app.Gin{C: c}
  57. // 获取请求参数
  58. var req QueryPresaleApplyReq
  59. if err := appG.C.ShouldBindQuery(&req); err != nil {
  60. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  61. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  62. return
  63. }
  64. // 查询数据
  65. engine := db.GetEngine()
  66. datas := make([]Cptradepresaleapply, 0)
  67. // s := engine.Where("userid=?", req.UserID)
  68. // if req.AccountID > 0 {
  69. // s = s.And("accountid=?", req.AccountID)
  70. // }
  71. // if req.ApplyID > 0 {
  72. // s = s.And("applyid=?", req.ApplyID)
  73. // }
  74. sql := fmt.Sprintf(`select
  75. t.ApplyID,
  76. t.UserID,
  77. t.AccountID,
  78. t.GoodsCode,
  79. t.GoodsName,
  80. t.RelatedGoodsID,
  81. t.PresaleQty,
  82. t.StartTime,
  83. t.EndTime,
  84. t.AttachmentUrl,
  85. t.ApplyStatus,
  86. t.HandleStatus,
  87. t.ApplyTime,
  88. t.CreatorID,
  89. t.CreateTime,
  90. t.MarketID,
  91. t.TradeDate,
  92. t.APPLYREMARK,
  93. g.goodscode RelatedGoodsCode,
  94. g.goodsname RelatedGoodsName,
  95. m.MarketName,
  96. m.TradeMode,
  97. e.enumdicname GoodUnit,
  98. g.GoodsID
  99. from CPTrade_PresaleApply t
  100. left join goods g on t.RelatedGoodsID = g.goodsid
  101. left join market m on t.MarketID = m.marketid
  102. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  103. where t.UserID = %d`, req.UserID)
  104. if req.AccountID > 0 {
  105. sql += fmt.Sprintf(` and t.AccountID = %d`, req.AccountID)
  106. }
  107. if req.ApplyID > 0 {
  108. sql += fmt.Sprintf(` and t.ApplyID = %d`, req.ApplyID)
  109. }
  110. if err := engine.SQL(sql).Find(&datas); err != nil {
  111. // 查询失败
  112. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  113. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  114. return
  115. }
  116. // 查询成功
  117. logger.GetLogger().Debugln("QueryPreasleApply successed: %v", datas)
  118. appG.Response(http.StatusOK, e.SUCCESS, datas)
  119. }
  120. // QueryCPTradeUserGoodsDataReq 远期订单查询请求参数
  121. type QueryCPTradeUserGoodsDataReq struct {
  122. AccountID int `form:"accountid" binding:"required"`
  123. }
  124. // Cptradeusergoodsdata 用户合约数据表 - 导历史 (远期订单数据)
  125. type Cptradeusergoodsdata struct {
  126. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID
  127. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  128. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 仓单标准ID
  129. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  130. Inqty int64 `json:"inqty" xorm:"'INQTY'"` // 转入量(总数量)
  131. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销量
  132. Deliveryqty int64 `json:"deliveryqty" xorm:"'DELIVERYQTY'"` // 交割量
  133. Curpresaleqty int64 `json:"curpresaleqty" xorm:"'CURPRESALEQTY'"` // 当前预售量
  134. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量
  135. Presaledamount int64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额
  136. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  137. Freezeamount float64 `json:"freezeamount" xorm:"'FREEZEAMOUNT'"` // 冻结金额
  138. Hasspotfreeze int64 `json:"hasspotfreeze" xorm:"'HASSPOTFREEZE'"` // 是否有现货冻结 - 0:否 1:有
  139. Goodscode string `json:"GoodsCode" xorm:"'GOODSCODE'"` // 订单商品代码
  140. Goodsname string `json:"GoodsName" xorm:"'GOODSNAME'"` // 订单商品名称
  141. Wrstandardcode string `json:"WRStandardCode" xorm:"'WRSTANDARDCODE'"` // 仓单标准代码
  142. Wrstandardname string `json:"WRStandardName" xorm:"'WRSTANDARDNAME'"` // 仓单标准名称
  143. Enabledqty int64 `json:"EnabledQty" xorm:"'ENABLEDQTY'"` // 可用量
  144. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  145. }
  146. // TableName is CPTRADE_USERGOODSDATA
  147. // func (Cptradeusergoodsdata) TableName() string {
  148. // return "CPTRADE_USERGOODSDATA"
  149. // }
  150. // QueryUserGoodsData 查询远期订单信息
  151. // @Summary 查询远期订单信息
  152. // @Produce json
  153. // @Security ApiKeyAuth
  154. // @Param accountid query int true "资金账户ID"
  155. // @Success 200 {object} Cptradeusergoodsdata
  156. // @Failure 500 {object} app.Response
  157. // @Router /CPTrade/QueryUserGoodsData [get]
  158. // @Tags 产能预售
  159. func QueryUserGoodsData(c *gin.Context) {
  160. appG := app.Gin{C: c}
  161. // 获取请求参数
  162. var req QueryCPTradeUserGoodsDataReq
  163. if err := appG.C.ShouldBindQuery(&req); err != nil {
  164. logger.GetLogger().Errorf("QueryUserGoodsData failed: %s", err.Error())
  165. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  166. return
  167. }
  168. // 查询数据
  169. engine := db.GetEngine()
  170. datas := make([]Cptradeusergoodsdata, 0)
  171. if err := engine.SQL(`select
  172. t.AccountID,
  173. t.GoodsID,
  174. t.WRStandardID,
  175. t.UserID,
  176. t.InQty,
  177. t.CancelQty,
  178. t.DeliveryQty,
  179. t.CurPresaleQty,
  180. t.PresaledQty,
  181. t.PresaledAmount,
  182. t.FreezeAmount,
  183. t.MarketID,
  184. t.HasSpotFreeze,
  185. g.GoodsCode,
  186. g.GoodsName,
  187. ws.WRStandardCode,
  188. ws.WRStandardName,
  189. (t.InQty - t.CancelQty - t.DeliveryQty - t.CurPresaleQty) EnabledQty,
  190. e.enumdicname GoodUnit
  191. from CPTrade_UserGoodsData t
  192. left join goods g on t.goodsid = g.goodsid
  193. left join WRStandard ws on t.wrstandardid = ws.wrstandardid
  194. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  195. where t.accountid = ?`, req.AccountID).Find(&datas); err != nil {
  196. // 查询失败
  197. logger.GetLogger().Errorf("QueryUserGoodsData failed: %s", err.Error())
  198. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  199. return
  200. }
  201. // 查询成功
  202. logger.GetLogger().Debugln("QueryUserGoodsData successed: %v", datas)
  203. appG.Response(http.StatusOK, e.SUCCESS, datas)
  204. }
  205. // QueryPositionCancelReq 查询远期订单注销申请请求参数
  206. type QueryPositionCancelReq struct {
  207. UserID int `form:"userid" binding:"required"`
  208. AccountID int `form:"accountid"`
  209. CancelID int `form:"cancelid"`
  210. }
  211. // Cptradepositioncancel 远期订单注销申请表
  212. type Cptradepositioncancel struct {
  213. Cancelid int64 `json:"cancelid" xorm:"'CANCELID'" binding:"required"` // 注销ID(SEQ_CPTRADE_POSITIONCANCEL)
  214. Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID
  215. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID
  216. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  217. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销数量
  218. Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
  219. Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  220. Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  221. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人ID
  222. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  223. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  224. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  225. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 订单商品代码
  226. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 订单商品名称
  227. Marketname string `json:"marketname" xorm:"'GOODSNAME'"` // 市场名称
  228. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  229. Creatorname string `json:"creatorname" xorm:"CREATORNAME"` // 创建人
  230. }
  231. // QueryPositionCancel 查询远期订单注销申请信息
  232. // @Summary 查询远期订单注销申请信息
  233. // @Produce json
  234. // @Security ApiKeyAuth
  235. // @Param userid query int true "账户ID"
  236. // @Param cancelid query int false "注销ID"
  237. // @Param accountid query int false "资金账户ID"
  238. // @Success 200 {object} Cptradepositioncancel
  239. // @Failure 500 {object} app.Response
  240. // @Router /CPTrade/QueryPositionCancel [get]
  241. // @Tags 产能预售
  242. func QueryPositionCancel(c *gin.Context) {
  243. appG := app.Gin{C: c}
  244. // 获取请求参数
  245. var req QueryPositionCancelReq
  246. if err := appG.C.ShouldBindQuery(&req); err != nil {
  247. logger.GetLogger().Errorf("QueryPositionCancel failed: %s", err.Error())
  248. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  249. return
  250. }
  251. // 查询数据
  252. sql := fmt.Sprintf(`select
  253. t.CancelID,
  254. t.UserID,
  255. t.AccountID,
  256. t.GoodsID,
  257. t.CancelQty,
  258. t.ApplyStatus,
  259. t.HandleStatus,
  260. t.ApplyTime,
  261. t.CreatorID,
  262. t.CreateTime,
  263. t.TradeDate,
  264. t.MarketID,
  265. g.GoodsCode,
  266. g.GoodsName,
  267. m.MarketName,
  268. e.enumdicname GoodUnit,
  269. u.username CreatorName
  270. from CPTrade_PositionCancel t
  271. left join goods g on t.goodsid = g.goodsid
  272. left join market m on t.marketid = m.marketid
  273. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  274. left join systemmanager u on t.creatorid = u.autoid
  275. where t.userid = %d`, req.UserID)
  276. if req.AccountID > 0 {
  277. sql += fmt.Sprintf(` and t.AccountID= %d`, req.AccountID)
  278. }
  279. if req.CancelID > 0 {
  280. sql += fmt.Sprintf(` and t.CancelID= %d`, req.CancelID)
  281. }
  282. engine := db.GetEngine()
  283. datas := make([]Cptradepositioncancel, 0)
  284. if err := engine.SQL(sql).Find(&datas); err != nil {
  285. // 查询失败
  286. logger.GetLogger().Errorf("QueryPositionCancel failed: %s", err.Error())
  287. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  288. return
  289. }
  290. // 查询成功
  291. logger.GetLogger().Debugln("QueryPositionCancel successed: %v", datas)
  292. appG.Response(http.StatusOK, e.SUCCESS, datas)
  293. }
  294. // QueryPresaleGoodsExReq 查询产能预售商品扩展请求参数
  295. type QueryPresaleGoodsExReq struct {
  296. GoodsID int `form:"goodsid"`
  297. MarketID int `form:"marketid"`
  298. PresaleMode int `form:"presalemode"`
  299. GoodsIDs string `form:"goodsids"`
  300. GoodsCode string `form:"goodscode"`
  301. }
  302. // QueryPresaleGoodsExRsp 产能预售商品扩展表
  303. type QueryPresaleGoodsExRsp struct {
  304. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(预售)
  305. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  306. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  307. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  308. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  309. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  310. Presalemode int64 `json:"presalemode" xorm:"'PRESALEMODE'"` // 预售模式 - 1:一口价 2:大宗式竞拍
  311. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID - 根据预售模式选择市场
  312. Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价]
  313. Startprice float64 `json:"startprice" xorm:"'STARTPRICE'"` // 起拍价[大宗式竞拍]
  314. Floorprice float64 `json:"floorprice" xorm:"'FLOORPRICE'"` // 底价[大宗式竞拍]
  315. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  316. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  317. Relatedmarketid int64 `json:"relatedmarketid" xorm:"'RELATEDMARKETID'"` // 关联交易合约市场ID
  318. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新)
  319. Sellstatus int64 `json:"sellstatus" xorm:"'SELLSTATUS'"` // 卖方处理状态 - 1:卖方头寸未处理 2:卖方头寸已处理
  320. Presaledamount float64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额(预售结束时更新)
  321. Goodsdetail string `json:"goodsdetail" xorm:"'GOODSDETAIL'"` // 详情[大宗]
  322. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价[大宗]
  323. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  324. }
  325. // QueryPresaleGoodsEx 查询产能预售商品扩展信息
  326. // @Summary 查询产能预售商品扩展信息
  327. // @Produce json
  328. // @Security ApiKeyAuth
  329. // @Param goodsid query int false "预售商品ID"
  330. // @Param marketid query int false "预售市场ID"
  331. // @Param presalemode query int false "预售模式 - 1:一口价 2:大宗式竞拍"
  332. // @Param goodsids query string false "预售商品ID列表 - 格式:1,2,3"
  333. // @Param goodscode query string false "预售商品代码"
  334. // @Success 200 {object} QueryPresaleGoodsExRsp
  335. // @Failure 500 {object} app.Response
  336. // @Router /CPTrade/QueryPresaleGoodsEx [get]
  337. // @Tags 产能预售
  338. func QueryPresaleGoodsEx(c *gin.Context) {
  339. appG := app.Gin{C: c}
  340. // FIXME: 由于数据中包括[]int类型,会造成校验报错,故暂时不使用
  341. // 获取请求参数
  342. var req QueryPresaleGoodsExReq
  343. if err := appG.C.ShouldBindQuery(&req); err != nil {
  344. logger.GetLogger().Errorf("QueryPresaleGoodsEx failed: %s", err.Error())
  345. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  346. return
  347. }
  348. // 查询数据
  349. engine := db.GetEngine()
  350. datas := make([]QueryPresaleGoodsExRsp, 0)
  351. sql := `select
  352. t.GoodsID,
  353. t.ApplyID,
  354. t.UserID,
  355. t.AccountID,
  356. t.RelatedGoodsID,
  357. t.PresaleQty,
  358. t.StartTime,
  359. t.EndTime,
  360. t.AttachmentUrl,
  361. t.PresaleMode,
  362. t.MarketID,
  363. t.RefPrice,
  364. t.StartPrice,
  365. t.FloorPrice,
  366. t.CreateTime,
  367. t.TradeDate,
  368. t.RelatedMarketID,
  369. t.PresaledQty,
  370. t.PresaledAmount,
  371. t.SellStatus,
  372. t.GoodsDetail,
  373. t.TradePrice,
  374. e.enumdicname GoodUnit
  375. from CPTrade_PresaleGoodsEx t
  376. left join goods g on t.GoodsID = g.goodsid
  377. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  378. where 1=1 `
  379. if req.GoodsID > 0 {
  380. sql += fmt.Sprintf(" and t.GoodsID = %d", req.GoodsID)
  381. }
  382. if req.MarketID > 0 {
  383. sql += fmt.Sprintf(" and t.MarketID = %d", req.MarketID)
  384. }
  385. if req.PresaleMode > 0 {
  386. sql += fmt.Sprintf(" and t.PresaleMode = %d", req.PresaleMode)
  387. }
  388. if len(req.GoodsIDs) > 0 {
  389. // s = s.And("GoodsID in (?)", req.GoodsIDs)
  390. sql += fmt.Sprintf(" and t.GoodsID in (%s)", req.GoodsIDs)
  391. }
  392. if len(req.GoodsCode) > 0 {
  393. sql += fmt.Sprintf(" and g.GoodsCode = '%s'", req.GoodsCode)
  394. }
  395. if err := engine.SQL(sql).Find(&datas); err != nil {
  396. // 查询失败
  397. logger.GetLogger().Errorf("QueryPresaleGoodsEx failed: %s", err.Error())
  398. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  399. return
  400. }
  401. // 查询成功
  402. logger.GetLogger().Debugln("QueryPresaleGoodsEx successed: %v", datas)
  403. appG.Response(http.StatusOK, e.SUCCESS, datas)
  404. }
  405. // QueryCPTradeMyBidReq 我的出价信息查询请求参数
  406. type QueryCPTradeMyBidReq struct {
  407. AccountID int `form:"accountid" binding:"required"`
  408. GoodsID int `form:"goodsid"`
  409. MarketID int `form:"marketid"`
  410. }
  411. // QueryCPTradeMyBidRsp 我的出价信息查询
  412. type QueryCPTradeMyBidRsp struct {
  413. Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  414. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  415. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  416. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  417. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  418. Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
  419. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  420. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'" binding:"required"` // 成交价格
  421. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'" binding:"required"` // 成交数量
  422. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  423. OrderTotalPrice float64 `json:"ordertotalprice" xorm:"'ORDERTOTALPRICE'"` // 货款金额(委托总价格=委托价格*委托数量*合约单位)
  424. OrderTotalWeight int64 `json:"ordertotalweight" xorm:"'ORDERTOTALWEIGHT'"` // 竞拍总重量(委托总重量=委托数量*合约单位)
  425. TotalTotalPrice float64 `json:"totaltotalprice" xorm:"'TOTALTOTALPRICE'"` // 成交货款金额(成交总价格=成交价格*成交数量*合约单位)
  426. }
  427. // QueryCPTradeMyBidInfos 查询产能预售我的出价信息
  428. // @Summary 查询产能预售我的出价信息
  429. // @Produce json
  430. // @Security ApiKeyAuth
  431. // @Param accountid query int true "资金账户"
  432. // @Param marketid query int false "预售市场ID"
  433. // @Param goodsid query int false "预售商品ID"
  434. // @Success 200 {object} QueryCPTradeMyBidRsp
  435. // @Failure 500 {object} app.Response
  436. // @Router /CPTrade/QueryCPTradeMyBidInfos [get]
  437. // @Tags 产能预售
  438. func QueryCPTradeMyBidInfos(c *gin.Context) {
  439. appG := app.Gin{C: c}
  440. // 获取请求参数
  441. var req QueryCPTradeMyBidReq
  442. if err := appG.C.ShouldBindQuery(&req); err != nil {
  443. logger.GetLogger().Errorf("QueryCPTradeMyBidInfos failed: %s", err.Error())
  444. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  445. return
  446. }
  447. // 查询数据
  448. engine := db.GetEngine()
  449. datas := make([]QueryCPTradeMyBidRsp, 0)
  450. // 我的出价 -> 限价买建仓委托单
  451. sql := fmt.Sprintf(`select
  452. t.OrderID,
  453. t.MarketID,
  454. t.GoodsID,
  455. t.AccountID,
  456. t.OrderPrice,
  457. t.OrderQty,
  458. t.OrderTime,
  459. td.TradePrice,
  460. td.TradeQty,
  461. e.enumdicname GoodUnit,
  462. (t.orderprice * t.orderqty * g.agreeunit) OrderTotalPrice,
  463. (t.orderqty * g.agreeunit) OrderTotalWeight,
  464. (td.tradeprice * td.tradeqty * g.agreeunit) TotalTotalPrice
  465. from Trade_OrderDetail t
  466. left join Trade_TradeDetail td on t.orderid = td.OrderID
  467. left join goods g on t.goodsid = g.goodsid
  468. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  469. where t.BuyOrSell = 0 and t.BuildType = 1 and t.PriceMode = 2 and t.AccountID = %d`, req.AccountID)
  470. if req.GoodsID > 0 {
  471. sql += fmt.Sprintf(" and t.GoodsID = %d", req.GoodsID)
  472. }
  473. if req.MarketID > 0 {
  474. sql += fmt.Sprintf(" and t.MarketID = %d", req.MarketID)
  475. } else {
  476. // 如果没有传市场ID,则肯定查询预售一口价挂牌(40)和预售大宗竞拍(41)两个市场的数据
  477. // FIXME: 目前暂时直接写死市场ID
  478. sql += fmt.Sprintf(" and t.MarketID in (%s)", "40201,41201")
  479. }
  480. if err := engine.SQL(sql).Find(&datas); err != nil {
  481. // 查询失败
  482. logger.GetLogger().Errorf("QueryCPTradeMyBidInfos failed: %s", err.Error())
  483. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  484. return
  485. }
  486. // 查询成功
  487. logger.GetLogger().Debugln("QueryCPTradeMyBidInfos successed: %v", datas)
  488. appG.Response(http.StatusOK, e.SUCCESS, datas)
  489. }
  490. // QueryMyCPTradeGoodsReq 查询我的预售信息请求参数
  491. type QueryMyCPTradeGoodsReq struct {
  492. AccountID int `form:"accountid" binding:"required"`
  493. }
  494. // QueryMyCPTradeGoodsRsp 我的预售信息
  495. type QueryMyCPTradeGoodsRsp struct {
  496. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  497. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(预售)
  498. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称(预售)
  499. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  500. Currencyid int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 报价货币ID
  501. Goodunitid int64 `json:"goodunitid" xorm:"'GOODUNITID'"` // 报价单位ID
  502. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  503. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  504. Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 预售市场名称
  505. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  506. Applyid int64 `json:"applyid" xorm:"'APPLYID'"` // 关联申请ID
  507. Userid int64 `json:"userid" xorm:"'USERID'"` // 卖方用户ID
  508. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 卖方账户ID
  509. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  510. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  511. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  512. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  513. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  514. Presalemode int64 `json:"presalemode" xorm:"'PRESALEMODE'"` // 预售模式 - 1:一口价 2:大宗式竞拍
  515. Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价]
  516. Startprice float64 `json:"startprice" xorm:"'STARTPRICE'"` // 起拍价[大宗式竞拍]
  517. Floorprice float64 `json:"floorprice" xorm:"'FLOORPRICE'"` // 底价[大宗式竞拍]
  518. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  519. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  520. Relatedmarketid int64 `json:"relatedmarketid" xorm:"'RELATEDMARKETID'"` // 关联交易合约市场ID
  521. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新)
  522. Sellstatus int64 `json:"sellstatus" xorm:"'SELLSTATUS'"` // 卖方处理状态 - 1:卖方头寸未处理 2:卖方头寸已处理
  523. Presaledamount float64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额(预售结束时更新)
  524. Goodsdetail string `json:"goodsdetail" xorm:"'GOODSDETAIL'"` // 详情[大宗]
  525. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价[大宗]
  526. Relatedgoodscode string `json:"relatedgoodscode" xorm:"'RELATEDGOODSCODE'" binding:"required"` // 商品代码(订单)
  527. Relatedgoodsname string `json:"relatedgoodsname" xorm:"'RELATEDGOODSNAME'" binding:"required"` // 商品名称(订单)
  528. }
  529. // QueryMyCPTradeGoods 查询我的预售信息
  530. // @Summary 查询我的预售信息
  531. // @Produce json
  532. // @Security ApiKeyAuth
  533. // @Param accountid query int true "资金账户"
  534. // @Success 200 {object} QueryMyCPTradeGoodsRsp
  535. // @Failure 500 {object} app.Response
  536. // @Router /CPTrade/QueryMyCPTradeGoods [get]
  537. // @Tags 产能预售
  538. func QueryMyCPTradeGoods(c *gin.Context) {
  539. appG := app.Gin{C: c}
  540. // 获取请求参数
  541. var req QueryMyCPTradeGoodsReq
  542. if err := appG.C.ShouldBindQuery(&req); err != nil {
  543. logger.GetLogger().Errorf("QueryMyCPTradeGoods failed: %s", err.Error())
  544. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  545. return
  546. }
  547. // 查询数据
  548. engine := db.GetEngine()
  549. datas := make([]QueryMyCPTradeGoodsRsp, 0)
  550. sql := fmt.Sprintf(`select
  551. t.Goodsid,
  552. t.Goodscode,
  553. t.Goodsname,
  554. t.Marketid,
  555. t.Currencyid,
  556. t.Goodunitid,
  557. t.Agreeunit,
  558. t.Decimalplace,
  559. m.Marketname,
  560. e.enumdicname GoodUnit,
  561. c.Applyid,
  562. c.Userid,
  563. c.Accountid,
  564. c.Relatedgoodsid,
  565. c.Presaleqty,
  566. c.Starttime,
  567. c.Endtime,
  568. c.Attachmenturl,
  569. c.Presalemode,
  570. c.Refprice,
  571. c.Startprice,
  572. c.Floorprice,
  573. c.Createtime,
  574. c.Tradedate,
  575. c.Relatedmarketid,
  576. c.Presaledqty,
  577. c.Sellstatus,
  578. c.Presaledamount,
  579. c.Goodsdetail,
  580. c.Tradeprice,
  581. g1.Goodscode RelatedGoodsCode,
  582. g1.GoodsName RelatedGoodsName
  583. from goods t
  584. left join market m on t.marketid = m.marketid
  585. left join enumdicitem e on t.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  586. left join CPTRADE_PRESALEGOODSEX c on t.goodsid = c.goodsid
  587. left join goods g1 on c.Relatedgoodsid = g1.goodsid
  588. where m.trademode in (40,41) and c.Accountid = %d`, req.AccountID)
  589. if err := engine.SQL(sql).Find(&datas); err != nil {
  590. // 查询失败
  591. logger.GetLogger().Errorf("QueryMyCPTradeGoods failed: %s", err.Error())
  592. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  593. return
  594. }
  595. // 查询成功
  596. logger.GetLogger().Debugln("QueryMyCPTradeGoods successed: %v", datas)
  597. appG.Response(http.StatusOK, e.SUCCESS, datas)
  598. }
  599. // QueryCPTradeOrderDetailReq 查询产能预售委托单信息请求参数
  600. type QueryCPTradeOrderDetailReq struct {
  601. GoodsID int `form:"goodsid"`
  602. GoodsIDs string `form:"goodsids"`
  603. MarketID int `form:"marketid"`
  604. }
  605. // QueryCPTradeOrderDetailRsq 产能预售委托单信息
  606. type QueryCPTradeOrderDetailRsq struct {
  607. Strorderid string `json:"strorderid" xorm:"'STRORDERID'" binding:"required"` // 委托单号
  608. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'" binding:"required"` // 交易日(yyyyMMdd)
  609. Buildtype int64 `json:"buildtype" xorm:"'BUILDTYPE'" binding:"required"` // 委托单据类型 - 1:建仓 2:平仓 3:先平后建
  610. Preorderid int64 `json:"preorderid" xorm:"'PREORDERID'"` // 关联预埋单号(止盈止损单时填写)
  611. Cancelorderid int64 `json:"cancelorderid" xorm:"'CANCELORDERID'"` // 撤单单号(撤单时填写)
  612. Relatedid int64 `json:"relatedid" xorm:"'RELATEDID'"` // 关联单号(交割单)
  613. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  614. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  615. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  616. Memberuserid int64 `json:"memberuserid" xorm:"'MEMBERUSERID'" binding:"required"` // 所属会员UserID
  617. Buyorsell int64 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  618. Pricemode int64 `json:"pricemode" xorm:"'PRICEMODE'" binding:"required"` // 取价方式 - 1:市价 2: 限价
  619. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  620. Marketmaxsub float64 `json:"marketmaxsub" xorm:"'MARKETMAXSUB'"` // 市价最大偏移范围
  621. Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
  622. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  623. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 撤单数量
  624. Openqty int64 `json:"openqty" xorm:"'OPENQTY'"` // 开仓数量(先建后平操作,需要记录)
  625. Closeqty int64 `json:"closeqty" xorm:"'CLOSEQTY'"` // 平仓数量(先建后平操作 需要记录)
  626. Opentradeqty int64 `json:"opentradeqty" xorm:"'OPENTRADEQTY'"` // 开仓成交数量(先建后平操作,需要记录)
  627. Closetradeqty int64 `json:"closetradeqty" xorm:"'CLOSETRADEQTY'"` // 平仓成交数量(先建后平操作,需要记录)
  628. Freezemargin float64 `json:"freezemargin" xorm:"'FREEZEMARGIN'"` // 冻结保证金(冻结交易金额)
  629. Unfreezemargin float64 `json:"unfreezemargin" xorm:"'UNFREEZEMARGIN'"` // 解冻保证金
  630. Freezecharge float64 `json:"freezecharge" xorm:"'FREEZECHARGE'"` // 冻结手续费
  631. Unfreezecharge float64 `json:"unfreezecharge" xorm:"'UNFREEZECHARGE'"` // 解冻手续费
  632. Openfreezecharge float64 `json:"openfreezecharge" xorm:"'OPENFREEZECHARGE'"` // 开仓冻结手续费(先建后平操作,需要记录)
  633. Closefreezecharge float64 `json:"closefreezecharge" xorm:"'CLOSEFREEZECHARGE'"` // 平仓冻结手续费(先建后平操作,需要记录)
  634. Openunfreezecharge float64 `json:"openunfreezecharge" xorm:"'OPENUNFREEZECHARGE'"` // 开仓解冻手续费(先建后平操作,需要记录)
  635. Closeunfreezecharge float64 `json:"closeunfreezecharge" xorm:"'CLOSEUNFREEZECHARGE'"` // 平仓解冻手续费(先建后平操作,需要记录)
  636. Validtype int64 `json:"validtype" xorm:"'VALIDTYPE'" binding:"required"` // 有效类型 - 1当日有效 2本周有效 3指定日期有效 4一直有效 5指定时间有效
  637. Validtime time.Time `json:"validtime" xorm:"'VALIDTIME'"` // 有效期限
  638. Volumetype int64 `json:"volumetype" xorm:"'VOLUMETYPE'"` // 当时间有效类型为 “立即执行否则取消 IOC” 时,需要此项 - 0:任意量 1:最小量(暂时不支持) 2:全部量
  639. Operatetype int64 `json:"operatetype" xorm:"'OPERATETYPE'" binding:"required"` // 操作类型 - 1:正常下单 2:斩仓 3:转单 4:结算撤单 5:系统卖出(适用于先平后建的卖出) 6:行情源报价 7:(结算)到期强平 8:(结算)协议转让 9:系统对冲单 10:(结算)到期无效 11:交割协议转让 12:交割协议平仓 13:交割成交(所有权) 14:管理端强行平仓 15:管理端协议转让
  640. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  641. Ordersrc int64 `json:"ordersrc" xorm:"'ORDERSRC'"` // 委托来源 - 1:客户端 2:管理端 3:风控服务 4:交割服务 5:交易服务 6:交易日结 7:商品强平 8:管理端商品退市强平 9:交易接口 10:交割服务商被动(受托竞价) 11:预埋触发
  642. Orderstatus int64 `json:"orderstatus" xorm:"'ORDERSTATUS'"` // 委托状态 - 1: 委托请求 2:待冻结 3:委托成功 4: 委托失败 5:配对成功 6: 已撤销 7:部分成交 8:已成交 9:部成部撤 10:成交失败 11:已拒绝 12:经过摘牌(先摘后挂专用-先摘后挂已摘过) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用)
  643. Operatorid int64 `json:"operatorid" xorm:"'OPERATORID'"` // 登录账号(LoginID)
  644. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  645. Clientordertime time.Time `json:"clientordertime" xorm:"'CLIENTORDERTIME'"` // 客户端委托时间
  646. Clientticket string `json:"clientticket" xorm:"'CLIENTTICKET'"` // 客户端流水号
  647. UUID string `json:"uuid" xorm:"'UUID'"` // 发起端唯一id
  648. Clienttype int64 `json:"clienttype" xorm:"'CLIENTTYPE'"` // 客户端类型 - 0:保留为未填终端类型 1:PC管理端 2:PC交易端 3:手机客户端_安卓 4:网页客户端 5:微信客户端 6:手机客户端_苹果 7:网上开户客户端 8:无效终端编号 9:报价终端(中江)
  649. Retcode int64 `json:"retcode" xorm:"'RETCODE'"` // 错误代码
  650. Tradeproperty int64 `json:"tradeproperty" xorm:"'TRADEPROPERTY'"` // 交易属性
  651. Listingselecttype int64 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
  652. Delistingtype int64 `json:"delistingtype" xorm:"'DELISTINGTYPE'"` // 摘牌类型 - 1:价格最优 2:点选成交
  653. Marginalgorithm int64 `json:"marginalgorithm" xorm:"'MARGINALGORITHM'"` // 保证金收取方式 1:比率 2:固定
  654. Marginvalue float64 `json:"marginvalue" xorm:"'MARGINVALUE'"` // 即市保证金设置值
  655. Openfeealgorithm int64 `json:"openfeealgorithm" xorm:"'OPENFEEALGORITHM'"` // 建仓手续费收取方式 1:比率 2:固定
  656. Openmemberchargevalue float64 `json:"openmemberchargevalue" xorm:"'OPENMEMBERCHARGEVALUE'"` // 建仓会员手续费设置值
  657. Openexchagechargevalue float64 `json:"openexchagechargevalue" xorm:"'OPENEXCHAGECHARGEVALUE'"` // 建仓交易所手续费设置值
  658. Closefeealgorithm int64 `json:"closefeealgorithm" xorm:"'CLOSEFEEALGORITHM'"` // 平仓手续费收取方式 1:比率 2:固定
  659. Closememberchargevalue float64 `json:"closememberchargevalue" xorm:"'CLOSEMEMBERCHARGEVALUE'"` // 平仓会员手续费设置值
  660. Closeexchagechargevalue float64 `json:"closeexchagechargevalue" xorm:"'CLOSEEXCHAGECHARGEVALUE'"` // 平仓交易所手续费设置值
  661. Optiontype int64 `json:"optiontype" xorm:"'OPTIONTYPE'"` // 期权类型 - 1:认购(看涨) 2:认沽(看跌)
  662. Premium float64 `json:"premium" xorm:"'PREMIUM'"` // 权利金
  663. Ispreexercise int64 `json:"ispreexercise" xorm:"'ISPREEXERCISE'"` // 是否预申报- 0:否 1:是
  664. Preexerciseprice float64 `json:"preexerciseprice" xorm:"'PREEXERCISEPRICE'"` // 预申报价格
  665. Isconfirmexercise int64 `json:"isconfirmexercise" xorm:"'ISCONFIRMEXERCISE'"` // 是否确认行权- 0:否 1:是
  666. Quoteid int64 `json:"quoteid" xorm:"'QUOTEID'"` // 报价单ID
  667. Gcaccountid int64 `json:"gcaccountid" xorm:"'GCACCOUNTID'"` // 账户ID[合约币种]
  668. Sessionid int64 `json:"sessionid" xorm:"'SESSIONID'"` // 会话ID
  669. }
  670. // QueryCPTradeOrderDetail 查询产能预售委托单信息
  671. // @Summary 查询产能预售委托单信息
  672. // @Produce json
  673. // @Security ApiKeyAuth
  674. // @Param goodsid query int false "预售商品ID"
  675. // @Param marketid query int false "预售市场ID"
  676. // @Param goodsids query string false "预售商品ID列表 - 格式:1,2,3"
  677. // @Success 200 {object} QueryCPTradeOrderDetailRsq
  678. // @Failure 500 {object} app.Response
  679. // @Router /CPTrade/QueryCPTradeOrderDetail [get]
  680. // @Tags 产能预售
  681. func QueryCPTradeOrderDetail(c *gin.Context) {
  682. appG := app.Gin{C: c}
  683. // FIXME: 由于数据中包括[]int类型,会造成校验报错,故暂时不使用
  684. // 获取请求参数
  685. var req QueryCPTradeOrderDetailReq
  686. if err := appG.C.ShouldBindQuery(&req); err != nil {
  687. logger.GetLogger().Errorf("QueryCPTradeOrderDetail failed: %s", err.Error())
  688. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  689. return
  690. }
  691. // 查询数据
  692. engine := db.GetEngine()
  693. datas := make([]QueryCPTradeOrderDetailRsq, 0)
  694. sql := `select
  695. to_char(t.orderid) strOrderID,
  696. t.*
  697. from Trade_OrderDetail t
  698. where t.BuyOrSell = 1 and t.BuildType = 2 and t.MarketID in (40201,41201)`
  699. if req.GoodsID > 0 {
  700. sql += fmt.Sprintf(" and t.GoodsID = %d", req.GoodsID)
  701. }
  702. if req.MarketID > 0 {
  703. sql += fmt.Sprintf(" and t.MarketID = %d", req.MarketID)
  704. }
  705. if len(req.GoodsIDs) > 0 {
  706. // s = s.And("GoodsID in (?)", req.GoodsIDs)
  707. sql += fmt.Sprintf(" and t.GoodsID in (%s)", req.GoodsIDs)
  708. }
  709. if err := engine.SQL(sql).Find(&datas); err != nil {
  710. // 查询失败
  711. logger.GetLogger().Errorf("QueryCPTradeOrderDetail failed: %s", err.Error())
  712. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  713. return
  714. }
  715. // 查询成功
  716. logger.GetLogger().Debugln("QueryCPTradeOrderDetail successed: %v", datas)
  717. appG.Response(http.StatusOK, e.SUCCESS, datas)
  718. }