cpTrade.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // Package cptrade 产能预售
  2. package cptrade
  3. import (
  4. "mtp2_if/db"
  5. "mtp2_if/global/app"
  6. "mtp2_if/global/e"
  7. "mtp2_if/logger"
  8. "net/http"
  9. "time"
  10. "github.com/gin-gonic/gin"
  11. )
  12. // QueryPresaleApplyReq 产能预售申请表请求参数
  13. type QueryPresaleApplyReq struct {
  14. UserID int `form:"userid" binding:"required"`
  15. ApplyID int `form:"applyid"`
  16. AccountID int `form:"accountid"`
  17. }
  18. // Cptradepresaleapply CPTRADE_PRESALEAPPLY 产能预售申请表
  19. type Cptradepresaleapply struct {
  20. Applyid int64 `json:"applyid" xorm:"'APPLYID'" binding:"required"` // 申请ID(181+Unix秒时间戳(10位)+xxxxxx)
  21. Userid int64 `json:"userid" xorm:"'USERID'"` // 申请人ID
  22. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 申请人账户ID
  23. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  24. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  25. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  26. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  27. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  28. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  29. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  30. Applystatus int64 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
  31. Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  32. Applytime time.Time `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  33. Firstremark string `json:"firstremark" xorm:"'FIRSTREMARK'"` // 初审备注
  34. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID
  35. Secondremark string `json:"secondremark" xorm:"'SECONDREMARK'"` // 复审备注
  36. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  37. }
  38. // TableName is
  39. func (Cptradepresaleapply) TableName() string {
  40. return "CPTRADE_PRESALEAPPLY"
  41. }
  42. // QueryPreasleApply 查询产能预售申请表信息
  43. // @Summary 查询产能预售申请表信息
  44. // @Produce json
  45. // @Security ApiKeyAuth
  46. // @Param userid query int true "账户ID"
  47. // @Param applyid query int false "申请ID"
  48. // @Param accountid query int false "资金账户ID"
  49. // @Success 200 {object} Cptradepresaleapply
  50. // @Failure 500 {object} app.Response
  51. // @Router /CPTrade/QueryPreasleApply [get]
  52. // @Tags 产能预售
  53. func QueryPreasleApply(c *gin.Context) {
  54. appG := app.Gin{C: c}
  55. // 获取请求参数
  56. var queryPresaleApplyReq QueryPresaleApplyReq
  57. if err := appG.C.ShouldBindQuery(&queryPresaleApplyReq); err != nil {
  58. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  59. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  60. return
  61. }
  62. // 查询数据
  63. engine := db.GetEngine()
  64. cptradepresaleapplys := make([]Cptradepresaleapply, 0)
  65. s := engine.Where("userid=?", queryPresaleApplyReq.UserID)
  66. if queryPresaleApplyReq.AccountID != 0 {
  67. s = s.And("accountid=?", queryPresaleApplyReq.AccountID)
  68. }
  69. if queryPresaleApplyReq.ApplyID != 0 {
  70. s = s.And("applyid=?", queryPresaleApplyReq.ApplyID)
  71. }
  72. // 执行查询
  73. err := s.Find(&cptradepresaleapplys)
  74. if err != nil {
  75. // 查询失败
  76. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  77. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  78. return
  79. }
  80. appG.Response(http.StatusOK, e.SUCCESS, cptradepresaleapplys)
  81. }
  82. // QueryCPTradeUserGoodsDataReq 远期订单查询请求参数
  83. type QueryCPTradeUserGoodsDataReq struct {
  84. AccountID int `form:"accountid" binding:"required"`
  85. }
  86. // Cptradeusergoodsdata 用户合约数据表 - 导历史 (远期订单数据)
  87. type Cptradeusergoodsdata struct {
  88. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID
  89. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  90. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 仓单标准ID
  91. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  92. Inqty int64 `json:"inqty" xorm:"'INQTY'"` // 转入量
  93. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 注销量
  94. Deliveryqty int64 `json:"deliveryqty" xorm:"'DELIVERYQTY'"` // 交割量
  95. Curpresaleqty int64 `json:"curpresaleqty" xorm:"'CURPRESALEQTY'"` // 当前预售量
  96. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量
  97. Presaledamount int64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额
  98. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  99. Freezeamount float64 `json:"freezeamount" xorm:"'FREEZEAMOUNT'"` // 冻结金额
  100. Hasspotfreeze int64 `json:"hasspotfreeze" xorm:"'HASSPOTFREEZE'"` // 是否有现货冻结 - 0:否 1:有
  101. Goodscode string `json:"GoodsCode"` // 订单商品代码
  102. Goodsname string `json:"GoodsName"` // 订单商品名称
  103. Wrstandardcode string `json:"WRStandardCode"` // 仓单标准代码
  104. Wrstandardname string `json:"WRStandardName"` // 仓单标准名称
  105. Enabledqty int64 `json:"EnabledQty"` // 可用量
  106. }
  107. // TableName is CPTRADE_USERGOODSDATA
  108. func (Cptradeusergoodsdata) TableName() string {
  109. return "CPTRADE_USERGOODSDATA"
  110. }
  111. // QueryCPTradeUserGoodsData 查询远期订单信息
  112. // @Summary 查询远期订单信息
  113. // @Produce json
  114. // @Security ApiKeyAuth
  115. // @Param accountid query int true "资金账户ID"
  116. // @Success 200 {object} Cptradeusergoodsdata
  117. // @Failure 500 {object} app.Response
  118. // @Router /CPTrade/QueryCPTradeUserGoodsData [get]
  119. // @Tags 产能预售
  120. func QueryCPTradeUserGoodsData(c *gin.Context) {
  121. appG := app.Gin{C: c}
  122. // 获取请求参数
  123. var queryCPTradeUserGoodsDataReq QueryCPTradeUserGoodsDataReq
  124. if err := appG.C.ShouldBindQuery(&queryCPTradeUserGoodsDataReq); err != nil {
  125. logger.GetLogger().Errorf("QueryCPTradeUserGoodsData failed: %s", err.Error())
  126. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  127. return
  128. }
  129. // 查询数据
  130. engine := db.GetEngine()
  131. cptradeusergoodsdatas := make([]Cptradeusergoodsdata, 0)
  132. err := engine.SQL(`select
  133. t.AccountID,
  134. t.GoodsID,
  135. t.WRStandardID,
  136. t.UserID,
  137. t.InQty,
  138. t.CancelQty,
  139. t.DeliveryQty,
  140. t.CurPresaleQty,
  141. t.PresaledQty,
  142. t.PresaledAmount,
  143. t.FreezeAmount,
  144. t.MarketID,
  145. t.HasSpotFreeze,
  146. g.GoodsCode,
  147. g.GoodsName,
  148. ws.WRStandardCode,
  149. ws.WRStandardName,
  150. (t.InQty - t.CancelQty - t.DeliveryQty - t.CurPresaleQty) EnabledQty
  151. from CPTrade_UserGoodsData t
  152. left join goods g on t.goodsid = g.goodsid
  153. left join WRStandard ws on t.wrstandardid = ws.wrstandardid
  154. where t.accountid = ?`, queryCPTradeUserGoodsDataReq.AccountID).Find(&cptradeusergoodsdatas)
  155. if err != nil {
  156. // 查询失败
  157. logger.GetLogger().Errorf("QueryCPTradeUserGoodsData failed: %s", err.Error())
  158. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  159. return
  160. }
  161. appG.Response(http.StatusOK, e.SUCCESS, cptradeusergoodsdatas)
  162. }