|
|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
|
"mtp2_if/db"
|
|
|
"mtp2_if/logger"
|
|
|
+ "mtp2_if/mtpcache"
|
|
|
"mtp2_if/utils"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
@@ -1020,3 +1021,181 @@ func (r *THJGoodsDetailReq) GetTHJGoodsDetail() (rsp *THJGoodsDetailRsp, err err
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+type PurchaseTransfer struct {
|
|
|
+ WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME" form:"wrstandardname"` // 现货商品名称(模糊查询)
|
|
|
+ UNITID int32 `json:"unitid" xorm:"UNITID"` // 现货商品单位ID
|
|
|
+ THUMURLS string `json:"thumurls" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
|
|
|
+ PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
|
|
|
+ REFGOODSID int64 `json:"refgoodsid" xorm:"REFGOODSID"` // 参考商品ID
|
|
|
+
|
|
|
+ PageEx `xorm:"extends"` // 页码信息
|
|
|
+}
|
|
|
+
|
|
|
+func (r *PurchaseTransfer) calc() {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *PurchaseTransfer) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+ select
|
|
|
+ t.WRSTANDARDID ,
|
|
|
+ t.WRSTANDARDCODE,
|
|
|
+ t.WRSTANDARDNAME,
|
|
|
+ t.UNITID ,
|
|
|
+ t.THUMURLS ,
|
|
|
+ t.PICTUREURLS ,
|
|
|
+ t.REFGOODSID
|
|
|
+ from wrstandard wr
|
|
|
+ where wr.wrstandardid in (
|
|
|
+ select td.wrstandardid
|
|
|
+ from THJ_PurchaseTransfer t
|
|
|
+ inner join THJ_PurchaseTradeDetail td on t.wrtradedetailid = td.wrtradedetailid
|
|
|
+ where t.TransferStatus = 1)
|
|
|
+ and %v
|
|
|
+ order by wr.wrstandardname
|
|
|
+`
|
|
|
+ param := "1=1"
|
|
|
+ if r.WRSTANDARDNAME != "" {
|
|
|
+ param = fmt.Sprintf("wr.wrstandardname like '%%%v%%'", r.WRSTANDARDNAME)
|
|
|
+ }
|
|
|
+ sqlId.FormatParam(param)
|
|
|
+
|
|
|
+ sqlId.Page(r.Page, r.PageSize)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *PurchaseTransfer) GetDataByPage() (interface{}, error, int, int, int) {
|
|
|
+ sData := make([]PurchaseTransfer, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ total := 0
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ total = sData[i].Total
|
|
|
+ }
|
|
|
+ return sData, err, r.Page, r.PageSize, total
|
|
|
+}
|
|
|
+
|
|
|
+type THJPurchaseTradeDetail_Goodsinfo struct {
|
|
|
+ WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME" form:"wrstandardname"` // 现货商品名称(模糊查询)
|
|
|
+ UNITID int32 `json:"unitid" xorm:"UNITID"` // 现货商品单位ID
|
|
|
+ PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
|
|
|
+ REFGOODSID int64 `json:"refgoodsid" xorm:"REFGOODSID"` // 参考商品ID
|
|
|
+ REFGOODSCODE string `json:"refgoodscode" xorm:"REFGOODSCODE"` // 参考商品代码
|
|
|
+}
|
|
|
+
|
|
|
+type THJPurchaseTradeDetail_Date struct {
|
|
|
+ ENDDATE string `json:"enddate" xorm:"ENDDATE"` // 预售结束日期
|
|
|
+
|
|
|
+ DEPOSITRATE float64 `json:"depositrate" xorm:"DEPOSITRATE"` // 定金比例
|
|
|
+ TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 摘牌价格
|
|
|
+ TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 摘牌数量
|
|
|
+
|
|
|
+ TRANSFERID int64 `json:"transferid" xorm:"TRANSFERID"` // 协议转让ID(332+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ TRANSFERPRICE float64 `json:"transferprice" xorm:"TRANSFERPRICE"` // 转让价格
|
|
|
+ TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 转让金额
|
|
|
+}
|
|
|
+
|
|
|
+type HistoryData struct {
|
|
|
+ Opened float64 `json:"o"` // 开盘价
|
|
|
+ Highest float64 `json:"h"` // 最高价
|
|
|
+ Lowest float64 `json:"l"` // 最低价
|
|
|
+ Closed float64 `json:"c"` // 收盘价
|
|
|
+ TotleVolume int `json:"tv"` // 总量(成交量)
|
|
|
+ TotleTurnover float64 `json:"tt"` // 总金额
|
|
|
+ HoldVolume int `json:"hv"` // 持仓量
|
|
|
+ Settle float64 `json:"s"` // 结算价,日线周期(包括)以上才有
|
|
|
+ TimeStamp time.Time `json:"ts"` // 时间
|
|
|
+ IsFill bool `json:"f"` // 是否补充数据
|
|
|
+}
|
|
|
+
|
|
|
+type THJPurchaseTradeDetailReq struct {
|
|
|
+ WRSTANDARDID int64 `form:"wrstandardid" binding:"required"` // 现货商品ID
|
|
|
+}
|
|
|
+
|
|
|
+// THJPurchaseTradeDetailRsp 合同转让详情
|
|
|
+type THJPurchaseTradeDetailRsp struct {
|
|
|
+ GoodsInfo THJPurchaseTradeDetail_Goodsinfo `json:"goodsinfo"` // 商品信息
|
|
|
+ DeliveryDates []THJPurchaseTradeDetail_Date `json:"deliverydate"` // 交割日期
|
|
|
+ History []HistoryData `json:"history"` // 历史价格走势(历史数据日线)
|
|
|
+}
|
|
|
+
|
|
|
+// GetTHJWrstandardDetail 获取采购商品详情
|
|
|
+func (r *THJPurchaseTradeDetailReq) GetData() (rsp *THJPurchaseTradeDetailRsp, err error) {
|
|
|
+ engine := db.GetEngine()
|
|
|
+
|
|
|
+ rsp = new(THJPurchaseTradeDetailRsp)
|
|
|
+
|
|
|
+ // 采购商品信息
|
|
|
+ var goodsInfo THJPurchaseTradeDetail_Goodsinfo
|
|
|
+ sql := fmt.Sprintf(`
|
|
|
+ select
|
|
|
+ t.WRSTANDARDID ,
|
|
|
+ t.WRSTANDARDCODE,
|
|
|
+ t.WRSTANDARDNAME,
|
|
|
+ t.UNITID ,
|
|
|
+ t.PICTUREURLS ,
|
|
|
+ t.REFGOODSID ,
|
|
|
+ t.REFGOODSCODE
|
|
|
+ from wrstandard wr
|
|
|
+ where wr.wrstandardid = %v
|
|
|
+ `, r.WRSTANDARDID)
|
|
|
+ if _, err = engine.SQL(sql).Get(&goodsInfo); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.GoodsInfo = goodsInfo
|
|
|
+
|
|
|
+ // 交割日期
|
|
|
+ deliveryDates := make([]THJPurchaseTradeDetail_Date, 0)
|
|
|
+ sql = fmt.Sprintf(`
|
|
|
+ select
|
|
|
+ pi.ENDDATE,
|
|
|
+ td.DEPOSITRATE,
|
|
|
+ td.TRADEPRICE,
|
|
|
+ td.TRADEQTY,
|
|
|
+ t.TRANSFERPRICE,
|
|
|
+ t.TRANSFERAMOUNT,
|
|
|
+ wr.REFGOODSID,
|
|
|
+ t.TRANSFERID
|
|
|
+ from THJ_PurchaseTransfer t
|
|
|
+ inner join THJ_PurchaseTradeDetail td on t.wrtradedetailid = td.wrtradedetailid
|
|
|
+ inner join WR_PresaleInfo pi on t.presaleapplyid = pi.presaleapplyid
|
|
|
+ inner join wrstandard wr on wr.wrstandardid = td.wrstandardid
|
|
|
+ where td.wrstandardid = %v
|
|
|
+ `, r.WRSTANDARDID)
|
|
|
+ if err = engine.SQL(sql).Find(&deliveryDates); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.DeliveryDates = deliveryDates
|
|
|
+
|
|
|
+ // 历史价格走势
|
|
|
+ cycleDatas, err := GetHistoryCycleDatas(CycleTypeMinutesDay, goodsInfo.REFGOODSCODE, nil, nil, 50, false)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取目标商品报价小数位
|
|
|
+ dcplace := mtpcache.GetGoodsDecimalplace(goodsInfo.REFGOODSCODE)
|
|
|
+ // 计算最终价格
|
|
|
+ rst := make([]HistoryData, 0)
|
|
|
+ for _, v := range cycleDatas {
|
|
|
+ historyData := HistoryData{
|
|
|
+ Opened: utils.IntToFloat64(v.Open, dcplace),
|
|
|
+ Highest: utils.IntToFloat64(v.High, dcplace),
|
|
|
+ Lowest: utils.IntToFloat64(v.Low, dcplace),
|
|
|
+ Closed: utils.IntToFloat64(v.Close, dcplace),
|
|
|
+ TotleVolume: v.TV,
|
|
|
+ TotleTurnover: float64(v.TT),
|
|
|
+ HoldVolume: v.HV,
|
|
|
+ Settle: utils.IntToFloat64(v.SP, dcplace),
|
|
|
+ TimeStamp: time.Unix(int64(v.ST), 0),
|
|
|
+ }
|
|
|
+ rst = append(rst, historyData)
|
|
|
+ }
|
|
|
+ rsp.History = rst
|
|
|
+
|
|
|
+ return
|
|
|
+}
|