cpTrade.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. Relatedgoodscode string `json:"relatedgoodscode" xorm:"'RELATEDGOODSCODE'"` // 关联交易合约代码
  37. Relatedgoodsname string `json:"relatedgoodsname" xorm:"'RELATEDGOODSNAME'"` // 关联交易合约名称
  38. Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 预售市场名称
  39. Trademode int64 `json:"trademode" xorm:"'TRADEMODE'"` // 交易模式 - 16:挂牌点选 21:大宗竞拍
  40. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  41. }
  42. // TableName is
  43. func (Cptradepresaleapply) TableName() string {
  44. return "CPTRADE_PRESALEAPPLY"
  45. }
  46. // QueryPreasleApply 查询产能预售申请信息
  47. // @Summary 查询产能预售申请信息
  48. // @Produce json
  49. // @Security ApiKeyAuth
  50. // @Param userid query int true "账户ID"
  51. // @Param applyid query int false "申请ID"
  52. // @Param accountid query int false "资金账户ID"
  53. // @Success 200 {object} Cptradepresaleapply
  54. // @Failure 500 {object} app.Response
  55. // @Router /CPTrade/QueryPreasleApply [get]
  56. // @Tags 产能预售
  57. func QueryPreasleApply(c *gin.Context) {
  58. appG := app.Gin{C: c}
  59. // 获取请求参数
  60. var req QueryPresaleApplyReq
  61. if err := appG.C.ShouldBindQuery(&req); err != nil {
  62. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  63. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  64. return
  65. }
  66. // 查询数据
  67. engine := db.GetEngine()
  68. datas := make([]Cptradepresaleapply, 0)
  69. // s := engine.Where("userid=?", req.UserID)
  70. // if req.AccountID != 0 {
  71. // s = s.And("accountid=?", req.AccountID)
  72. // }
  73. // if req.ApplyID != 0 {
  74. // s = s.And("applyid=?", req.ApplyID)
  75. // }
  76. sql := fmt.Sprintf(`select
  77. t.ApplyID,
  78. t.UserID,
  79. t.AccountID,
  80. t.GoodsCode,
  81. t.GoodsName,
  82. t.RelatedGoodsID,
  83. t.PresaleQty,
  84. t.StartTime,
  85. t.EndTime,
  86. t.AttachmentUrl,
  87. t.ApplyStatus,
  88. t.HandleStatus,
  89. t.ApplyTime,
  90. t.CreatorID,
  91. t.CreateTime,
  92. t.MarketID,
  93. t.TradeDate,
  94. g.goodscode RelatedGoodsCode,
  95. g.goodsname RelatedGoodsName,
  96. m.MarketName,
  97. m.TradeMode,
  98. e.enumdicname GoodUnit
  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().Infof("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. // QueryCPTradeUserGoodsData 查询远期订单信息
  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/QueryCPTradeUserGoodsData [get]
  158. // @Tags 产能预售
  159. func QueryCPTradeUserGoodsData(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("QueryCPTradeUserGoodsData 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("QueryCPTradeUserGoodsData failed: %s", err.Error())
  198. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  199. return
  200. }
  201. // 查询成功
  202. logger.GetLogger().Infof("QueryCPTradeUserGoodsData 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'"` // 创建人
  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. }
  230. // TableName is CPTRADE_POSITIONCANCEL
  231. func (Cptradepositioncancel) TableName() string {
  232. return "CPTRADE_POSITIONCANCEL"
  233. }
  234. // QueryCPTradePositionCancel 查询远期订单注销申请信息
  235. // @Summary 查询远期订单注销申请信息
  236. // @Produce json
  237. // @Security ApiKeyAuth
  238. // @Param userid query int true "账户ID"
  239. // @Param cancelid query int false "注销ID"
  240. // @Param accountid query int false "资金账户ID"
  241. // @Success 200 {object} Cptradepositioncancel
  242. // @Failure 500 {object} app.Response
  243. // @Router /CPTrade/QueryCPTradePositionCancel [get]
  244. // @Tags 产能预售
  245. func QueryCPTradePositionCancel(c *gin.Context) {
  246. appG := app.Gin{C: c}
  247. // 获取请求参数
  248. var req QueryPositionCancelReq
  249. if err := appG.C.ShouldBindQuery(&req); err != nil {
  250. logger.GetLogger().Errorf("QueryCPTradePositionCancel failed: %s", err.Error())
  251. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  252. return
  253. }
  254. // 查询数据
  255. sql := fmt.Sprintf(`select
  256. t.CancelID,
  257. t.UserID,
  258. t.AccountID,
  259. t.GoodsID,
  260. t.CancelQty,
  261. t.ApplyStatus,
  262. t.HandleStatus,
  263. t.ApplyTime,
  264. t.CreatorID,
  265. t.CreateTime,
  266. t.TradeDate,
  267. t.MarketID,
  268. g.GoodsCode,
  269. g.GoodsName,
  270. m.MarketName,
  271. e.enumdicname GoodUnit
  272. from CPTrade_PositionCancel t
  273. left join goods g on t.goodsid = g.goodsid
  274. left join market m on t.marketid = m.marketid
  275. left join enumdicitem e on g.goodunitid = e.enumitemname and e.enumdiccode = 'goodsunit'
  276. where t.userid = %d`, req.UserID)
  277. if req.AccountID != 0 {
  278. sql += fmt.Sprintf(` and t.AccountID= %d`, req.AccountID)
  279. }
  280. if req.CancelID != 0 {
  281. sql += fmt.Sprintf(` and t.CancelID= %d`, req.CancelID)
  282. }
  283. engine := db.GetEngine()
  284. datas := make([]Cptradepositioncancel, 0)
  285. if err := engine.SQL(sql).Find(&datas); err != nil {
  286. // 查询失败
  287. logger.GetLogger().Errorf("QueryCPTradePositionCancel failed: %s", err.Error())
  288. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  289. return
  290. }
  291. // 查询成功
  292. logger.GetLogger().Infof("QueryCPTradePositionCancel successed: %v", datas)
  293. appG.Response(http.StatusOK, e.SUCCESS, datas)
  294. }