package models import ( "mtp2_if/db" "mtp2_if/utils" "strconv" "time" ) // Reckondaytaaccount 资金账户日照表 type ReportReckondaytaaccount struct { ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 资金账户ID RECKONDATE string `json:"reckondate" xorm:"RECKONDATE" form:"reckondate" binding:"required"` // 日照日期(yyyyMMdd) USERID int64 `json:"userid" xorm:"USERID"` // 用户ID CURRENCYID int64 `json:"currencyid" xorm:"CURRENCYID"` // 货币ID CHANGEFLAG int32 `json:"changeflag" xorm:"CHANGEFLAG"` // 变动标志(当前账户资金有任何变动更新为1系统结算时更新0;供清算时使用) 0:无变动 1:有变动 PASSWORD string `json:"password" xorm:"PASSWORD"` // 资金密码 TRADESTATUS int32 `json:"tradestatus" xorm:"TRADESTATUS"` // 交易状态 - 1:正常 2:受限 3:冻结 4:禁止建仓(人工受限) 5:禁止交易(人工冻结) SIGNSTATUS int32 `json:"signstatus" xorm:"SIGNSTATUS"` // 签约状态 - 1:未签约 2:已签约 3:已解约 ISMAIN int32 `json:"ismain" xorm:"ISMAIN"` // 是否账号 0:不是母账户 1:是母账户 PARENTACCOUNTID int64 `json:"parentaccountid" xorm:"PARENTACCOUNTID"` // 所属根账户 RELATEUSERID int64 `json:"relateuserid" xorm:"RELATEUSERID"` // 关联用户 RELATEDACCOUNTSTATUS int32 `json:"relatedaccountstatus" xorm:"RELATEDACCOUNTSTATUS"` // 关联用户交易状态 - 1:正常(可交易) 2:受限(可平仓,不可建仓) 3:冻结(不可交易) TAACCOUNTTYPE int32 `json:"taaccounttype" xorm:"TAACCOUNTTYPE"` // 外部/内部账号 - 1:外部账号 2:内部账号 ISRECKONACCOUNT int32 `json:"isreckonaccount" xorm:"ISRECKONACCOUNT"` // 是否机构分润账号 0:不是 1:是 ISMARKETACCOUNT int32 `json:"ismarketaccount" xorm:"ISMARKETACCOUNT"` // 是否机构接单账号 0:不是 1:是 BALANCE float64 `json:"balance" xorm:"BALANCE"` // 期初余额 ORIFREEZEMARGIN float64 `json:"orifreezemargin" xorm:"ORIFREEZEMARGIN"` // 期初冻结保证金 ORIUSEDMARGIN float64 `json:"oriusedmargin" xorm:"ORIUSEDMARGIN"` // 期初占用保证金 ORIOTHERFREEZEMARGIN float64 `json:"oriotherfreezemargin" xorm:"ORIOTHERFREEZEMARGIN"` // 期初其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入) ORIFREEZECHARGE float64 `json:"orifreezecharge" xorm:"ORIFREEZECHARGE"` // 期初手续费冻结 ORIMORTGAGECREDIT float64 `json:"orimortgagecredit" xorm:"ORIMORTGAGECREDIT"` // 期初授信金额 ORIOTHERCREDIT float64 `json:"oriothercredit" xorm:"ORIOTHERCREDIT"` // 期初其它授信金额 ORIOUTAMOUNTFREEZE float64 `json:"orioutamountfreeze" xorm:"ORIOUTAMOUNTFREEZE"` // 期初出金冻结 CURRENTBALANCE float64 `json:"currentbalance" xorm:"CURRENTBALANCE"` // 期末余额 FREEZEMARGIN float64 `json:"freezemargin" xorm:"FREEZEMARGIN"` // 冻结保证金 USEDMARGIN float64 `json:"usedmargin" xorm:"USEDMARGIN"` // 占用保证金 OTHERFREEZEMARGIN float64 `json:"otherfreezemargin" xorm:"OTHERFREEZEMARGIN"` // 其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入) FREEZECHARGE float64 `json:"freezecharge" xorm:"FREEZECHARGE"` // 手续费冻结 MORTGAGECREDIT float64 `json:"mortgagecredit" xorm:"MORTGAGECREDIT"` // 授信金额 OTHERCREDIT float64 `json:"othercredit" xorm:"OTHERCREDIT"` // 其它授信金额 OUTAMOUNTFREEZE float64 `json:"outamountfreeze" xorm:"OUTAMOUNTFREEZE"` // 出金冻结 INAMOUNT float64 `json:"inamount" xorm:"INAMOUNT"` // 今日入金金额 OUTAMOUNT float64 `json:"outamount" xorm:"OUTAMOUNT"` // 今日出金金额 PAYCHARGE float64 `json:"paycharge" xorm:"PAYCHARGE"` // 今日手续费支出 CLOSEPL float64 `json:"closepl" xorm:"CLOSEPL"` // 今日平仓盈亏 RECKONPL float64 `json:"reckonpl" xorm:"RECKONPL"` // 今日结算盈亏 CREDITINCREASE float64 `json:"creditincrease" xorm:"CREDITINCREASE"` // 今日授信增加 CREDITDECREASE float64 `json:"creditdecrease" xorm:"CREDITDECREASE"` // 今日授信减少 OTHERCREDITINCREASE float64 `json:"othercreditincrease" xorm:"OTHERCREDITINCREASE"` // 今日其它授信增加 OTHERCREDITDECREASE float64 `json:"othercreditdecrease" xorm:"OTHERCREDITDECREASE"` // 今日其它授信减少 OTHERPAY float64 `json:"otherpay" xorm:"OTHERPAY"` // 其他支出(交割付款 申购付款 全款买入 商城买入 卖家退货) OTHERINCOME float64 `json:"otherincome" xorm:"OTHERINCOME"` // 其他收入(交割收款 申购收款 全款卖出 商城卖出 买家退货 会员手续费收入) TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 今日划转金额(母子账号资金划转,从账号划入为正,从账号划出为负) OUTTHRESHOLD float64 `json:"outthreshold" xorm:"OUTTHRESHOLD"` // 出金阈值 CLEARBALANCE float64 `json:"clearbalance" xorm:"CLEARBALANCE"` // 清算余额 = 期末余额 - 授信金额 - 其它授信金额 DIVIDEDCHARGE float64 `json:"dividedcharge" xorm:"DIVIDEDCHARGE"` // 今日已收手续费分成 PAYEXCHCHARGE float64 `json:"payexchcharge" xorm:"PAYEXCHCHARGE"` // 今日应付交易所手续费 CLEARPL float64 `json:"clearpl" xorm:"CLEARPL"` // 真实资金变动值(除出入金、应付交易所手续费)清算盈亏 = 期末余额 - 期初余额 - (今日入金 + 今日出金) - 今日应付交易所手续费 - 【(今日授信增加 + 今日授信减少) - (今日其它授信增加 + 今日其它授信减少) ----母账户】 = 今日手续费支出 + 今日平仓盈亏 + 今日结算盈亏 + 其他支出 + 其他收入 + 今日划转金额 + 今日已收手续费分成 - 今日应付交易所手续费 THIRDINAMOUNT float64 `json:"thirdinamount" xorm:"THIRDINAMOUNT"` // 今日三方入金 TRADECHARGE float64 `json:"tradecharge" xorm:"TRADECHARGE"` // 今日交易手续费支出 [101,102] INTERESTCHARGE float64 `json:"interestcharge" xorm:"INTERESTCHARGE"` // 今日递延费支出[103, 104] DELIVERYCHARGE float64 `json:"deliverycharge" xorm:"DELIVERYCHARGE"` // 今日交收手续费支出 [105,106] HOLDCHARGE float64 `json:"holdcharge" xorm:"HOLDCHARGE"` // 今日持仓过夜费支出[108,109,110] THIRDOUTAMOUNT float64 `json:"thirdoutamount" xorm:"THIRDOUTAMOUNT"` // 今日三方出金 TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 今日成交量 TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 今日成交金额 DELIVERYAMOUNTOUT float64 `json:"deliveryamountout" xorm:"DELIVERYAMOUNTOUT"` // 今日交收货款支出 DELIVERYAMOUNTIN float64 `json:"deliveryamountin" xorm:"DELIVERYAMOUNTIN"` // 今日交收货款收入 DELIVERYCOMPENSATIONFEEOUT float64 `json:"deliverycompensationfeeout" xorm:"DELIVERYCOMPENSATIONFEEOUT"` // 今日交收补偿费支出 DELIVERYCOMPENSATIONFEEIN float64 `json:"deliverycompensationfeein" xorm:"DELIVERYCOMPENSATIONFEEIN"` // 今日交收补偿费收入 CAPITALBALANCE float64 `json:"capitalbalance" xorm:"CAPITALBALANCE"` // 本金余额[外部子账户实际出入金余额] CLOSEPL2 float64 `json:"closepl2" xorm:"CLOSEPL2"` // 平仓盈亏(逐笔) RECKONPL2 float64 `json:"reckonpl2" xorm:"RECKONPL2"` // 结算盈亏(逐笔) - 汇总取期末 NETVALUE float64 `json:"netvalue" xorm:"NETVALUE"` // 净值 = 期末余额 + 所有权市值 + 仓单市值仓单市值由统计服务更新 PAYCHARGE2 float64 `json:"paycharge2" xorm:"PAYCHARGE2"` // 今日手续费支出(外部配置) DEFERCHARGE float64 `json:"defercharge" xorm:"DEFERCHARGE"` // 今日递延费2支出[111, 112] FROMACCOUNTID int64 `json:"fromaccountid" xorm:"FROMACCOUNTID"` // 所属上级账户 SUBLEVELPATH string `json:"sublevelpath" xorm:"SUBLEVELPATH"` // 账号层级路径(逗号分隔,首尾加逗号) OWNERSHIPVALUE float64 `json:"ownershipvalue" xorm:"OWNERSHIPVALUE"` // 所有权市值 SPOTVALUE float64 `json:"spotvalue" xorm:"SPOTVALUE"` // 现货市值-统计服务更新 ACCOUNTPL float64 `json:"accountpl" xorm:"ACCOUNTPL"` // 今日账户盈亏 = 今日净值-昨日净值+今日出金-今日入金-今日划转+今日授信减少-今日授信增加+今日其它授信减少-今日其它授信增加+今日三方出金-今日三方入金;由统计服务更新 ACCOUNTNAME string `json:"accountname" xorm:"ACCOUNTNAME"` // 账户名称 ORIDEBT float64 `json:"oridebt" xorm:"ORIDEBT"` // 期初欠款 CURDEBT float64 `json:"curdebt" xorm:"CURDEBT"` // 期末欠款 AVAIABLEMONEY float64 `json:"avaiablemoney" xorm:"AVAIABLEMONEY"` // 可用资金 AVAIABLEOUTMONEY float64 `json:"avaiableoutmoney" xorm:"AVAIABLEOUTMONEY"` // 可出资金 FLOATPL float64 `json:"floatpl" xorm:"FLOATPL"` // 浮动盈亏 - 每日有负债类商品 FLOATNETVALUE float64 `json:"floatnetvalue" xorm:"FLOATNETVALUE"` // 浮动净值 = 净值 + 浮动盈亏 RISKRATE float64 `json:"riskrate" xorm:"RISKRATE"` // 风险率 = 占用/ 浮动净值 或 浮动净值/占用 } func (r *ReportReckondaytaaccount) calc() { } func (r *ReportReckondaytaaccount) buildSql() string { var sqlId utils.SQLVal = ` select t.accountid, t.reckondate, t.userid, t.currencyid, t.changeflag, t.password, t.tradestatus, t.signstatus, t.ismain, t.parentaccountid, t.relateuserid, t.relatedaccountstatus, t.taaccounttype, t.isreckonaccount, t.ismarketaccount, t.balance, t.orifreezemargin, t.oriusedmargin, t.oriotherfreezemargin, t.orifreezecharge, t.orimortgagecredit, t.oriothercredit, t.orioutamountfreeze, t.currentbalance, t.freezemargin, t.usedmargin, t.otherfreezemargin, t.freezecharge, t.mortgagecredit, t.othercredit, t.outamountfreeze, t.inamount, t.outamount, t.paycharge, t.closepl, t.reckonpl, t.creditincrease, t.creditdecrease, t.othercreditincrease, t.othercreditdecrease, t.otherpay, t.otherincome, t.transferamount, t.outthreshold, t.clearbalance, t.dividedcharge, t.payexchcharge, t.clearpl, t.thirdinamount, t.tradecharge, t.interestcharge, t.deliverycharge, t.holdcharge, t.thirdoutamount, t.tradeqty, t.tradeamount, t.deliveryamountout, t.deliveryamountin, t.deliverycompensationfeeout, t.deliverycompensationfeein, t.capitalbalance, t.closepl2, t.reckonpl2, t.netvalue, t.paycharge2, t.defercharge, t.fromaccountid, t.sublevelpath, t.ownershipvalue, t.spotvalue, t.accountpl, t.accountname, t.oridebt, t.curdebt, t.avaiablemoney, t.avaiableoutmoney, t.floatpl, t.floatnetvalue, t.riskrate from reckon_daytaaccount t where t.reckondate = %v and t.accountid = %v ` sqlId.FormatParam(r.RECKONDATE, r.ACCOUNTID) return sqlId.String() } // GetDataEx 从数据库中查询数据 func (r *ReportReckondaytaaccount) GetDataEx() (interface{}, error) { e := db.GetEngine() s := e.SQL(r.buildSql()) sData := make([]ReportReckondaytaaccount, 0) if err := s.Find(&sData); err != nil { return nil, err } for i := range sData { sData[i].calc() } return sData, nil } type ReportBankAccountOutInLog struct { UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间 Executetypedisplay string `json:"executetypedisplay" xorm:"EXECUTETYPEDISPLAY"` // 申请类型 AMOUNT float64 `json:"amount" xorm:"AMOUNT"` // 金额 Applystatusdisplay string `json:"applystatusdisplay" xorm:"APPLYSTATUSDISPLAY"` // 申请状态 AccountId int64 `form:"accountid" binding:"required"` // 资金账户 Tradedate string `form:"tradedate" binding:"required"` // 查询日期 日报表-yyyyMMdd 月报表-yyyyMM ReportType int `form:"reporttype" binding:"required"` // 报表类型 日报表-1 月报表-2 PageEx `xorm:"extends"` // 页码信息 } func (r *ReportBankAccountOutInLog) calc() { } func (r *ReportBankAccountOutInLog) buildSql() string { var sqlId utils.SQLVal = ` select to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME, en1.enumdicname EXECUTETYPEDISPLAY, t.AMOUNT, en2.enumdicname APPLYSTATUSDISPLAY from Bank_AccountOutInApply t left join enumdicitem en1 on en1.enumdiccode = 'executetype' and en1.enumitemname = t.executetype left join enumdicitem en2 on en2.enumdiccode = 'applystatus' and en2.enumitemname = t.applystatus where 1=1 ` sqlId.And("t.accountcode", strconv.Itoa(int(r.AccountId))) if r.ReportType == 1 { // 日报表 sqlId.And("t.tradedate", r.Tradedate) } else { // 月报表 sqlId.And("substr(t.tradedate, 0,6)", r.Tradedate) } sqlId.OrderByDesc("t.updatetime") sqlId.Page(r.Page, r.PageSize) return sqlId.String() } func (r *ReportBankAccountOutInLog) GetDataByPage() (interface{}, error, int, int, int) { sData := make([]ReportBankAccountOutInLog, 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 ReportReckonDayPosition struct { CURPOSITIONQTY int64 `json:"curpositionqty" xorm:"CURPOSITIONQTY"` // 当前持仓总数量 FROZENQTY int64 `json:"frozenqty" xorm:"FROZENQTY"` // 持仓冻结 CURHOLDERAMOUNT float64 `json:"curholderamount" xorm:"CURHOLDERAMOUNT"` // 当前持仓总金额 GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品Id ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 账号Id RECKONDATE string `json:"reckondate" xorm:"RECKONDATE" form:"reckondate" binding:"required"` // 日照日期(yyyyMMdd) GOODSDISPLAY string `json:"goodsdisplay" xorm:"GOODSDISPLAY"` // 商品名称 DECIMALPLACE int32 `json:"decimalplace" xorm:"DECIMALPLACE"` // 报价小数位 BUYORSELLDISPLAY string `json:"buyorselldisplay" xorm:"BUYORSELLDISPLAY"` // 方向 AVAGEPRICEDISPLAY string `json:"avagepricedisplay" xorm:"AVAGEPRICEDISPLAY"` // 均价 ReportType int `form:"reporttype" binding:"required"` // 报表类型 日报表-1 月报表-2 PageEx `xorm:"extends"` // 页码信息 } func (r *ReportReckonDayPosition) calc() { } func (r *ReportReckonDayPosition) buildSql() string { var sqlId utils.SQLVal = ` select p.*, en1.enumdicname buyorselldisplay, round(p.curholderamount / p.curpositionqty, g.decimalplace) avagepricedisplay from (select 0 buyorsell, t.buycurpositionqty curpositionqty, t.buyfrozenqty frozenqty, t.buycurholderamount curholderamount, t.goodsid, t.accountid, t.reckondate, g.goodscode || '/' || g.goodsname goodsdisplay, g.decimalplace from reckon_dayposition t left join goods g on g.goodsid = t.goodsid left join market m on m.marketid = g.marketid where t.buycurpositionqty > 0 and m.trademode not in (40, 41, 48, 51) and t.accountid = %v and t.reckondate = '%v' union select 1 buyorsell, t.sellcurpositionqty curpositionqty, t.sellfrozenqty frozenqty, t.sellcurholderamount sellholderamount, t.goodsid, t.accountid, t.reckondate, g.goodscode || '/' || g.goodsname goodsdisplay, g.decimalplace from reckon_dayposition t left join goods g on g.goodsid = t.goodsid left join market m on m.marketid = g.marketid where t.sellcurpositionqty > 0 and m.trademode not in (40, 41, 48, 51) and t.accountid = %v and t.reckondate = '%v' ) p left join goods g on g.goodsid = p.goodsid left join market m on m.marketid = g.marketid left join enumdicitem en1 on en1.enumdiccode = 'buyOrSell' and en1.enumitemname = p.buyorsell order by g.goodscode, p.buyorsell ` sqlId.FormatParam(r.ACCOUNTID, r.RECKONDATE, r.ACCOUNTID, r.RECKONDATE) sqlId.Page(r.Page, r.PageSize) return sqlId.String() } func (r *ReportReckonDayPosition) buildSql_m() string { var sqlId utils.SQLVal = ` select p.*, en1.enumdicname buyorselldisplay, round(p.curholderamount / p.curpositionqty, g.decimalplace) avagepricedisplay from (select 0 buyorsell, t.buycurpositionqty curpositionqty, t.buyfrozenqty frozenqty, t.buycurholderamount curholderamount, t.goodsid, t.accountid, t.cycletype, t.cycletime, g.goodscode || '/' || g.goodsname goodsdisplay, g.decimalplace from report_tradeposition t left join goods g on g.goodsid = t.goodsid left join market m on m.marketid = g.marketid where t.buycurpositionqty > 0 and m.trademode not in (40, 41, 48, 51) and t.cycletype = 1 and t.cycletime = '%v' and t.accountid = %v union select 1 buyorsell, t.sellcurpositionqty curpositionqty, t.sellfrozenqty frozenqty, t.sellcurholderamount sellholderamount, t.goodsid, t.accountid, t.cycletype, t.cycletime, g.goodscode || '/' || g.goodsname goodsdisplay, g.decimalplace from report_tradeposition t left join goods g on g.goodsid = t.goodsid left join market m on m.marketid = g.marketid where t.sellcurpositionqty > 0 and m.trademode not in (40, 41, 48, 51) and t.cycletype = 1 and t.cycletime = '%v' and t.accountid = %v) p left join goods g on g.goodsid = p.goodsid left join market m on m.marketid = g.marketid left join enumdicitem en1 on en1.enumdiccode = 'buyOrSell' and en1.enumitemname = p.buyorsell order by g.goodscode, p.buyorsell ` sqlId.FormatParam(r.RECKONDATE, r.ACCOUNTID, r.RECKONDATE, r.ACCOUNTID) sqlId.Page(r.Page, r.PageSize) return sqlId.String() } func (r *ReportReckonDayPosition) GetDataByPage() (interface{}, error, int, int, int) { sData := make([]ReportReckonDayPosition, 0) sql := r.buildSql() if r.ReportType == 2 { sql = r.buildSql_m() } err := db.GetEngine().SQL(sql).Find(&sData) total := 0 for i := range sData { sData[i].calc() total = sData[i].Total } return sData, err, r.Page, r.PageSize, total } type ReportTradeDetail struct { TRADETIME string `json:"tradetime" xorm:"TRADETIME"` // 时间 GOODSDISPLAY string `json:"goodsdisplay" xorm:"GOODSDISPLAY"` // 商品 BUYORSELLDISPLAY string `json:"buyorselldisplay" xorm:"BUYORSELLDISPLAY"` // 类型/方向 TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 数量 TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 价格 TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 成交金额 CHARGE float64 `json:"charge" xorm:"CHARGE"` // 服务费 TRADEID string `json:"tradeid" xorm:"TRADEID"` // 成交单号 ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 资金账户 GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 期货合约ID(自增ID SEQ_GOODS) DECIMALPLACE int32 `json:"decimalplace" xorm:"DECIMALPLACE"` // 报价小数位 HISTRADEDATE string `json:"histradedate" xorm:"HISTRADEDATE" form:"histradedate" binding:"required"` // 查询日期 日报表-yyyyMMdd 月报表-yyyyMM ReportType int `form:"reporttype" binding:"required"` // 报表类型 日报表-1 月报表-2 PageEx `xorm:"extends"` // 页码信息 } func (r *ReportTradeDetail) calc() { } func (r *ReportTradeDetail) buildSql() string { var sqlId utils.SQLVal = ` select to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') TRADETIME, g.goodscode || '/' || g.goodsname goodsdisplay, en2.enumdicname || '/' || en1.enumdicname buyorselldisplay, t.tradeqty, t.tradeprice, t.tradeamount, t.opencharge + t.closecharge charge, t.tradeid, g.decimalplace, g.goodsid, t.accountid from his_trade_tradedetail t left join goods g on g.goodsid = t.goodsid left join enumdicitem en1 on en1.enumdiccode = 'buyOrSell' and en1.enumitemname = t.buyorsell left join enumdicitem en2 on en2.enumdiccode = 'buildtype' and en2.enumitemname = t.buildtype where t.isvaliddata = 1 ` sqlId.And("t.accountid", r.ACCOUNTID) if r.ReportType == 1 { // 日报表 sqlId.And("t.histradedate", r.HISTRADEDATE) } else { // 月报表 sqlId.And("substr(t.histradedate, 0,6)", r.HISTRADEDATE) } sqlId.OrderByDesc("t.tradetime") sqlId.Page(r.Page, r.PageSize) return sqlId.String() } func (r *ReportTradeDetail) GetDataByPage() (interface{}, error, int, int, int) { sData := make([]ReportTradeDetail, 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 } // Reporttaaccount 资金账户报表表 type Reporttaaccount struct { ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 资金账户ID CYCLETYPE int32 `json:"cycletype" xorm:"CYCLETYPE"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表 CYCLETIME string `json:"cycletime" xorm:"CYCLETIME" form:"cycletime" binding:"required"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0) UPDATETIME time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间 USERID int64 `json:"userid" xorm:"USERID"` // 用户ID ISMAIN int32 `json:"ismain" xorm:"ISMAIN"` // 是否母账号 0:不是母账户 1:是母账户 PARENTACCOUNTID int64 `json:"parentaccountid" xorm:"PARENTACCOUNTID"` // 所属根账户 TAACCOUNTTYPE int32 `json:"taaccounttype" xorm:"TAACCOUNTTYPE"` // 外部/内部账号 - 1:外部账号 2:内部账号 CURRENCYID int64 `json:"currencyid" xorm:"CURRENCYID"` // 货币ID BALANCE float64 `json:"balance" xorm:"BALANCE"` // 期初余额 ORIFREEZEMARGIN float64 `json:"orifreezemargin" xorm:"ORIFREEZEMARGIN"` // 期初冻结保证金 ORIUSEDMARGIN float64 `json:"oriusedmargin" xorm:"ORIUSEDMARGIN"` // 期初占用保证金 ORIOTHERFREEZEMARGIN float64 `json:"oriotherfreezemargin" xorm:"ORIOTHERFREEZEMARGIN"` // 期初其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入) ORIFREEZECHARGE float64 `json:"orifreezecharge" xorm:"ORIFREEZECHARGE"` // 期初手续费冻结 ORIMORTGAGECREDIT float64 `json:"orimortgagecredit" xorm:"ORIMORTGAGECREDIT"` // 期初授信金额 ORIOTHERCREDIT float64 `json:"oriothercredit" xorm:"ORIOTHERCREDIT"` // 期初其它授信金额 ORIOUTAMOUNTFREEZE float64 `json:"orioutamountfreeze" xorm:"ORIOUTAMOUNTFREEZE"` // 期初出金冻结 CURRENTBALANCE float64 `json:"currentbalance" xorm:"CURRENTBALANCE"` // 期末余额 FREEZEMARGIN float64 `json:"freezemargin" xorm:"FREEZEMARGIN"` // 冻结保证金 USEDMARGIN float64 `json:"usedmargin" xorm:"USEDMARGIN"` // 占用保证金 OTHERFREEZEMARGIN float64 `json:"otherfreezemargin" xorm:"OTHERFREEZEMARGIN"` // 其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入) FREEZECHARGE float64 `json:"freezecharge" xorm:"FREEZECHARGE"` // 手续费冻结 MORTGAGECREDIT float64 `json:"mortgagecredit" xorm:"MORTGAGECREDIT"` // 授信金额 OTHERCREDIT float64 `json:"othercredit" xorm:"OTHERCREDIT"` // 其它授信金额 OUTAMOUNTFREEZE float64 `json:"outamountfreeze" xorm:"OUTAMOUNTFREEZE"` // 出金冻结 INAMOUNT float64 `json:"inamount" xorm:"INAMOUNT"` // 本周期入金金额 OUTAMOUNT float64 `json:"outamount" xorm:"OUTAMOUNT"` // 本周期出金金额 PAYCHARGE float64 `json:"paycharge" xorm:"PAYCHARGE"` // 本周期手续费支出 CLOSEPL float64 `json:"closepl" xorm:"CLOSEPL"` // 本周期平仓盈亏 RECKONPL float64 `json:"reckonpl" xorm:"RECKONPL"` // 本周期结算盈亏 CREDITINCREASE float64 `json:"creditincrease" xorm:"CREDITINCREASE"` // 本周期授信增加 CREDITDECREASE float64 `json:"creditdecrease" xorm:"CREDITDECREASE"` // 本周期授信减少 OTHERCREDITINCREASE float64 `json:"othercreditincrease" xorm:"OTHERCREDITINCREASE"` // 本周期其它授信增加 OTHERCREDITDECREASE float64 `json:"othercreditdecrease" xorm:"OTHERCREDITDECREASE"` // 本周期其它授信减少 OTHERPAY float64 `json:"otherpay" xorm:"OTHERPAY"` // 其他支出(交割付款 申购付款 全款买入 商城买入 卖家退货) OTHERINCOME float64 `json:"otherincome" xorm:"OTHERINCOME"` // 其他收入(交割收款 申购收款 全款卖出 商城卖出 买家退货 会员手续费收入) TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 本周期划转金额(母子账号资金划转,从账号划入为正,从账号划出为负) OUTTHRESHOLD float64 `json:"outthreshold" xorm:"OUTTHRESHOLD"` // 出金阈值 CLEARBALANCE float64 `json:"clearbalance" xorm:"CLEARBALANCE"` // 清算余额 = 期末余额 - 授信金额 - 其它授信金额 DIVIDEDCHARGE float64 `json:"dividedcharge" xorm:"DIVIDEDCHARGE"` // 本周期已收手续费分成 PAYEXCHCHARGE float64 `json:"payexchcharge" xorm:"PAYEXCHCHARGE"` // 本周期应付交易所手续费 CLEARPL float64 `json:"clearpl" xorm:"CLEARPL"` // 清算盈亏 THIRDINAMOUNT float64 `json:"thirdinamount" xorm:"THIRDINAMOUNT"` // 本周期三方入金 TRADECHARGE float64 `json:"tradecharge" xorm:"TRADECHARGE"` // 本周期交易手续费支出 [101,102] INTERESTCHARGE float64 `json:"interestcharge" xorm:"INTERESTCHARGE"` // 本周期递延费支出[103, 104] DELIVERYCHARGE float64 `json:"deliverycharge" xorm:"DELIVERYCHARGE"` // 本周期交收手续费支出 [105,106] HOLDCHARGE float64 `json:"holdcharge" xorm:"HOLDCHARGE"` // 本周期持仓过夜费支出[108,109, 110] THIRDOUTAMOUNT float64 `json:"thirdoutamount" xorm:"THIRDOUTAMOUNT"` // 本周期三方出金 TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 本周期成交量 TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 本周期成交金额 DELIVERYAMOUNTOUT float64 `json:"deliveryamountout" xorm:"DELIVERYAMOUNTOUT"` // 本周期交收货款支出 DELIVERYAMOUNTIN float64 `json:"deliveryamountin" xorm:"DELIVERYAMOUNTIN"` // 本周期交收货款收入 DELIVERYCOMPENSATIONFEEOUT float64 `json:"deliverycompensationfeeout" xorm:"DELIVERYCOMPENSATIONFEEOUT"` // 本周期交收补偿费支出 DELIVERYCOMPENSATIONFEEIN float64 `json:"deliverycompensationfeein" xorm:"DELIVERYCOMPENSATIONFEEIN"` // 本周期交收补偿费收入 CAPITALBALANCE float64 `json:"capitalbalance" xorm:"CAPITALBALANCE"` // 本周期本金余额[外部子账户实际出入金余额] CLOSEPL2 float64 `json:"closepl2" xorm:"CLOSEPL2"` // 平仓盈亏(逐笔) RECKONPL2 float64 `json:"reckonpl2" xorm:"RECKONPL2"` // 结算盈亏(逐笔) - 汇总取期末 NETVALUE float64 `json:"netvalue" xorm:"NETVALUE"` // 净值 = 期末余额 + 所有权市值 PAYCHARGE2 float64 `json:"paycharge2" xorm:"PAYCHARGE2"` // 今日手续费支出(外部配置) DEFERCHARGE float64 `json:"defercharge" xorm:"DEFERCHARGE"` // 本周期递延费2支出[111, 112] FROMACCOUNTID int64 `json:"fromaccountid" xorm:"FROMACCOUNTID"` // 所属上级账户 SUBLEVELPATH string `json:"sublevelpath" xorm:"SUBLEVELPATH"` // 账号层级路径(逗号分隔,首尾加逗号) RELATEUSERID int64 `json:"relateuserid" xorm:"RELATEUSERID"` // 关联用户 OWNERSHIPVALUE float64 `json:"ownershipvalue" xorm:"OWNERSHIPVALUE"` // 所有权市值 SPOTVALUE float64 `json:"spotvalue" xorm:"SPOTVALUE"` // 现货市值-统计服务更新 ACCOUNTPL float64 `json:"accountpl" xorm:"ACCOUNTPL"` // 今日账户盈亏 = 今日净值-昨日净值+今日出金-今日入金-今日划转+今日授信减少-今日授信增加+今日其它授信减少-今日其它授信增加+今日三方出金-今日三方入金;由统计服务更新 ACCOUNTNAME string `json:"accountname" xorm:"ACCOUNTNAME"` // 账户名称 ORIDEBT float64 `json:"oridebt" xorm:"ORIDEBT"` // 期初欠款【期初】 CURDEBT float64 `json:"curdebt" xorm:"CURDEBT"` // 期末欠款【期末】 AVAIABLEMONEY float64 `json:"avaiablemoney" xorm:"AVAIABLEMONEY"` // 可用资金【期末】 AVAIABLEOUTMONEY float64 `json:"avaiableoutmoney" xorm:"AVAIABLEOUTMONEY"` // 可出资金【期末】 FLOATPL float64 `json:"floatpl" xorm:"FLOATPL"` // 浮动盈亏【期末】 FLOATNETVALUE float64 `json:"floatnetvalue" xorm:"FLOATNETVALUE"` // 浮动净值【期末】 RISKRATE float64 `json:"riskrate" xorm:"RISKRATE"` // 风险率【期末】 } func (r *Reporttaaccount) calc() { } func (r *Reporttaaccount) buildSql() string { var sqlId utils.SQLVal = ` select t.accountid, t.cycletype, t.cycletime, t.updatetime, t.userid, t.ismain, t.parentaccountid, t.taaccounttype, t.currencyid, t.balance, t.orifreezemargin, t.oriusedmargin, t.oriotherfreezemargin, t.orifreezecharge, t.orimortgagecredit, t.oriothercredit, t.orioutamountfreeze, t.currentbalance, t.freezemargin, t.usedmargin, t.otherfreezemargin, t.freezecharge, t.mortgagecredit, t.othercredit, t.outamountfreeze, t.inamount, t.outamount, t.paycharge, t.closepl, t.reckonpl, t.creditincrease, t.creditdecrease, t.othercreditincrease, t.othercreditdecrease, t.otherpay, t.otherincome, t.transferamount, t.outthreshold, t.clearbalance, t.dividedcharge, t.payexchcharge, t.clearpl, t.thirdinamount, t.tradecharge, t.interestcharge, t.deliverycharge, t.holdcharge, t.thirdoutamount, t.tradeqty, t.tradeamount, t.deliveryamountout, t.deliveryamountin, t.deliverycompensationfeeout, t.deliverycompensationfeein, t.capitalbalance, t.closepl2, t.reckonpl2, t.netvalue, t.paycharge2, t.defercharge, t.fromaccountid, t.sublevelpath, t.relateuserid, t.ownershipvalue, t.spotvalue, t.accountpl, t.accountname, t.oridebt, t.curdebt, t.avaiablemoney, t.avaiableoutmoney, t.floatpl, t.floatnetvalue, t.riskrate from report_taaccount t where t.cycletype = 1 and t.cycletime = '%v' and t.accountid = %v ` sqlId.FormatParam(r.CYCLETIME, r.ACCOUNTID) return sqlId.String() } // GetDataEx 从数据库中查询数据 func (r *Reporttaaccount) GetDataEx() (interface{}, error) { e := db.GetEngine() s := e.SQL(r.buildSql()) sData := make([]Reporttaaccount, 0) if err := s.Find(&sData); err != nil { return nil, err } for i := range sData { sData[i].calc() } return sData, nil }