cpTrade.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. "strings"
  11. "time"
  12. "github.com/gin-gonic/gin"
  13. )
  14. // QueryPresaleApplyReq 产能预售申请表请求参数
  15. type QueryPresaleApplyReq struct {
  16. UserID int `form:"userid" binding:"required"`
  17. ApplyID int `form:"applyid"`
  18. AccountID int `form:"accountid"`
  19. }
  20. // Cptradepresaleapply CPTRADE_PRESALEAPPLY 产能预售申请表
  21. type Cptradepresaleapply struct {
  22. Applyid int64 `json:"applyid" xorm:"'APPLYID'" binding:"required"` // 申请ID(181+Unix秒时间戳(10位)+xxxxxx)
  23. Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID
  24. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID
  25. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  26. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  27. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  28. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  29. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  30. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  31. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  32. Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
  33. Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  34. Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  35. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID
  36. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  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. // TableName is
  45. // func (Cptradepresaleapply) TableName() string {
  46. // return "CPTRADE_PRESALEAPPLY"
  47. // }
  48. // QueryPreasleApply 查询产能预售申请信息
  49. // @Summary 查询产能预售申请信息
  50. // @Produce json
  51. // @Security ApiKeyAuth
  52. // @Param userid query int true "账户ID"
  53. // @Param applyid query int false "申请ID"
  54. // @Param accountid query int false "资金账户ID"
  55. // @Success 200 {object} Cptradepresaleapply
  56. // @Failure 500 {object} app.Response
  57. // @Router /CPTrade/QueryPreasleApply [get]
  58. // @Tags 产能预售
  59. func QueryPreasleApply(c *gin.Context) {
  60. appG := app.Gin{C: c}
  61. // 获取请求参数
  62. var req QueryPresaleApplyReq
  63. if err := appG.C.ShouldBindQuery(&req); err != nil {
  64. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  65. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  66. return
  67. }
  68. // 查询数据
  69. engine := db.GetEngine()
  70. datas := make([]Cptradepresaleapply, 0)
  71. // s := engine.Where("userid=?", req.UserID)
  72. // if req.AccountID > 0 {
  73. // s = s.And("accountid=?", req.AccountID)
  74. // }
  75. // if req.ApplyID > 0 {
  76. // s = s.And("applyid=?", req.ApplyID)
  77. // }
  78. sql := fmt.Sprintf(`select
  79. t.ApplyID,
  80. t.UserID,
  81. t.AccountID,
  82. t.GoodsCode,
  83. t.GoodsName,
  84. t.RelatedGoodsID,
  85. t.PresaleQty,
  86. t.StartTime,
  87. t.EndTime,
  88. t.AttachmentUrl,
  89. t.ApplyStatus,
  90. t.HandleStatus,
  91. t.ApplyTime,
  92. t.CreatorID,
  93. t.CreateTime,
  94. t.MarketID,
  95. t.TradeDate,
  96. g.goodscode RelatedGoodsCode,
  97. g.goodsname RelatedGoodsName,
  98. m.MarketName,
  99. m.TradeMode,
  100. e.enumdicname GoodUnit,
  101. g.GoodsID
  102. from CPTrade_PresaleApply t
  103. left join goods g on t.RelatedGoodsID = g.goodsid
  104. left join market m on t.MarketID = m.marketid
  105. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  106. where t.UserID = %d`, req.UserID)
  107. if req.AccountID > 0 {
  108. sql += fmt.Sprintf(` and t.AccountID = %d`, req.AccountID)
  109. }
  110. if req.ApplyID > 0 {
  111. sql += fmt.Sprintf(` and t.ApplyID = %d`, req.ApplyID)
  112. }
  113. if err := engine.SQL(sql).Find(&datas); err != nil {
  114. // 查询失败
  115. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  116. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  117. return
  118. }
  119. // 查询成功
  120. logger.GetLogger().Infof("QueryPreasleApply successed: %v", datas)
  121. appG.Response(http.StatusOK, e.SUCCESS, datas)
  122. }
  123. // QueryCPTradeUserGoodsDataReq 远期订单查询请求参数
  124. type QueryCPTradeUserGoodsDataReq struct {
  125. AccountID int `form:"accountid" binding:"required"`
  126. }
  127. // Cptradeusergoodsdata 用户合约数据表 - 导历史 (远期订单数据)
  128. type Cptradeusergoodsdata struct {
  129. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID
  130. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  131. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 仓单标准ID
  132. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  133. Inqty int64 `json:"inqty" xorm:"'INQTY'"` // 转入量(总数量)
  134. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销量
  135. Deliveryqty int64 `json:"deliveryqty" xorm:"'DELIVERYQTY'"` // 交割量
  136. Curpresaleqty int64 `json:"curpresaleqty" xorm:"'CURPRESALEQTY'"` // 当前预售量
  137. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量
  138. Presaledamount int64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额
  139. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  140. Freezeamount float64 `json:"freezeamount" xorm:"'FREEZEAMOUNT'"` // 冻结金额
  141. Hasspotfreeze int64 `json:"hasspotfreeze" xorm:"'HASSPOTFREEZE'"` // 是否有现货冻结 - 0:否 1:有
  142. Goodscode string `json:"GoodsCode" xorm:"'GOODSCODE'"` // 订单商品代码
  143. Goodsname string `json:"GoodsName" xorm:"'GOODSNAME'"` // 订单商品名称
  144. Wrstandardcode string `json:"WRStandardCode" xorm:"'WRSTANDARDCODE'"` // 仓单标准代码
  145. Wrstandardname string `json:"WRStandardName" xorm:"'WRSTANDARDNAME'"` // 仓单标准名称
  146. Enabledqty int64 `json:"EnabledQty" xorm:"'ENABLEDQTY'"` // 可用量
  147. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  148. }
  149. // TableName is CPTRADE_USERGOODSDATA
  150. // func (Cptradeusergoodsdata) TableName() string {
  151. // return "CPTRADE_USERGOODSDATA"
  152. // }
  153. // QueryUserGoodsData 查询远期订单信息
  154. // @Summary 查询远期订单信息
  155. // @Produce json
  156. // @Security ApiKeyAuth
  157. // @Param accountid query int true "资金账户ID"
  158. // @Success 200 {object} Cptradeusergoodsdata
  159. // @Failure 500 {object} app.Response
  160. // @Router /CPTrade/QueryUserGoodsData [get]
  161. // @Tags 产能预售
  162. func QueryUserGoodsData(c *gin.Context) {
  163. appG := app.Gin{C: c}
  164. // 获取请求参数
  165. var req QueryCPTradeUserGoodsDataReq
  166. if err := appG.C.ShouldBindQuery(&req); err != nil {
  167. logger.GetLogger().Errorf("QueryUserGoodsData failed: %s", err.Error())
  168. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  169. return
  170. }
  171. // 查询数据
  172. engine := db.GetEngine()
  173. datas := make([]Cptradeusergoodsdata, 0)
  174. if err := engine.SQL(`select
  175. t.AccountID,
  176. t.GoodsID,
  177. t.WRStandardID,
  178. t.UserID,
  179. t.InQty,
  180. t.CancelQty,
  181. t.DeliveryQty,
  182. t.CurPresaleQty,
  183. t.PresaledQty,
  184. t.PresaledAmount,
  185. t.FreezeAmount,
  186. t.MarketID,
  187. t.HasSpotFreeze,
  188. g.GoodsCode,
  189. g.GoodsName,
  190. ws.WRStandardCode,
  191. ws.WRStandardName,
  192. (t.InQty - t.CancelQty - t.DeliveryQty - t.CurPresaleQty) EnabledQty,
  193. e.enumdicname GoodUnit
  194. from CPTrade_UserGoodsData t
  195. left join goods g on t.goodsid = g.goodsid
  196. left join WRStandard ws on t.wrstandardid = ws.wrstandardid
  197. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  198. where t.accountid = ?`, req.AccountID).Find(&datas); err != nil {
  199. // 查询失败
  200. logger.GetLogger().Errorf("QueryUserGoodsData failed: %s", err.Error())
  201. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  202. return
  203. }
  204. // 查询成功
  205. logger.GetLogger().Infof("QueryUserGoodsData successed: %v", datas)
  206. appG.Response(http.StatusOK, e.SUCCESS, datas)
  207. }
  208. // QueryPositionCancelReq 查询远期订单注销申请请求参数
  209. type QueryPositionCancelReq struct {
  210. UserID int `form:"userid" binding:"required"`
  211. AccountID int `form:"accountid"`
  212. CancelID int `form:"cancelid"`
  213. }
  214. // Cptradepositioncancel 远期订单注销申请表
  215. type Cptradepositioncancel struct {
  216. Cancelid int64 `json:"cancelid" xorm:"'CANCELID'" binding:"required"` // 注销ID(SEQ_CPTRADE_POSITIONCANCEL)
  217. Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID
  218. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID
  219. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  220. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销数量
  221. Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
  222. Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  223. Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  224. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人ID
  225. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  226. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  227. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  228. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 订单商品代码
  229. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 订单商品名称
  230. Marketname string `json:"marketname" xorm:"'GOODSNAME'"` // 市场名称
  231. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  232. Creatorname string `json:"creatorname" xorm:"CREATORNAME"` // 创建人
  233. }
  234. // TableName is CPTRADE_POSITIONCANCEL
  235. // func (Cptradepositioncancel) TableName() string {
  236. // return "CPTRADE_POSITIONCANCEL"
  237. // }
  238. // QueryPositionCancel 查询远期订单注销申请信息
  239. // @Summary 查询远期订单注销申请信息
  240. // @Produce json
  241. // @Security ApiKeyAuth
  242. // @Param userid query int true "账户ID"
  243. // @Param cancelid query int false "注销ID"
  244. // @Param accountid query int false "资金账户ID"
  245. // @Success 200 {object} Cptradepositioncancel
  246. // @Failure 500 {object} app.Response
  247. // @Router /CPTrade/QueryPositionCancel [get]
  248. // @Tags 产能预售
  249. func QueryPositionCancel(c *gin.Context) {
  250. appG := app.Gin{C: c}
  251. // 获取请求参数
  252. var req QueryPositionCancelReq
  253. if err := appG.C.ShouldBindQuery(&req); err != nil {
  254. logger.GetLogger().Errorf("QueryPositionCancel failed: %s", err.Error())
  255. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  256. return
  257. }
  258. // 查询数据
  259. sql := fmt.Sprintf(`select
  260. t.CancelID,
  261. t.UserID,
  262. t.AccountID,
  263. t.GoodsID,
  264. t.CancelQty,
  265. t.ApplyStatus,
  266. t.HandleStatus,
  267. t.ApplyTime,
  268. t.CreatorID,
  269. t.CreateTime,
  270. t.TradeDate,
  271. t.MarketID,
  272. g.GoodsCode,
  273. g.GoodsName,
  274. m.MarketName,
  275. e.enumdicname GoodUnit,
  276. u.username CreatorName
  277. from CPTrade_PositionCancel t
  278. left join goods g on t.goodsid = g.goodsid
  279. left join market m on t.marketid = m.marketid
  280. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  281. left join systemmanager u on t.creatorid = u.autoid
  282. where t.userid = %d`, req.UserID)
  283. if req.AccountID > 0 {
  284. sql += fmt.Sprintf(` and t.AccountID= %d`, req.AccountID)
  285. }
  286. if req.CancelID > 0 {
  287. sql += fmt.Sprintf(` and t.CancelID= %d`, req.CancelID)
  288. }
  289. engine := db.GetEngine()
  290. datas := make([]Cptradepositioncancel, 0)
  291. if err := engine.SQL(sql).Find(&datas); err != nil {
  292. // 查询失败
  293. logger.GetLogger().Errorf("QueryPositionCancel failed: %s", err.Error())
  294. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  295. return
  296. }
  297. // 查询成功
  298. logger.GetLogger().Infof("QueryPositionCancel successed: %v", datas)
  299. appG.Response(http.StatusOK, e.SUCCESS, datas)
  300. }
  301. // QueryPresaleGoodsExReq 查询产能预售商品扩展请求参数
  302. type QueryPresaleGoodsExReq struct {
  303. GoodsID int `form:"goodsid"`
  304. MarketID int `form:"marketid"`
  305. PresaleMode int `form:"presalemode"`
  306. GoodsIDs string `form:"goodsids"`
  307. }
  308. // Cptradepresalegoodsex 产能预售商品扩展表
  309. type Cptradepresalegoodsex struct {
  310. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(预售)
  311. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  312. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  313. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  314. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  315. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  316. Presalemode int64 `json:"presalemode" xorm:"'PRESALEMODE'"` // 预售模式 - 1:一口价 2:大宗式竞拍
  317. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID - 根据预售模式选择市场
  318. Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价]
  319. Startprice float64 `json:"startprice" xorm:"'STARTPRICE'"` // 起拍价[大宗式竞拍]
  320. Floorprice float64 `json:"floorprice" xorm:"'FLOORPRICE'"` // 底价[大宗式竞拍]
  321. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  322. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  323. Relatedmarketid int64 `json:"relatedmarketid" xorm:"'RELATEDMARKETID'"` // 关联交易合约市场ID
  324. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新)
  325. Sellstatus int64 `json:"sellstatus" xorm:"'SELLSTATUS'"` // 卖方处理状态 - 1:卖方头寸未处理 2:卖方头寸已处理
  326. Presaledamount float64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额(预售结束时更新)
  327. Goodsdetail string `json:"goodsdetail" xorm:"'GOODSDETAIL'"` // 详情[大宗]
  328. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价[大宗]
  329. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  330. }
  331. // TableName is CPTRADE_PRESALEGOODSEX
  332. // func (Cptradepresalegoodsex) TableName() string {
  333. // return "CPTRADE_PRESALEGOODSEX"
  334. // }
  335. // QueryPresaleGoodsEx 查询产能预售商品扩展信息
  336. // @Summary 查询产能预售商品扩展信息
  337. // @Produce json
  338. // @Security ApiKeyAuth
  339. // @Param goodsid query int false "预售商品ID"
  340. // @Param marketid query int false "预售市场ID"
  341. // @Param presalemode query int false "预售模式 - 1:一口价 2:大宗式竞拍"
  342. // @Param goodsids query string false "预售商品ID列表 - 格式:1,2,3"
  343. // @Success 200 {object} Cptradepresalegoodsex
  344. // @Failure 500 {object} app.Response
  345. // @Router /CPTrade/QueryPresaleGoodsEx [get]
  346. // @Tags 产能预售
  347. func QueryPresaleGoodsEx(c *gin.Context) {
  348. appG := app.Gin{C: c}
  349. // FIXME: 由于数据中包括[]int类型,会造成校验报错,故暂时不使用
  350. // 获取请求参数
  351. var req QueryPresaleGoodsExReq
  352. if err := appG.C.ShouldBindQuery(&req); err != nil {
  353. logger.GetLogger().Errorf("QueryPresaleGoodsEx failed: %s", err.Error())
  354. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  355. return
  356. }
  357. // 查询数据
  358. engine := db.GetEngine()
  359. datas := make([]Cptradepresalegoodsex, 0)
  360. sql := `select
  361. t.GoodsID,
  362. t.ApplyID,
  363. t.UserID,
  364. t.AccountID,
  365. t.RelatedGoodsID,
  366. t.PresaleQty,
  367. t.StartTime,
  368. t.EndTime,
  369. t.AttachmentUrl,
  370. t.PresaleMode,
  371. t.MarketID,
  372. t.RefPrice,
  373. t.StartPrice,
  374. t.FloorPrice,
  375. t.CreateTime,
  376. t.TradeDate,
  377. t.RelatedMarketID,
  378. t.PresaledQty,
  379. t.PresaledAmount,
  380. t.SellStatus,
  381. t.GoodsDetail,
  382. t.TradePrice,
  383. e.enumdicname GoodUnit
  384. from CPTrade_PresaleGoodsEx t
  385. left join goods g on t.GoodsID = g.goodsid
  386. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  387. where 1=1 `
  388. s := engine.SQL(sql)
  389. if req.GoodsID > 0 {
  390. s = s.And("GoodsID=?", req.GoodsID)
  391. }
  392. if req.MarketID > 0 {
  393. s = s.And("MarketID=?", req.MarketID)
  394. }
  395. if req.PresaleMode > 0 {
  396. s = s.And("PresaleMode=?", req.PresaleMode)
  397. }
  398. if len(req.GoodsIDs) > 0 {
  399. // s = s.And("GoodsID in (?)", req.GoodsIDs)
  400. s = s.In("GOODSID", strings.Split(req.GoodsIDs, ","))
  401. }
  402. if err := s.Find(&datas); err != nil {
  403. // 查询失败
  404. logger.GetLogger().Errorf("QueryPresaleGoodsEx failed: %s", err.Error())
  405. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  406. return
  407. }
  408. // 查询成功
  409. logger.GetLogger().Infof("QueryPresaleGoodsEx successed: %v", datas)
  410. appG.Response(http.StatusOK, e.SUCCESS, datas)
  411. }
  412. // QueryCPTradeMyBidReq 我的出价信息查询请求参数
  413. type QueryCPTradeMyBidReq struct {
  414. AccountID int `form:"accountid" binding:"required"`
  415. GoodsID int `form:"goodsid"`
  416. MarketID int `form:"marketid"`
  417. }
  418. // QueryCPTradeMyBidRsp 我的出价信息查询
  419. type QueryCPTradeMyBidRsp struct {
  420. Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  421. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  422. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  423. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  424. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  425. Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
  426. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  427. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'" binding:"required"` // 成交价格
  428. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'" binding:"required"` // 成交数量
  429. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  430. OrderTotalPrice float64 `json:"ordertotalprice" xorm:"'ORDERTOTALPRICE'"` // 货款金额(委托总价格=委托价格*委托数量*合约单位)
  431. OrderTotalWeight int64 `json:"ordertotalweight" xorm:"'ORDERTOTALWEIGHT'"` // 竟拍总重量(委托总重量=委托数量*合约单位)
  432. TotalTotalPrice float64 `json:"totaltotalprice" xorm:"'TOTALTOTALPRICE'"` // 成交货款金额(成交总价格=委托价格*委托数量*合约单位)
  433. }
  434. // QueryCPTradeMyBidInfos 查询产能预售我的出价信息
  435. // @Summary 查询产能预售我的出价信息
  436. // @Produce json
  437. // @Security ApiKeyAuth
  438. // @Param accountid query int true "资金账户"
  439. // @Param marketid query int false "预售市场ID"
  440. // @Param goodsid query int false "预售商品ID"
  441. // @Success 200 {object} QueryCPTradeMyBidRsp
  442. // @Failure 500 {object} app.Response
  443. // @Router /CPTrade/QueryCPTradeMyBidInfos [get]
  444. // @Tags 产能预售
  445. func QueryCPTradeMyBidInfos(c *gin.Context) {
  446. appG := app.Gin{C: c}
  447. // 获取请求参数
  448. var req QueryCPTradeMyBidReq
  449. if err := appG.C.ShouldBindQuery(&req); err != nil {
  450. logger.GetLogger().Errorf("QueryCPTradeMyBidInfos failed: %s", err.Error())
  451. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  452. return
  453. }
  454. // 查询数据
  455. engine := db.GetEngine()
  456. datas := make([]QueryCPTradeMyBidRsp, 0)
  457. // 我的出价 -> 限价买建仓委托单
  458. sql := fmt.Sprintf(`select
  459. t.OrderID,
  460. t.MarketID,
  461. t.GoodsID,
  462. t.AccountID,
  463. t.OrderPrice,
  464. t.OrderQty,
  465. t.OrderTime,
  466. td.TradePrice,
  467. td.TradeQty,
  468. e.enumdicname GoodUnit,
  469. (t.orderprice * t.orderqty * g.agreeunit) OrderTotalPrice,
  470. (t.orderqty * g.agreeunit) OrderTotalWeight,
  471. (td.tradeprice * td.tradeqty * g.agreeunit) TotalTotalPrice
  472. from Trade_OrderDetail t
  473. left join Trade_TradeDetail td on t.orderid = td.OrderID
  474. left join goods g on t.goodsid = g.goodsid
  475. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  476. where t.BuyOrSell = 0 and t.BuildType = 1 and t.PriceMode = 2
  477. and t.AccountID = %d`, req.AccountID)
  478. s := engine.SQL(sql)
  479. if req.GoodsID > 0 {
  480. s = s.And("GoodsID=?", req.GoodsID)
  481. }
  482. if req.MarketID > 0 {
  483. s = s.And("MarketID=?", req.MarketID)
  484. }
  485. if err := s.Find(&datas); err != nil {
  486. // 查询失败
  487. logger.GetLogger().Errorf("QueryCPTradeMyBidInfos failed: %s", err.Error())
  488. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  489. return
  490. }
  491. // 查询成功
  492. logger.GetLogger().Infof("QueryCPTradeMyBidInfos successed: %v", datas)
  493. appG.Response(http.StatusOK, e.SUCCESS, datas)
  494. }