report.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. package models
  2. import (
  3. "mtp2_if/db"
  4. "mtp2_if/utils"
  5. "strconv"
  6. "time"
  7. )
  8. // Reckondaytaaccount 资金账户日照表
  9. type ReportReckondaytaaccount struct {
  10. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 资金账户ID
  11. RECKONDATE string `json:"reckondate" xorm:"RECKONDATE" form:"reckondate" binding:"required"` // 日照日期(yyyyMMdd)
  12. USERID int64 `json:"userid" xorm:"USERID"` // 用户ID
  13. CURRENCYID int64 `json:"currencyid" xorm:"CURRENCYID"` // 货币ID
  14. CHANGEFLAG int32 `json:"changeflag" xorm:"CHANGEFLAG"` // 变动标志(当前账户资金有任何变动更新为1系统结算时更新0;供清算时使用) 0:无变动 1:有变动
  15. PASSWORD string `json:"password" xorm:"PASSWORD"` // 资金密码
  16. TRADESTATUS int32 `json:"tradestatus" xorm:"TRADESTATUS"` // 交易状态 - 1:正常 2:受限 3:冻结 4:禁止建仓(人工受限) 5:禁止交易(人工冻结)
  17. SIGNSTATUS int32 `json:"signstatus" xorm:"SIGNSTATUS"` // 签约状态 - 1:未签约 2:已签约 3:已解约
  18. ISMAIN int32 `json:"ismain" xorm:"ISMAIN"` // 是否账号 0:不是母账户 1:是母账户
  19. PARENTACCOUNTID int64 `json:"parentaccountid" xorm:"PARENTACCOUNTID"` // 所属根账户
  20. RELATEUSERID int64 `json:"relateuserid" xorm:"RELATEUSERID"` // 关联用户
  21. RELATEDACCOUNTSTATUS int32 `json:"relatedaccountstatus" xorm:"RELATEDACCOUNTSTATUS"` // 关联用户交易状态 - 1:正常(可交易) 2:受限(可平仓,不可建仓) 3:冻结(不可交易)
  22. TAACCOUNTTYPE int32 `json:"taaccounttype" xorm:"TAACCOUNTTYPE"` // 外部/内部账号 - 1:外部账号 2:内部账号
  23. ISRECKONACCOUNT int32 `json:"isreckonaccount" xorm:"ISRECKONACCOUNT"` // 是否机构分润账号 0:不是 1:是
  24. ISMARKETACCOUNT int32 `json:"ismarketaccount" xorm:"ISMARKETACCOUNT"` // 是否机构接单账号 0:不是 1:是
  25. BALANCE float64 `json:"balance" xorm:"BALANCE"` // 期初余额
  26. ORIFREEZEMARGIN float64 `json:"orifreezemargin" xorm:"ORIFREEZEMARGIN"` // 期初冻结保证金
  27. ORIUSEDMARGIN float64 `json:"oriusedmargin" xorm:"ORIUSEDMARGIN"` // 期初占用保证金
  28. ORIOTHERFREEZEMARGIN float64 `json:"oriotherfreezemargin" xorm:"ORIOTHERFREEZEMARGIN"` // 期初其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入)
  29. ORIFREEZECHARGE float64 `json:"orifreezecharge" xorm:"ORIFREEZECHARGE"` // 期初手续费冻结
  30. ORIMORTGAGECREDIT float64 `json:"orimortgagecredit" xorm:"ORIMORTGAGECREDIT"` // 期初授信金额
  31. ORIOTHERCREDIT float64 `json:"oriothercredit" xorm:"ORIOTHERCREDIT"` // 期初其它授信金额
  32. ORIOUTAMOUNTFREEZE float64 `json:"orioutamountfreeze" xorm:"ORIOUTAMOUNTFREEZE"` // 期初出金冻结
  33. CURRENTBALANCE float64 `json:"currentbalance" xorm:"CURRENTBALANCE"` // 期末余额
  34. FREEZEMARGIN float64 `json:"freezemargin" xorm:"FREEZEMARGIN"` // 冻结保证金
  35. USEDMARGIN float64 `json:"usedmargin" xorm:"USEDMARGIN"` // 占用保证金
  36. OTHERFREEZEMARGIN float64 `json:"otherfreezemargin" xorm:"OTHERFREEZEMARGIN"` // 其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入)
  37. FREEZECHARGE float64 `json:"freezecharge" xorm:"FREEZECHARGE"` // 手续费冻结
  38. MORTGAGECREDIT float64 `json:"mortgagecredit" xorm:"MORTGAGECREDIT"` // 授信金额
  39. OTHERCREDIT float64 `json:"othercredit" xorm:"OTHERCREDIT"` // 其它授信金额
  40. OUTAMOUNTFREEZE float64 `json:"outamountfreeze" xorm:"OUTAMOUNTFREEZE"` // 出金冻结
  41. INAMOUNT float64 `json:"inamount" xorm:"INAMOUNT"` // 今日入金金额
  42. OUTAMOUNT float64 `json:"outamount" xorm:"OUTAMOUNT"` // 今日出金金额
  43. PAYCHARGE float64 `json:"paycharge" xorm:"PAYCHARGE"` // 今日手续费支出
  44. CLOSEPL float64 `json:"closepl" xorm:"CLOSEPL"` // 今日平仓盈亏
  45. RECKONPL float64 `json:"reckonpl" xorm:"RECKONPL"` // 今日结算盈亏
  46. CREDITINCREASE float64 `json:"creditincrease" xorm:"CREDITINCREASE"` // 今日授信增加
  47. CREDITDECREASE float64 `json:"creditdecrease" xorm:"CREDITDECREASE"` // 今日授信减少
  48. OTHERCREDITINCREASE float64 `json:"othercreditincrease" xorm:"OTHERCREDITINCREASE"` // 今日其它授信增加
  49. OTHERCREDITDECREASE float64 `json:"othercreditdecrease" xorm:"OTHERCREDITDECREASE"` // 今日其它授信减少
  50. OTHERPAY float64 `json:"otherpay" xorm:"OTHERPAY"` // 其他支出(交割付款 申购付款 全款买入 商城买入 卖家退货)
  51. OTHERINCOME float64 `json:"otherincome" xorm:"OTHERINCOME"` // 其他收入(交割收款 申购收款 全款卖出 商城卖出 买家退货 会员手续费收入)
  52. TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 今日划转金额(母子账号资金划转,从账号划入为正,从账号划出为负)
  53. OUTTHRESHOLD float64 `json:"outthreshold" xorm:"OUTTHRESHOLD"` // 出金阈值
  54. CLEARBALANCE float64 `json:"clearbalance" xorm:"CLEARBALANCE"` // 清算余额 = 期末余额 - 授信金额 - 其它授信金额
  55. DIVIDEDCHARGE float64 `json:"dividedcharge" xorm:"DIVIDEDCHARGE"` // 今日已收手续费分成
  56. PAYEXCHCHARGE float64 `json:"payexchcharge" xorm:"PAYEXCHCHARGE"` // 今日应付交易所手续费
  57. CLEARPL float64 `json:"clearpl" xorm:"CLEARPL"` // 真实资金变动值(除出入金、应付交易所手续费)清算盈亏 = 期末余额 - 期初余额 - (今日入金 + 今日出金) - 今日应付交易所手续费 - 【(今日授信增加 + 今日授信减少) - (今日其它授信增加 + 今日其它授信减少) ----母账户】 = 今日手续费支出 + 今日平仓盈亏 + 今日结算盈亏 + 其他支出 + 其他收入 + 今日划转金额 + 今日已收手续费分成 - 今日应付交易所手续费
  58. THIRDINAMOUNT float64 `json:"thirdinamount" xorm:"THIRDINAMOUNT"` // 今日三方入金
  59. TRADECHARGE float64 `json:"tradecharge" xorm:"TRADECHARGE"` // 今日交易手续费支出 [101,102]
  60. INTERESTCHARGE float64 `json:"interestcharge" xorm:"INTERESTCHARGE"` // 今日递延费支出[103, 104]
  61. DELIVERYCHARGE float64 `json:"deliverycharge" xorm:"DELIVERYCHARGE"` // 今日交收手续费支出 [105,106]
  62. HOLDCHARGE float64 `json:"holdcharge" xorm:"HOLDCHARGE"` // 今日持仓过夜费支出[108,109,110]
  63. THIRDOUTAMOUNT float64 `json:"thirdoutamount" xorm:"THIRDOUTAMOUNT"` // 今日三方出金
  64. TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 今日成交量
  65. TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 今日成交金额
  66. DELIVERYAMOUNTOUT float64 `json:"deliveryamountout" xorm:"DELIVERYAMOUNTOUT"` // 今日交收货款支出
  67. DELIVERYAMOUNTIN float64 `json:"deliveryamountin" xorm:"DELIVERYAMOUNTIN"` // 今日交收货款收入
  68. DELIVERYCOMPENSATIONFEEOUT float64 `json:"deliverycompensationfeeout" xorm:"DELIVERYCOMPENSATIONFEEOUT"` // 今日交收补偿费支出
  69. DELIVERYCOMPENSATIONFEEIN float64 `json:"deliverycompensationfeein" xorm:"DELIVERYCOMPENSATIONFEEIN"` // 今日交收补偿费收入
  70. CAPITALBALANCE float64 `json:"capitalbalance" xorm:"CAPITALBALANCE"` // 本金余额[外部子账户实际出入金余额]
  71. CLOSEPL2 float64 `json:"closepl2" xorm:"CLOSEPL2"` // 平仓盈亏(逐笔)
  72. RECKONPL2 float64 `json:"reckonpl2" xorm:"RECKONPL2"` // 结算盈亏(逐笔) - 汇总取期末
  73. NETVALUE float64 `json:"netvalue" xorm:"NETVALUE"` // 净值 = 期末余额 + 所有权市值 + 仓单市值仓单市值由统计服务更新
  74. PAYCHARGE2 float64 `json:"paycharge2" xorm:"PAYCHARGE2"` // 今日手续费支出(外部配置)
  75. DEFERCHARGE float64 `json:"defercharge" xorm:"DEFERCHARGE"` // 今日递延费2支出[111, 112]
  76. FROMACCOUNTID int64 `json:"fromaccountid" xorm:"FROMACCOUNTID"` // 所属上级账户
  77. SUBLEVELPATH string `json:"sublevelpath" xorm:"SUBLEVELPATH"` // 账号层级路径(逗号分隔,首尾加逗号)
  78. OWNERSHIPVALUE float64 `json:"ownershipvalue" xorm:"OWNERSHIPVALUE"` // 所有权市值
  79. SPOTVALUE float64 `json:"spotvalue" xorm:"SPOTVALUE"` // 现货市值-统计服务更新
  80. ACCOUNTPL float64 `json:"accountpl" xorm:"ACCOUNTPL"` // 今日账户盈亏 = 今日净值-昨日净值+今日出金-今日入金-今日划转+今日授信减少-今日授信增加+今日其它授信减少-今日其它授信增加+今日三方出金-今日三方入金;由统计服务更新
  81. ACCOUNTNAME string `json:"accountname" xorm:"ACCOUNTNAME"` // 账户名称
  82. ORIDEBT float64 `json:"oridebt" xorm:"ORIDEBT"` // 期初欠款
  83. CURDEBT float64 `json:"curdebt" xorm:"CURDEBT"` // 期末欠款
  84. AVAIABLEMONEY float64 `json:"avaiablemoney" xorm:"AVAIABLEMONEY"` // 可用资金
  85. AVAIABLEOUTMONEY float64 `json:"avaiableoutmoney" xorm:"AVAIABLEOUTMONEY"` // 可出资金
  86. FLOATPL float64 `json:"floatpl" xorm:"FLOATPL"` // 浮动盈亏 - 每日有负债类商品
  87. FLOATNETVALUE float64 `json:"floatnetvalue" xorm:"FLOATNETVALUE"` // 浮动净值 = 净值 + 浮动盈亏
  88. RISKRATE float64 `json:"riskrate" xorm:"RISKRATE"` // 风险率 = 占用/ 浮动净值 或 浮动净值/占用
  89. }
  90. func (r *ReportReckondaytaaccount) calc() {
  91. }
  92. func (r *ReportReckondaytaaccount) buildSql() string {
  93. var sqlId utils.SQLVal = `
  94. select
  95. t.accountid,
  96. t.reckondate,
  97. t.userid,
  98. t.currencyid,
  99. t.changeflag,
  100. t.password,
  101. t.tradestatus,
  102. t.signstatus,
  103. t.ismain,
  104. t.parentaccountid,
  105. t.relateuserid,
  106. t.relatedaccountstatus,
  107. t.taaccounttype,
  108. t.isreckonaccount,
  109. t.ismarketaccount,
  110. t.balance,
  111. t.orifreezemargin,
  112. t.oriusedmargin,
  113. t.oriotherfreezemargin,
  114. t.orifreezecharge,
  115. t.orimortgagecredit,
  116. t.oriothercredit,
  117. t.orioutamountfreeze,
  118. t.currentbalance,
  119. t.freezemargin,
  120. t.usedmargin,
  121. t.otherfreezemargin,
  122. t.freezecharge,
  123. t.mortgagecredit,
  124. t.othercredit,
  125. t.outamountfreeze,
  126. t.inamount,
  127. t.outamount,
  128. t.paycharge,
  129. t.closepl,
  130. t.reckonpl,
  131. t.creditincrease,
  132. t.creditdecrease,
  133. t.othercreditincrease,
  134. t.othercreditdecrease,
  135. t.otherpay,
  136. t.otherincome,
  137. t.transferamount,
  138. t.outthreshold,
  139. t.clearbalance,
  140. t.dividedcharge,
  141. t.payexchcharge,
  142. t.clearpl,
  143. t.thirdinamount,
  144. t.tradecharge,
  145. t.interestcharge,
  146. t.deliverycharge,
  147. t.holdcharge,
  148. t.thirdoutamount,
  149. t.tradeqty,
  150. t.tradeamount,
  151. t.deliveryamountout,
  152. t.deliveryamountin,
  153. t.deliverycompensationfeeout,
  154. t.deliverycompensationfeein,
  155. t.capitalbalance,
  156. t.closepl2,
  157. t.reckonpl2,
  158. t.netvalue,
  159. t.paycharge2,
  160. t.defercharge,
  161. t.fromaccountid,
  162. t.sublevelpath,
  163. t.ownershipvalue,
  164. t.spotvalue,
  165. t.accountpl,
  166. t.accountname,
  167. t.oridebt,
  168. t.curdebt,
  169. t.avaiablemoney,
  170. t.avaiableoutmoney,
  171. t.floatpl,
  172. t.floatnetvalue,
  173. t.riskrate
  174. from reckon_daytaaccount t
  175. where t.reckondate = %v and t.accountid = %v
  176. `
  177. sqlId.FormatParam(r.RECKONDATE, r.ACCOUNTID)
  178. return sqlId.String()
  179. }
  180. // GetDataEx 从数据库中查询数据
  181. func (r *ReportReckondaytaaccount) GetDataEx() (interface{}, error) {
  182. e := db.GetEngine()
  183. s := e.SQL(r.buildSql())
  184. sData := make([]ReportReckondaytaaccount, 0)
  185. if err := s.Find(&sData); err != nil {
  186. return nil, err
  187. }
  188. for i := range sData {
  189. sData[i].calc()
  190. }
  191. return sData, nil
  192. }
  193. type ReportBankAccountOutInLog struct {
  194. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  195. Executetypedisplay string `json:"executetypedisplay" xorm:"EXECUTETYPEDISPLAY"` // 申请类型
  196. AMOUNT float64 `json:"amount" xorm:"AMOUNT"` // 金额
  197. Applystatusdisplay string `json:"applystatusdisplay" xorm:"APPLYSTATUSDISPLAY"` // 申请状态
  198. AccountId int64 `form:"accountid" binding:"required"` // 资金账户
  199. Tradedate string `form:"tradedate" binding:"required"` // 查询日期 日报表-yyyyMMdd 月报表-yyyyMM
  200. ReportType int `form:"reporttype" binding:"required"` // 报表类型 日报表-1 月报表-2
  201. PageEx `xorm:"extends"` // 页码信息
  202. }
  203. func (r *ReportBankAccountOutInLog) calc() {
  204. }
  205. func (r *ReportBankAccountOutInLog) buildSql() string {
  206. var sqlId utils.SQLVal = `
  207. select
  208. to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME,
  209. en1.enumdicname EXECUTETYPEDISPLAY,
  210. t.AMOUNT,
  211. en2.enumdicname APPLYSTATUSDISPLAY
  212. from Bank_AccountOutInApply t
  213. left join enumdicitem en1
  214. on en1.enumdiccode = 'executetype'
  215. and en1.enumitemname = t.executetype
  216. left join enumdicitem en2
  217. on en2.enumdiccode = 'applystatus'
  218. and en2.enumitemname = t.applystatus
  219. where 1=1
  220. `
  221. sqlId.And("t.accountcode", strconv.Itoa(int(r.AccountId)))
  222. if r.ReportType == 1 {
  223. // 日报表
  224. sqlId.And("t.tradedate", r.Tradedate)
  225. } else {
  226. // 月报表
  227. sqlId.And("substr(t.tradedate, 0,6)", r.Tradedate)
  228. }
  229. sqlId.OrderByDesc("t.updatetime")
  230. sqlId.Page(r.Page, r.PageSize)
  231. return sqlId.String()
  232. }
  233. func (r *ReportBankAccountOutInLog) GetDataByPage() (interface{}, error, int, int, int) {
  234. sData := make([]ReportBankAccountOutInLog, 0)
  235. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  236. total := 0
  237. for i := range sData {
  238. sData[i].calc()
  239. total = sData[i].Total
  240. }
  241. return sData, err, r.Page, r.PageSize, total
  242. }
  243. type ReportReckonDayPosition struct {
  244. CURPOSITIONQTY int64 `json:"curpositionqty" xorm:"CURPOSITIONQTY"` // 当前持仓总数量
  245. FROZENQTY int64 `json:"frozenqty" xorm:"FROZENQTY"` // 持仓冻结
  246. CURHOLDERAMOUNT float64 `json:"curholderamount" xorm:"CURHOLDERAMOUNT"` // 当前持仓总金额
  247. GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品Id
  248. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 账号Id
  249. RECKONDATE string `json:"reckondate" xorm:"RECKONDATE" form:"reckondate" binding:"required"` // 日照日期(yyyyMMdd)
  250. GOODSDISPLAY string `json:"goodsdisplay" xorm:"GOODSDISPLAY"` // 商品名称
  251. DECIMALPLACE int32 `json:"decimalplace" xorm:"DECIMALPLACE"` // 报价小数位
  252. BUYORSELLDISPLAY string `json:"buyorselldisplay" xorm:"BUYORSELLDISPLAY"` // 方向
  253. AVAGEPRICEDISPLAY string `json:"avagepricedisplay" xorm:"AVAGEPRICEDISPLAY"` // 均价
  254. ReportType int `form:"reporttype" binding:"required"` // 报表类型 日报表-1 月报表-2
  255. PageEx `xorm:"extends"` // 页码信息
  256. }
  257. func (r *ReportReckonDayPosition) calc() {
  258. }
  259. func (r *ReportReckonDayPosition) buildSql() string {
  260. var sqlId utils.SQLVal = `
  261. select p.*,
  262. en1.enumdicname buyorselldisplay,
  263. round(p.curholderamount / p.curpositionqty, g.decimalplace) avagepricedisplay
  264. from (select 0 buyorsell,
  265. t.buycurpositionqty curpositionqty,
  266. t.buyfrozenqty frozenqty,
  267. t.buycurholderamount curholderamount,
  268. t.goodsid,
  269. t.accountid,
  270. t.reckondate,
  271. g.goodscode || '/' || g.goodsname goodsdisplay,
  272. g.decimalplace
  273. from reckon_dayposition t
  274. left join goods g
  275. on g.goodsid = t.goodsid
  276. left join market m
  277. on m.marketid = g.marketid
  278. where t.buycurpositionqty > 0
  279. and m.trademode not in (40, 41, 48, 51)
  280. and t.accountid = %v
  281. and t.reckondate = '%v'
  282. union
  283. select 1 buyorsell,
  284. t.sellcurpositionqty curpositionqty,
  285. t.sellfrozenqty frozenqty,
  286. t.sellcurholderamount sellholderamount,
  287. t.goodsid,
  288. t.accountid,
  289. t.reckondate,
  290. g.goodscode || '/' || g.goodsname goodsdisplay,
  291. g.decimalplace
  292. from reckon_dayposition t
  293. left join goods g
  294. on g.goodsid = t.goodsid
  295. left join market m
  296. on m.marketid = g.marketid
  297. where t.sellcurpositionqty > 0
  298. and m.trademode not in (40, 41, 48, 51)
  299. and t.accountid = %v
  300. and t.reckondate = '%v' ) p
  301. left join goods g
  302. on g.goodsid = p.goodsid
  303. left join market m
  304. on m.marketid = g.marketid
  305. left join enumdicitem en1
  306. on en1.enumdiccode = 'buyOrSell'
  307. and en1.enumitemname = p.buyorsell
  308. order by g.goodscode, p.buyorsell
  309. `
  310. sqlId.FormatParam(r.ACCOUNTID, r.RECKONDATE, r.ACCOUNTID, r.RECKONDATE)
  311. sqlId.Page(r.Page, r.PageSize)
  312. return sqlId.String()
  313. }
  314. func (r *ReportReckonDayPosition) buildSql_m() string {
  315. var sqlId utils.SQLVal = `
  316. select p.*,
  317. en1.enumdicname buyorselldisplay,
  318. round(p.curholderamount / p.curpositionqty, g.decimalplace) avagepricedisplay
  319. from (select 0 buyorsell,
  320. t.buycurpositionqty curpositionqty,
  321. t.buyfrozenqty frozenqty,
  322. t.buycurholderamount curholderamount,
  323. t.goodsid,
  324. t.accountid,
  325. t.cycletype,
  326. t.cycletime,
  327. g.goodscode || '/' || g.goodsname goodsdisplay,
  328. g.decimalplace
  329. from report_tradeposition t
  330. left join goods g
  331. on g.goodsid = t.goodsid
  332. left join market m
  333. on m.marketid = g.marketid
  334. where t.buycurpositionqty > 0
  335. and m.trademode not in (40, 41, 48, 51)
  336. and t.cycletype = 1
  337. and t.cycletime = '%v'
  338. and t.accountid = %v
  339. union
  340. select 1 buyorsell,
  341. t.sellcurpositionqty curpositionqty,
  342. t.sellfrozenqty frozenqty,
  343. t.sellcurholderamount sellholderamount,
  344. t.goodsid,
  345. t.accountid,
  346. t.cycletype,
  347. t.cycletime,
  348. g.goodscode || '/' || g.goodsname goodsdisplay,
  349. g.decimalplace
  350. from report_tradeposition t
  351. left join goods g
  352. on g.goodsid = t.goodsid
  353. left join market m
  354. on m.marketid = g.marketid
  355. where t.sellcurpositionqty > 0
  356. and m.trademode not in (40, 41, 48, 51)
  357. and t.cycletype = 1
  358. and t.cycletime = '%v'
  359. and t.accountid = %v) p
  360. left join goods g
  361. on g.goodsid = p.goodsid
  362. left join market m
  363. on m.marketid = g.marketid
  364. left join enumdicitem en1
  365. on en1.enumdiccode = 'buyOrSell'
  366. and en1.enumitemname = p.buyorsell
  367. order by g.goodscode, p.buyorsell
  368. `
  369. sqlId.FormatParam(r.RECKONDATE, r.ACCOUNTID, r.RECKONDATE, r.ACCOUNTID)
  370. sqlId.Page(r.Page, r.PageSize)
  371. return sqlId.String()
  372. }
  373. func (r *ReportReckonDayPosition) GetDataByPage() (interface{}, error, int, int, int) {
  374. sData := make([]ReportReckonDayPosition, 0)
  375. sql := r.buildSql()
  376. if r.ReportType == 2 {
  377. sql = r.buildSql_m()
  378. }
  379. err := db.GetEngine().SQL(sql).Find(&sData)
  380. total := 0
  381. for i := range sData {
  382. sData[i].calc()
  383. total = sData[i].Total
  384. }
  385. return sData, err, r.Page, r.PageSize, total
  386. }
  387. type ReportTradeDetail struct {
  388. TRADETIME string `json:"tradetime" xorm:"TRADETIME"` // 时间
  389. GOODSDISPLAY string `json:"goodsdisplay" xorm:"GOODSDISPLAY"` // 商品
  390. BUYORSELLDISPLAY string `json:"buyorselldisplay" xorm:"BUYORSELLDISPLAY"` // 类型/方向
  391. TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 数量
  392. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 价格
  393. TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 成交金额
  394. CHARGE float64 `json:"charge" xorm:"CHARGE"` // 服务费
  395. TRADEID string `json:"tradeid" xorm:"TRADEID"` // 成交单号
  396. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 资金账户
  397. GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 期货合约ID(自增ID SEQ_GOODS)
  398. DECIMALPLACE int32 `json:"decimalplace" xorm:"DECIMALPLACE"` // 报价小数位
  399. HISTRADEDATE string `json:"histradedate" xorm:"HISTRADEDATE" form:"histradedate" binding:"required"` // 查询日期 日报表-yyyyMMdd 月报表-yyyyMM
  400. ReportType int `form:"reporttype" binding:"required"` // 报表类型 日报表-1 月报表-2
  401. PageEx `xorm:"extends"` // 页码信息
  402. }
  403. func (r *ReportTradeDetail) calc() {
  404. }
  405. func (r *ReportTradeDetail) buildSql() string {
  406. var sqlId utils.SQLVal = `
  407. select
  408. to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') TRADETIME,
  409. g.goodscode || '/' || g.goodsname goodsdisplay,
  410. en2.enumdicname || '/' || en1.enumdicname buyorselldisplay,
  411. t.tradeqty,
  412. t.tradeprice,
  413. t.tradeamount,
  414. t.opencharge + t.closecharge charge,
  415. t.tradeid,
  416. g.decimalplace,
  417. g.goodsid,
  418. t.accountid
  419. from his_trade_tradedetail t
  420. left join goods g
  421. on g.goodsid = t.goodsid
  422. left join enumdicitem en1
  423. on en1.enumdiccode = 'buyOrSell'
  424. and en1.enumitemname = t.buyorsell
  425. left join enumdicitem en2
  426. on en2.enumdiccode = 'buildtype'
  427. and en2.enumitemname = t.buildtype
  428. where t.isvaliddata = 1
  429. `
  430. sqlId.And("t.accountid", r.ACCOUNTID)
  431. if r.ReportType == 1 {
  432. // 日报表
  433. sqlId.And("t.histradedate", r.HISTRADEDATE)
  434. } else {
  435. // 月报表
  436. sqlId.And("substr(t.histradedate, 0,6)", r.HISTRADEDATE)
  437. }
  438. sqlId.OrderByDesc("t.tradetime")
  439. sqlId.Page(r.Page, r.PageSize)
  440. return sqlId.String()
  441. }
  442. func (r *ReportTradeDetail) GetDataByPage() (interface{}, error, int, int, int) {
  443. sData := make([]ReportTradeDetail, 0)
  444. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  445. total := 0
  446. for i := range sData {
  447. sData[i].calc()
  448. total = sData[i].Total
  449. }
  450. return sData, err, r.Page, r.PageSize, total
  451. }
  452. // Reporttaaccount 资金账户报表表
  453. type Reporttaaccount struct {
  454. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid" binding:"required"` // 资金账户ID
  455. CYCLETYPE int32 `json:"cycletype" xorm:"CYCLETYPE"` // 周期类型 - 1:月 2:季 3:年 4:周 5:全报表
  456. CYCLETIME string `json:"cycletime" xorm:"CYCLETIME" form:"cycletime" binding:"required"` // 周期时间 月(YYYYMM) 季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)
  457. UPDATETIME time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  458. USERID int64 `json:"userid" xorm:"USERID"` // 用户ID
  459. ISMAIN int32 `json:"ismain" xorm:"ISMAIN"` // 是否母账号 0:不是母账户 1:是母账户
  460. PARENTACCOUNTID int64 `json:"parentaccountid" xorm:"PARENTACCOUNTID"` // 所属根账户
  461. TAACCOUNTTYPE int32 `json:"taaccounttype" xorm:"TAACCOUNTTYPE"` // 外部/内部账号 - 1:外部账号 2:内部账号
  462. CURRENCYID int64 `json:"currencyid" xorm:"CURRENCYID"` // 货币ID
  463. BALANCE float64 `json:"balance" xorm:"BALANCE"` // 期初余额
  464. ORIFREEZEMARGIN float64 `json:"orifreezemargin" xorm:"ORIFREEZEMARGIN"` // 期初冻结保证金
  465. ORIUSEDMARGIN float64 `json:"oriusedmargin" xorm:"ORIUSEDMARGIN"` // 期初占用保证金
  466. ORIOTHERFREEZEMARGIN float64 `json:"oriotherfreezemargin" xorm:"ORIOTHERFREEZEMARGIN"` // 期初其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入)
  467. ORIFREEZECHARGE float64 `json:"orifreezecharge" xorm:"ORIFREEZECHARGE"` // 期初手续费冻结
  468. ORIMORTGAGECREDIT float64 `json:"orimortgagecredit" xorm:"ORIMORTGAGECREDIT"` // 期初授信金额
  469. ORIOTHERCREDIT float64 `json:"oriothercredit" xorm:"ORIOTHERCREDIT"` // 期初其它授信金额
  470. ORIOUTAMOUNTFREEZE float64 `json:"orioutamountfreeze" xorm:"ORIOUTAMOUNTFREEZE"` // 期初出金冻结
  471. CURRENTBALANCE float64 `json:"currentbalance" xorm:"CURRENTBALANCE"` // 期末余额
  472. FREEZEMARGIN float64 `json:"freezemargin" xorm:"FREEZEMARGIN"` // 冻结保证金
  473. USEDMARGIN float64 `json:"usedmargin" xorm:"USEDMARGIN"` // 占用保证金
  474. OTHERFREEZEMARGIN float64 `json:"otherfreezemargin" xorm:"OTHERFREEZEMARGIN"` // 其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入)
  475. FREEZECHARGE float64 `json:"freezecharge" xorm:"FREEZECHARGE"` // 手续费冻结
  476. MORTGAGECREDIT float64 `json:"mortgagecredit" xorm:"MORTGAGECREDIT"` // 授信金额
  477. OTHERCREDIT float64 `json:"othercredit" xorm:"OTHERCREDIT"` // 其它授信金额
  478. OUTAMOUNTFREEZE float64 `json:"outamountfreeze" xorm:"OUTAMOUNTFREEZE"` // 出金冻结
  479. INAMOUNT float64 `json:"inamount" xorm:"INAMOUNT"` // 本周期入金金额
  480. OUTAMOUNT float64 `json:"outamount" xorm:"OUTAMOUNT"` // 本周期出金金额
  481. PAYCHARGE float64 `json:"paycharge" xorm:"PAYCHARGE"` // 本周期手续费支出
  482. CLOSEPL float64 `json:"closepl" xorm:"CLOSEPL"` // 本周期平仓盈亏
  483. RECKONPL float64 `json:"reckonpl" xorm:"RECKONPL"` // 本周期结算盈亏
  484. CREDITINCREASE float64 `json:"creditincrease" xorm:"CREDITINCREASE"` // 本周期授信增加
  485. CREDITDECREASE float64 `json:"creditdecrease" xorm:"CREDITDECREASE"` // 本周期授信减少
  486. OTHERCREDITINCREASE float64 `json:"othercreditincrease" xorm:"OTHERCREDITINCREASE"` // 本周期其它授信增加
  487. OTHERCREDITDECREASE float64 `json:"othercreditdecrease" xorm:"OTHERCREDITDECREASE"` // 本周期其它授信减少
  488. OTHERPAY float64 `json:"otherpay" xorm:"OTHERPAY"` // 其他支出(交割付款 申购付款 全款买入 商城买入 卖家退货)
  489. OTHERINCOME float64 `json:"otherincome" xorm:"OTHERINCOME"` // 其他收入(交割收款 申购收款 全款卖出 商城卖出 买家退货 会员手续费收入)
  490. TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 本周期划转金额(母子账号资金划转,从账号划入为正,从账号划出为负)
  491. OUTTHRESHOLD float64 `json:"outthreshold" xorm:"OUTTHRESHOLD"` // 出金阈值
  492. CLEARBALANCE float64 `json:"clearbalance" xorm:"CLEARBALANCE"` // 清算余额 = 期末余额 - 授信金额 - 其它授信金额
  493. DIVIDEDCHARGE float64 `json:"dividedcharge" xorm:"DIVIDEDCHARGE"` // 本周期已收手续费分成
  494. PAYEXCHCHARGE float64 `json:"payexchcharge" xorm:"PAYEXCHCHARGE"` // 本周期应付交易所手续费
  495. CLEARPL float64 `json:"clearpl" xorm:"CLEARPL"` // 清算盈亏
  496. THIRDINAMOUNT float64 `json:"thirdinamount" xorm:"THIRDINAMOUNT"` // 本周期三方入金
  497. TRADECHARGE float64 `json:"tradecharge" xorm:"TRADECHARGE"` // 本周期交易手续费支出 [101,102]
  498. INTERESTCHARGE float64 `json:"interestcharge" xorm:"INTERESTCHARGE"` // 本周期递延费支出[103, 104]
  499. DELIVERYCHARGE float64 `json:"deliverycharge" xorm:"DELIVERYCHARGE"` // 本周期交收手续费支出 [105,106]
  500. HOLDCHARGE float64 `json:"holdcharge" xorm:"HOLDCHARGE"` // 本周期持仓过夜费支出[108,109, 110]
  501. THIRDOUTAMOUNT float64 `json:"thirdoutamount" xorm:"THIRDOUTAMOUNT"` // 本周期三方出金
  502. TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 本周期成交量
  503. TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 本周期成交金额
  504. DELIVERYAMOUNTOUT float64 `json:"deliveryamountout" xorm:"DELIVERYAMOUNTOUT"` // 本周期交收货款支出
  505. DELIVERYAMOUNTIN float64 `json:"deliveryamountin" xorm:"DELIVERYAMOUNTIN"` // 本周期交收货款收入
  506. DELIVERYCOMPENSATIONFEEOUT float64 `json:"deliverycompensationfeeout" xorm:"DELIVERYCOMPENSATIONFEEOUT"` // 本周期交收补偿费支出
  507. DELIVERYCOMPENSATIONFEEIN float64 `json:"deliverycompensationfeein" xorm:"DELIVERYCOMPENSATIONFEEIN"` // 本周期交收补偿费收入
  508. CAPITALBALANCE float64 `json:"capitalbalance" xorm:"CAPITALBALANCE"` // 本周期本金余额[外部子账户实际出入金余额]
  509. CLOSEPL2 float64 `json:"closepl2" xorm:"CLOSEPL2"` // 平仓盈亏(逐笔)
  510. RECKONPL2 float64 `json:"reckonpl2" xorm:"RECKONPL2"` // 结算盈亏(逐笔) - 汇总取期末
  511. NETVALUE float64 `json:"netvalue" xorm:"NETVALUE"` // 净值 = 期末余额 + 所有权市值
  512. PAYCHARGE2 float64 `json:"paycharge2" xorm:"PAYCHARGE2"` // 今日手续费支出(外部配置)
  513. DEFERCHARGE float64 `json:"defercharge" xorm:"DEFERCHARGE"` // 本周期递延费2支出[111, 112]
  514. FROMACCOUNTID int64 `json:"fromaccountid" xorm:"FROMACCOUNTID"` // 所属上级账户
  515. SUBLEVELPATH string `json:"sublevelpath" xorm:"SUBLEVELPATH"` // 账号层级路径(逗号分隔,首尾加逗号)
  516. RELATEUSERID int64 `json:"relateuserid" xorm:"RELATEUSERID"` // 关联用户
  517. OWNERSHIPVALUE float64 `json:"ownershipvalue" xorm:"OWNERSHIPVALUE"` // 所有权市值
  518. SPOTVALUE float64 `json:"spotvalue" xorm:"SPOTVALUE"` // 现货市值-统计服务更新
  519. ACCOUNTPL float64 `json:"accountpl" xorm:"ACCOUNTPL"` // 今日账户盈亏 = 今日净值-昨日净值+今日出金-今日入金-今日划转+今日授信减少-今日授信增加+今日其它授信减少-今日其它授信增加+今日三方出金-今日三方入金;由统计服务更新
  520. ACCOUNTNAME string `json:"accountname" xorm:"ACCOUNTNAME"` // 账户名称
  521. ORIDEBT float64 `json:"oridebt" xorm:"ORIDEBT"` // 期初欠款【期初】
  522. CURDEBT float64 `json:"curdebt" xorm:"CURDEBT"` // 期末欠款【期末】
  523. AVAIABLEMONEY float64 `json:"avaiablemoney" xorm:"AVAIABLEMONEY"` // 可用资金【期末】
  524. AVAIABLEOUTMONEY float64 `json:"avaiableoutmoney" xorm:"AVAIABLEOUTMONEY"` // 可出资金【期末】
  525. FLOATPL float64 `json:"floatpl" xorm:"FLOATPL"` // 浮动盈亏【期末】
  526. FLOATNETVALUE float64 `json:"floatnetvalue" xorm:"FLOATNETVALUE"` // 浮动净值【期末】
  527. RISKRATE float64 `json:"riskrate" xorm:"RISKRATE"` // 风险率【期末】
  528. }
  529. func (r *Reporttaaccount) calc() {
  530. }
  531. func (r *Reporttaaccount) buildSql() string {
  532. var sqlId utils.SQLVal = `
  533. select
  534. t.accountid,
  535. t.cycletype,
  536. t.cycletime,
  537. t.updatetime,
  538. t.userid,
  539. t.ismain,
  540. t.parentaccountid,
  541. t.taaccounttype,
  542. t.currencyid,
  543. t.balance,
  544. t.orifreezemargin,
  545. t.oriusedmargin,
  546. t.oriotherfreezemargin,
  547. t.orifreezecharge,
  548. t.orimortgagecredit,
  549. t.oriothercredit,
  550. t.orioutamountfreeze,
  551. t.currentbalance,
  552. t.freezemargin,
  553. t.usedmargin,
  554. t.otherfreezemargin,
  555. t.freezecharge,
  556. t.mortgagecredit,
  557. t.othercredit,
  558. t.outamountfreeze,
  559. t.inamount,
  560. t.outamount,
  561. t.paycharge,
  562. t.closepl,
  563. t.reckonpl,
  564. t.creditincrease,
  565. t.creditdecrease,
  566. t.othercreditincrease,
  567. t.othercreditdecrease,
  568. t.otherpay,
  569. t.otherincome,
  570. t.transferamount,
  571. t.outthreshold,
  572. t.clearbalance,
  573. t.dividedcharge,
  574. t.payexchcharge,
  575. t.clearpl,
  576. t.thirdinamount,
  577. t.tradecharge,
  578. t.interestcharge,
  579. t.deliverycharge,
  580. t.holdcharge,
  581. t.thirdoutamount,
  582. t.tradeqty,
  583. t.tradeamount,
  584. t.deliveryamountout,
  585. t.deliveryamountin,
  586. t.deliverycompensationfeeout,
  587. t.deliverycompensationfeein,
  588. t.capitalbalance,
  589. t.closepl2,
  590. t.reckonpl2,
  591. t.netvalue,
  592. t.paycharge2,
  593. t.defercharge,
  594. t.fromaccountid,
  595. t.sublevelpath,
  596. t.relateuserid,
  597. t.ownershipvalue,
  598. t.spotvalue,
  599. t.accountpl,
  600. t.accountname,
  601. t.oridebt,
  602. t.curdebt,
  603. t.avaiablemoney,
  604. t.avaiableoutmoney,
  605. t.floatpl,
  606. t.floatnetvalue,
  607. t.riskrate
  608. from report_taaccount t
  609. where t.cycletype = 1 and t.cycletime = '%v' and t.accountid = %v
  610. `
  611. sqlId.FormatParam(r.CYCLETIME, r.ACCOUNTID)
  612. return sqlId.String()
  613. }
  614. // GetDataEx 从数据库中查询数据
  615. func (r *Reporttaaccount) GetDataEx() (interface{}, error) {
  616. e := db.GetEngine()
  617. s := e.SQL(r.buildSql())
  618. sData := make([]Reporttaaccount, 0)
  619. if err := s.Find(&sData); err != nil {
  620. return nil, err
  621. }
  622. for i := range sData {
  623. sData[i].calc()
  624. }
  625. return sData, nil
  626. }