tjmd.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/9/7 16:01
  4. * @Modify : 2021/9/7 16:01
  5. * @note : 天津麦顿
  6. */
  7. package models
  8. import (
  9. "fmt"
  10. "mtp2_if/db"
  11. "mtp2_if/utils"
  12. )
  13. // TjmdQuoteGoods 掉期报价列表
  14. type TjmdQuoteGoods struct {
  15. GOODSID int64 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // 合约id
  16. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 合约代码
  17. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 合约名称
  18. REFGOODSID int64 `json:"refgoodsid" xorm:"'REFGOODSID'"` // 标的合约id
  19. REFGOODSCODE string `json:"refgoodscode" xorm:"'REFGOODSCODE'"` // 标的合约代码
  20. REFGOODSNAME string `json:"refgoodsname" xorm:"'REFGOODSNAME'"` // 标的合约名称
  21. SELLQTY float64 `json:"sellqty" xorm:"'SELLQTY'"` // 卖量(暂不做, 无值, 保留字段)
  22. BUYQTY float64 `json:"buyqty" xorm:"'BUYQTY'"` // 买量(暂不做, 无值, 保留字段)
  23. GOODSGROUPID int64 `json:"goodsgroupid" xorm:"'GOODSGROUPID'" form:"goodsgroupid"` // 商品组ID(自增ID)
  24. GOODSGROUPNAME string `json:"goodsgroupname" xorm:"'GOODSGROUPNAME'"` // 商品组名称
  25. UserType int32 `json:"-" form:"usertype"` // 用户类型
  26. FtMarketIds string `json:"-" form:"marketids"` // 市场id, 格式 1,2,3
  27. }
  28. func (r *TjmdQuoteGoods) calc() {
  29. }
  30. func (r *TjmdQuoteGoods) buildSql() string {
  31. var sqlId utils.SQLVal = `
  32. select g1.goodsid,
  33. g1.goodscode,
  34. g1.goodsname,
  35. g2.goodsid refgoodsid,
  36. g2.goodscode refgoodscode,
  37. g2.goodsname refgoodsname,
  38. gp.goodsgroupid,
  39. gp.goodsgroupname,
  40. gp.outergroupcode goodsgroupcode,
  41. gp.marketid
  42. from goods g1
  43. left join goods g2
  44. on g1.refgoodsid = g2.goodsid
  45. left join goodsgroup gp
  46. on g1.goodsgroupid = gp.goodsgroupid
  47. where 1=1
  48. `
  49. sqlId.JoinEx(r.FtMarketIds != "", fmt.Sprintf(" and gp.marketid in(%v)", r.FtMarketIds))
  50. return sqlId.String()
  51. }
  52. // GetDataEx 获取掉期报价列表
  53. func (r *TjmdQuoteGoods) GetDataEx() (interface{}, error) {
  54. sData := make([]TjmdQuoteGoods, 0)
  55. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  56. for i := range sData {
  57. sData[i].calc()
  58. }
  59. return sData, err
  60. }
  61. // TjmdTradeOrderDetail 买卖大厅
  62. type TjmdTradeOrderDetail struct {
  63. ORDERID string `json:"orderid" xorm:"'ORDERID'"` // 委托单号
  64. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // 商品id
  65. BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'" form:"buyorsell"` // 买卖方向 0-买 1-卖
  66. ORDERPRICE SFLOAT64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  67. ORDERQTY int64 `json:"orderqty" xorm:"'ORDERQTY'"` // 委托数量
  68. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  69. USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称(已脱敏)
  70. PRICEMODE int32 `json:"pricemode" xorm:"'PRICEMODE'"` // 取价方式 - 1:市价 2: 限价 3:浮动价
  71. MARKETMAXSUB float64 `json:"marketmaxsub" xorm:"'MARKETMAXSUB'"` // 市价最大偏移范围 [浮动价 - 点差]
  72. PageEx `xorm:"extends"`
  73. USERTYPE int32 `json:"-" form:"usertype"` // 用户类型
  74. FtMarketIds string `json:"-" form:"marketids"` // 市场id, 格式 1,2,3
  75. }
  76. func (r *TjmdTradeOrderDetail) calc() {
  77. r.USERNAME = EncryptByStar(r.USERNAME)
  78. }
  79. func (r *TjmdTradeOrderDetail) buildSql() string {
  80. var sqlId utils.SQLVal = `
  81. select to_char(t.orderid) orderid,
  82. t.buyorsell,
  83. t.goodsid,
  84. t.orderprice,
  85. t.orderqty - t.tradeqty orderqty,
  86. u.userid,
  87. u.accountname username,
  88. t.orderstatus,
  89. t.pricemode,
  90. t.marketmaxsub,
  91. g.marketid
  92. from trade_orderdetail t
  93. left join taaccount ta
  94. on t.accountid = ta.accountid
  95. left join useraccount u
  96. on ta.relateduserid = u.userid
  97. left join goods g on t.goodsid=g.goodsid
  98. where 1 = 1
  99. and t.orderstatus in (3, 7)
  100. and u.usertype = decode(%v,2,5,-1)
  101. `
  102. // 投资者只能看到会员的单, 会员只能看到投资者的单, decode(%v,2,5,-1)
  103. sqlId.FormatParam(r.USERTYPE)
  104. sqlId.And("t.GOODSID", r.GOODSID)
  105. sqlId.And("t.BUYORSELL", r.BUYORSELL)
  106. sqlId.JoinEx(r.FtMarketIds != "", fmt.Sprintf(" and g.marketid in(%v)", r.FtMarketIds))
  107. if r.BUYORSELL == 0 {
  108. sqlId.Join(" order by t.orderprice desc, t.ordertime desc")
  109. } else {
  110. sqlId.Join(" order by t.orderprice, t.ordertime desc")
  111. }
  112. sqlId.Page(r.Page, r.PageSize)
  113. return sqlId.String()
  114. }
  115. // GetDataByPage 获取买卖大厅
  116. func (r *TjmdTradeOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
  117. sData := make([]TjmdTradeOrderDetail, 0)
  118. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  119. for i := range sData {
  120. sData[i].calc()
  121. }
  122. if len(sData) > 0 {
  123. r.Total = sData[0].Total
  124. }
  125. return sData, err, r.Page, r.PageSize, r.Total
  126. }
  127. // TjmdTransferApply 协议转让申请
  128. type TjmdTransferApply struct {
  129. APPLYID int64 `json:"applyid" xorm:"'APPLYID'"` // 申请ID(自增ID SEQ_TRADE_HOLDTRANSFERAPPLY)
  130. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  131. INACCOUNTID int64 `json:"-" xorm:"INACCOUNTID" form:"inaccountid"` // 转入方资金ID(确认方) --对方申请
  132. OUTACCOUNTID int64 `json:"-" xorm:"OUTACCOUNTID" form:"outaccountid"` // 转出方资金ID(申请方) --我的申请
  133. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  134. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  135. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  136. QTYDECIMALPLACE int `json:"-" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
  137. BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖 - 0:买 1:卖
  138. TRANSFERPRICE float64 `json:"transferprice" xorm:"'TRANSFERPRICE'"` // 转让价格(协议价格)
  139. QTY SFLOAT64 `json:"qty" xorm:"'QTY'"` // 转让数量(数量)
  140. TRANSFERAMOUNT float64 `json:"transferamount" xorm:"'TRANSFERAMOUNT'"` // 转让总金额(金额)
  141. APPLYSTATUS int32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态 - 0:未提交 1:待审核 2:审核中 3:审核通过 4:审核拒绝 5:审核失败 6:已撤销
  142. TRADEID string `json:"tradeid" xorm:"'TRADEID'"` // 成交单号(关联持仓)
  143. APPLYTIME string `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间(时间)
  144. AUDITREMARK string `json:"auditremark" xorm:"'AUDITREMARK'"` // 审核备注(拒绝原因?)
  145. ApplyType int32 `json:"-" form:"applytype"` // 类型 1-我的申请 2-对方申请
  146. FtMarketIds string `json:"-" form:"marketids"` // 市场 格式 1,2,3
  147. FtAccountIds string `json:"-" form:"accountids"` // 资金账号 格式 1,2,3
  148. }
  149. func (r *TjmdTransferApply) calc() {
  150. if r.QTYDECIMALPLACE != 0 {
  151. r.QTY.Power10(r.QTYDECIMALPLACE * -1)
  152. }
  153. }
  154. func (r *TjmdTransferApply) buildSql() string {
  155. var sqlId utils.SQLVal = `
  156. select t.applyid,
  157. t.marketid,
  158. t.goodsid,
  159. g.goodscode,
  160. g.goodsname,
  161. g.qtydecimalplace,
  162. t.buyorsell,
  163. t.transferprice,
  164. t.qty,
  165. t.transferamount,
  166. t.applystatus,
  167. to_char(t.tradeid) tradeid,
  168. to_char(t.applytime,'yyyy-mm-dd hh24:mi:ss') applytime,
  169. t.auditremark
  170. from trade_holdtransferapply t
  171. left join goods g
  172. on t.goodsid = g.goodsid
  173. where 1=1
  174. `
  175. sqlId.JoinEx(r.FtMarketIds != "", fmt.Sprintf(" and t.marketid in(%v)", r.FtMarketIds))
  176. if r.ApplyType == 1 {
  177. sqlId.JoinEx(r.FtAccountIds != "", fmt.Sprintf(" and t.outaccountid in(%v)", r.FtAccountIds))
  178. } else if r.ApplyType == 2 {
  179. sqlId.JoinEx(r.FtAccountIds != "", fmt.Sprintf(" and t.inaccountid in(%v)", r.FtAccountIds))
  180. }
  181. return sqlId.String()
  182. }
  183. // GetDataEx 获取协议转让申请
  184. func (r *TjmdTransferApply) GetDataEx() (interface{}, error) {
  185. sData := make([]TjmdTransferApply, 0)
  186. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  187. for i := range sData {
  188. sData[i].calc()
  189. }
  190. return sData, err
  191. }