|
|
@@ -0,0 +1,137 @@
|
|
|
+/**
|
|
|
+* @Author: zou.yingbin
|
|
|
+* @Create : 2021/9/7 16:01
|
|
|
+* @Modify : 2021/9/7 16:01
|
|
|
+* @note : 天津麦顿
|
|
|
+ */
|
|
|
+
|
|
|
+package models
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "mtp2_if/db"
|
|
|
+ "mtp2_if/utils"
|
|
|
+)
|
|
|
+
|
|
|
+// TjmdQuoteGoods 掉期报价列表
|
|
|
+type TjmdQuoteGoods struct {
|
|
|
+ GOODSID int64 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // 合约id
|
|
|
+ GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 合约代码
|
|
|
+ GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 合约名称
|
|
|
+ REFGOODSID int64 `json:"refgoodsid" xorm:"'REFGOODSID'"` // 标的合约id
|
|
|
+ REFGOODSCODE string `json:"refgoodscode" xorm:"'REFGOODSCODE'"` // 标的合约代码
|
|
|
+ REFGOODSNAME string `json:"refgoodsname" xorm:"'REFGOODSNAME'"` // 标的合约名称
|
|
|
+ SELLQTY float64 `json:"sellqty" xorm:"'SELLQTY'"` // 卖量(暂不做, 无值, 保留字段)
|
|
|
+ BUYQTY float64 `json:"buyqty" xorm:"'BUYQTY'"` // 买量(暂不做, 无值, 保留字段)
|
|
|
+ GOODSGROUPID int64 `json:"goodsgroupid" xorm:"'GOODSGROUPID'" form:"goodsgroupid"` // 商品组ID(自增ID)
|
|
|
+ GOODSGROUPNAME string `json:"goodsgroupname" xorm:"'GOODSGROUPNAME'"` // 商品组名称
|
|
|
+
|
|
|
+ UserType int32 `json:"-" form:"usertype"` // 用户类型
|
|
|
+ FtMarketIds string `json:"-" form:"marketids"` // 市场id, 格式 1,2,3
|
|
|
+}
|
|
|
+
|
|
|
+func (r *TjmdQuoteGoods) calc() {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *TjmdQuoteGoods) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+select g1.goodsid,
|
|
|
+ g1.goodscode,
|
|
|
+ g1.goodsname,
|
|
|
+ g2.goodsid refgoodsid,
|
|
|
+ g2.goodscode refgoodscode,
|
|
|
+ g2.goodsname refgoodsname,
|
|
|
+ gp.goodsgroupid,
|
|
|
+ gp.goodsgroupname,
|
|
|
+ gp.outergroupcode goodsgroupcode,
|
|
|
+ gp.marketid
|
|
|
+ from goods g1
|
|
|
+ left join goods g2
|
|
|
+ on g1.refgoodsid = g2.goodsid
|
|
|
+ left join goodsgroup gp
|
|
|
+ on g1.goodsgroupid = gp.goodsgroupid
|
|
|
+ where 1=1
|
|
|
+`
|
|
|
+ sqlId.JoinEx(r.FtMarketIds != "", fmt.Sprintf(" and gp.marketid in(%v)", r.FtMarketIds))
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 获取掉期报价列表
|
|
|
+func (r *TjmdQuoteGoods) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]TjmdQuoteGoods, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
+}
|
|
|
+
|
|
|
+// TjmdTradeOrderDetail 买卖大厅
|
|
|
+type TjmdTradeOrderDetail struct {
|
|
|
+ ORDERID string `json:"orderid" xorm:"'ORDERID'"` // 委托单号
|
|
|
+ GOODSID int32 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // 商品id
|
|
|
+ BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'" form:"buyorsell"` // 买卖方向 0-买 1-卖
|
|
|
+ ORDERPRICE SFLOAT64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
|
|
|
+ ORDERQTY int64 `json:"orderqty" xorm:"'ORDERQTY'"` // 委托数量
|
|
|
+ USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
|
|
|
+ USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称(已脱敏)
|
|
|
+ PageEx `xorm:"extends"`
|
|
|
+
|
|
|
+ USERTYPE int32 `json:"-" form:"usertype"` // 用户类型
|
|
|
+ FtMarketIds string `json:"-" form:"marketids"` // 市场id, 格式 1,2,3
|
|
|
+}
|
|
|
+
|
|
|
+func (r *TjmdTradeOrderDetail) calc() {
|
|
|
+ r.USERNAME = EncryptByStar(r.USERNAME)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *TjmdTradeOrderDetail) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+select to_char(t.orderid) orderid,
|
|
|
+ t.buyorsell,
|
|
|
+ t.goodsid,
|
|
|
+ t.orderprice,
|
|
|
+ t.orderqty - t.tradeqty orderqty,
|
|
|
+ u.userid,
|
|
|
+ u.accountname username,
|
|
|
+ t.orderstatus,
|
|
|
+ g.marketid
|
|
|
+ from trade_orderdetail t
|
|
|
+ left join taaccount ta
|
|
|
+ on t.accountid = ta.accountid
|
|
|
+ left join useraccount u
|
|
|
+ on ta.relateduserid = u.userid
|
|
|
+ left join goods g on t.goodsid=g.goodsid
|
|
|
+ where 1 = 1
|
|
|
+ and t.orderstatus in (3, 7)
|
|
|
+ and u.usertype = decode(%v,2,5,-1)
|
|
|
+`
|
|
|
+ // 投资者只能看到会员的单, 会员只能看到投资者的单, decode(%v,2,5,-1)
|
|
|
+ sqlId.FormatParam(r.USERTYPE)
|
|
|
+ sqlId.And("t.GOODSID", r.GOODSID)
|
|
|
+ sqlId.And("t.BUYORSELL", r.BUYORSELL)
|
|
|
+ sqlId.AndEx("g.marketid", r.FtMarketIds, r.FtMarketIds != "")
|
|
|
+ if r.BUYORSELL == 0 {
|
|
|
+ sqlId.Join(" order by t.orderprice desc, t.ordertime desc")
|
|
|
+ } else {
|
|
|
+ sqlId.Join(" order by t.orderprice, t.ordertime desc")
|
|
|
+ }
|
|
|
+ sqlId.Page(r.Page, r.PageSize)
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataByPage 获取买卖大厅
|
|
|
+func (r *TjmdTradeOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
|
|
|
+ sData := make([]TjmdTradeOrderDetail, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ if len(sData) > 0 {
|
|
|
+ r.Total = sData[0].Total
|
|
|
+ }
|
|
|
+ return sData, err, r.Page, r.PageSize, r.Total
|
|
|
+}
|