|
@@ -1,6 +1,7 @@
|
|
|
package models
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "encoding/hex"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"math"
|
|
"math"
|
|
|
"mtp2_if/db"
|
|
"mtp2_if/db"
|
|
@@ -906,6 +907,19 @@ func GetHsbyMyPackages(accountIDs string, takeOrderStatus int) ([]HsbyMyPackage,
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // FIXME:- 目前暂时在服务端对手机号码进行解密
|
|
|
|
|
+ key, _ := hex.DecodeString(utils.AESSecretKey)
|
|
|
|
|
+ for i := range myPackages {
|
|
|
|
|
+ myPackage := &myPackages[i]
|
|
|
|
|
+
|
|
|
|
|
+ // 解密手机号码
|
|
|
|
|
+ if phonenum, err := hex.DecodeString(myPackage.Phonenum); err == nil { // hex -> []byte
|
|
|
|
|
+ if mobile, err := utils.AESDecrypt(phonenum, key); err == nil {
|
|
|
|
|
+ myPackage.Phonenum = string(mobile)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return myPackages, nil
|
|
return myPackages, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -938,3 +952,108 @@ func GetHsbyProvincesAndCities(provinceID int) ([]Division, error) {
|
|
|
|
|
|
|
|
return divisions, nil
|
|
return divisions, nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// HsbyBuyMyTradeDetail "我的订单 - 已完成"单据信息(一二级市场成交单,包括历史数据)
|
|
|
|
|
+type HsbyBuyMyTradeDetail struct {
|
|
|
|
|
+ Orderid string `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 单号(成交单号)
|
|
|
|
|
+ Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
|
|
|
|
|
+ Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
|
|
|
|
|
+ Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
|
|
|
|
|
+ Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
|
|
|
|
|
+ Price float64 `json:"price" xorm:"'PRICE'"` // 价格
|
|
|
|
|
+ Qty int64 `json:"qty" xorm:"'QTY'" binding:"required"` // 数量
|
|
|
|
|
+ Time time.Time `json:"time" xorm:"'TIME'" binding:"required"` // 时间
|
|
|
|
|
+ Amount float64 `json:"amount" xorm:"'AMOUNT'"` // 金额 = 价格 * 数量 * 合约单位
|
|
|
|
|
+
|
|
|
|
|
+ Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
|
|
|
|
|
+ Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
|
|
|
|
|
+ Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
|
|
|
|
|
+ Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
|
|
|
|
|
+
|
|
|
|
|
+ Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
|
|
|
|
|
+
|
|
|
|
|
+ Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
|
|
|
|
|
+
|
|
|
|
|
+ Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
|
|
|
|
|
+
|
|
|
|
|
+ Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// GetHsbyBuyMyTradeDetails 获取"我的订单 - 已完成"单据信息(一二级市场成交单,包括历史数据)
|
|
|
|
|
+// 输入 accountIDs string 资金账户列表
|
|
|
|
|
+// 输出 []HsbyBuyMyTradeDetail "我的订单 - 已完成"单据信息
|
|
|
|
|
+// 输出 error error
|
|
|
|
|
+func GetHsbyBuyMyTradeDetails(accountIDs string) ([]HsbyBuyMyTradeDetail, error) {
|
|
|
|
|
+ // 获取市场信息
|
|
|
|
|
+ markets, err := GetMarkets()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ engine := db.GetEngine()
|
|
|
|
|
+ marketIDs := "" // 我的订单包括一二级市场卖方向成交单(包括历史成交单)
|
|
|
|
|
+ // 默认取 TradeMode = 16
|
|
|
|
|
+ for _, v := range markets {
|
|
|
|
|
+ if v.Trademode == 16 || v.Trademode == 71 {
|
|
|
|
|
+ if len(marketIDs) == 0 {
|
|
|
|
|
+ marketIDs = strconv.Itoa(int(v.Marketid))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ marketIDs += "," + strconv.Itoa(int(v.Marketid))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ orders := make([]HsbyBuyMyTradeDetail, 0)
|
|
|
|
|
+
|
|
|
|
|
+ // 当前成交单
|
|
|
|
|
+ curOrders := make([]HsbyBuyMyTradeDetail, 0)
|
|
|
|
|
+ if err := engine.Table("TRADE_TRADEDETAIL").
|
|
|
|
|
+ Select(`to_char(TRADE_TRADEDETAIL.TRADEID) ORDERID,
|
|
|
|
|
+ TRADE_TRADEDETAIL.MARKETID, TRADE_TRADEDETAIL.GOODSID, TRADE_TRADEDETAIL.ACCOUNTID, TRADE_TRADEDETAIL.BUYORSELL,
|
|
|
|
|
+ TRADE_TRADEDETAIL.TRADEPRICE PRICE, TRADE_TRADEDETAIL.TRADEQTY QTY, TRADE_TRADEDETAIL.TRADETIME TIME, TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT,
|
|
|
|
|
+ GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
|
|
|
|
|
+ HSBY_GOODSEX.PICURLS,
|
|
|
|
|
+ MARKET.TRADEMODE,
|
|
|
|
|
+ ENUMDICITEM.PARAM2 CURRENCYSIGN,
|
|
|
|
|
+ HSBY_SUPPLIERINFO.VENDORNAME`).
|
|
|
|
|
+ Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_TRADEDETAIL.GOODSID").
|
|
|
|
|
+ Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
|
|
|
|
|
+ Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
|
|
|
|
|
+ Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_TRADEDETAIL.MARKETID").
|
|
|
|
|
+ Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
|
|
|
|
|
+ Where(fmt.Sprintf(`TRADE_TRADEDETAIL.BUYORSELL = 0
|
|
|
|
|
+ and TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
|
|
|
|
|
+ And(fmt.Sprintf("TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&curOrders); err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(curOrders) > 0 {
|
|
|
|
|
+ orders = append(orders, curOrders...)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 历史成交单
|
|
|
|
|
+ hisOrders := make([]HsbyBuyMyTradeDetail, 0)
|
|
|
|
|
+ if err := engine.Table("HIS_TRADE_TRADEDETAIL").
|
|
|
|
|
+ Select(`to_char(HIS_TRADE_TRADEDETAIL.TRADEID) ORDERID,
|
|
|
|
|
+ HIS_TRADE_TRADEDETAIL.MARKETID, HIS_TRADE_TRADEDETAIL.GOODSID, HIS_TRADE_TRADEDETAIL.ACCOUNTID, HIS_TRADE_TRADEDETAIL.BUYORSELL,
|
|
|
|
|
+ HIS_TRADE_TRADEDETAIL.TRADEPRICE PRICE, HIS_TRADE_TRADEDETAIL.TRADEQTY QTY, HIS_TRADE_TRADEDETAIL.TRADETIME TIME, HIS_TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT,
|
|
|
|
|
+ GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
|
|
|
|
|
+ HSBY_GOODSEX.PICURLS,
|
|
|
|
|
+ MARKET.TRADEMODE,
|
|
|
|
|
+ ENUMDICITEM.PARAM2 CURRENCYSIGN,
|
|
|
|
|
+ HSBY_SUPPLIERINFO.VENDORNAME`).
|
|
|
|
|
+ Join("LEFT", "GOODS", "GOODS.GOODSID = HIS_TRADE_TRADEDETAIL.GOODSID").
|
|
|
|
|
+ Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
|
|
|
|
|
+ Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
|
|
|
|
|
+ Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TRADE_TRADEDETAIL.MARKETID").
|
|
|
|
|
+ Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
|
|
|
|
|
+ Where(fmt.Sprintf(`HIS_TRADE_TRADEDETAIL.BUYORSELL = 0 and HIS_TRADE_TRADEDETAIL.ISVALIDDATA = 1
|
|
|
|
|
+ and HIS_TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
|
|
|
|
|
+ And(fmt.Sprintf("HIS_TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&hisOrders); err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(hisOrders) > 0 {
|
|
|
|
|
+ orders = append(orders, hisOrders...)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return orders, nil
|
|
|
|
|
+}
|