ermcpAccMgr.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/3/30 13:38
  4. * @Modify : 2021/3/30 13:38
  5. * @note : 账户管理
  6. **/
  7. package models
  8. import (
  9. "fmt"
  10. "mtp2_if/db"
  11. "mtp2_if/mtpcache"
  12. "mtp2_if/utils"
  13. "strings"
  14. )
  15. // ErmcpLoginUserEx 登录账号(按角色)
  16. type ErmcpLoginUserEx struct {
  17. ROLENAME string `json:"rolename"` // 角色名称
  18. USERTYPE int32 `json:"usertype"` // 用户类型 2-机构 7-企业成员(云平台)
  19. UserList []ErmcpLoginUser `json:"userlist"` // 用户列表
  20. RoleId int32 `json:"roleid"` // 角色id
  21. }
  22. // ErmcpLoginUser 查询登录账户
  23. type ErmcpLoginUser struct {
  24. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  25. MEMBERUSERID int64 `json:"memberuserid" xorm:"'MEMBERUSERID'"` // 所属会员id
  26. ACCOUNTNAME string `json:"accountname" xorm:"'ACCOUNTNAME'"` // 用户名称
  27. USERTYPE int32 `json:"usertype" xorm:"'USERTYPE'"` // 用户类型 - 1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者 6:客户 7:企业成员(云平台)
  28. LOGINSTATUS int32 `json:"loginstatus" xorm:"'LOGINSTATUS'"` // 登录账户状态 - 1:正常 2:冻结 3:无效
  29. CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  30. MODIFYTIME string `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  31. ROLETYPE string `json:"roletype" xorm:"'ROLETYPE'"` // 角色类型(逗号隔开,如22,23), 22:业务员 23:跟单员 24:交易员
  32. CLIENTROLEID int32 `json:"clientroleid" xorm:"'CLIENTROLEID'"` // 角色id(usertype=2)
  33. ROLENAME string `json:"rolename" xorm:"'ROLENAME'"` // 角色名称
  34. ROLESTATUS int32 `json:"rolestatus" xorm:"'ROLESTATUS'"` // 角色状态 1-启用 2-停用
  35. LOGINCODE string `json:"logincode" xorm:"'LOGINCODE'"` // 登录代码
  36. LOGINID int64 `json:"loginid" xorm:"'LOGINID'"` // 登录id(LOGINID)
  37. }
  38. func (r *ErmcpLoginUser) calc() {
  39. }
  40. func (r *ErmcpLoginUser) buildSql() string {
  41. var sqlId utils.SQLVal = "with tmp as" +
  42. " (select userid, wm_concat(roletype) roletype from arearole group by userid)" +
  43. "select t.userid," +
  44. " t.memberuserid," +
  45. " t.usertype," +
  46. " t.accountname," +
  47. " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  48. " to_char(t.modifytime, 'yyyy-mm-dd hh24:mi:ss') modifytime," +
  49. " r.roletype," +
  50. " 1 as rolestatus," +
  51. " l.logincode," +
  52. " l.loginid," +
  53. " l.clientroleid," +
  54. " '企业成员' rolename," +
  55. " l.loginstatus" +
  56. " from useraccount t" +
  57. " left join loginaccount l" +
  58. " on t.userid = l.userid" +
  59. " left join tmp r" +
  60. " on t.userid = r.userid" +
  61. " where 1=1" +
  62. " and t.memberuserid = %v" +
  63. " and t.usertype = 7" +
  64. " union all " +
  65. "select t.userid," +
  66. " t.memberuserid," +
  67. " t.usertype," +
  68. " t.accountname," +
  69. " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
  70. " to_char(t.modifytime, 'yyyy-mm-dd hh24:mi:ss') modifytime," +
  71. " to_char(r.roletype) roletype," +
  72. " r.rolestatus," +
  73. " l.logincode," +
  74. " l.loginid," +
  75. " l.clientroleid," +
  76. " Nvl(r.rolename, l.clientroleid) rolename," +
  77. " l.loginstatus" +
  78. " from useraccount t" +
  79. " left join loginaccount l" +
  80. " on t.userid = l.userid" +
  81. " left join systemmanagerrole r on l.clientroleid=r.autoid and r.areauserid=l.userid" +
  82. " where 1=1" +
  83. " and t.userid = %v" +
  84. " and t.usertype = 2"
  85. sqlId.FormatParam(r.USERID, r.USERID)
  86. return sqlId.String()
  87. }
  88. // hasRoletype 是否拥用某种角色
  89. func (r *ErmcpLoginUser) hasRoletype(nType int32) bool {
  90. sType := strings.Split(r.ROLETYPE, ",")
  91. strType := fmt.Sprintf("%v", nType)
  92. for i := range sType {
  93. if sType[i] == strType {
  94. return true
  95. }
  96. }
  97. return false
  98. }
  99. // GetDataEx 查询登录用户
  100. func (r *ErmcpLoginUser) GetDataEx() (interface{}, error) {
  101. sDataEx := make([]ErmcpLoginUserEx, 0)
  102. // 查询角色
  103. m := ErmcpRole{AREAUSERID: r.USERID}
  104. roles, _ := m.GetData()
  105. if len(roles) == 0 {
  106. return sDataEx, nil
  107. }
  108. // 初始化角色列表
  109. for _, val := range roles {
  110. sDataEx = append(sDataEx, ErmcpLoginUserEx{
  111. ROLENAME: val.ROLENAME,
  112. RoleId: val.AUTOID,
  113. UserList: make([]ErmcpLoginUser, 0),
  114. USERTYPE: func(roldId int32) int32 {
  115. if roldId == 22 || roldId == 23 || roldId == 24 {
  116. return 7
  117. }
  118. return 2
  119. }(val.AUTOID),
  120. })
  121. }
  122. // 查询用户
  123. sData := make([]ErmcpLoginUser, 0)
  124. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  125. for _, v := range sData {
  126. for i := range sDataEx {
  127. if v.USERTYPE == 2 {
  128. // 企业管理角色直接使用CLIENTROLEID判断
  129. if sDataEx[i].RoleId == v.CLIENTROLEID {
  130. sDataEx[i].UserList = append(sDataEx[i].UserList, v)
  131. }
  132. } else {
  133. // 企业成员usertype=7需根据roletype判断
  134. if sDataEx[i].RoleId == 22 && v.hasRoletype(22) {
  135. sDataEx[i].UserList = append(sDataEx[i].UserList, v)
  136. }
  137. if sDataEx[i].RoleId == 23 && v.hasRoletype(23) {
  138. }
  139. if sDataEx[i].RoleId == 24 && v.hasRoletype(24) {
  140. sDataEx[i].UserList = append(sDataEx[i].UserList, v)
  141. }
  142. }
  143. }
  144. }
  145. return sDataEx, err
  146. }
  147. // ErmcpTaAccount 期货账户(分组)
  148. type ErmcpTaAccountEx struct {
  149. MainAcc ErmcpTaAccount `json:"mainAcc"` // 主账号
  150. SubAccList []ErmcpTaAccount `json:"subacclist"` // 子账号列表
  151. }
  152. // ErmcpTaAccount 期货账户
  153. type ErmcpTaAccount struct {
  154. ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 账户id
  155. CURRENCYID int32 `json:"currencyid" xorm:"'CURRENCYID'"` // 币种id
  156. TRADESTATUS int32 `json:"tradestatus" xorm:"'TRADESTATUS'"` // 交易状态 - 1:正常 2:受限 3:冻结 4:禁止建仓(人工受限) 5:禁止交易(人工冻结) 6:待激活 7:已注销
  157. ISMAIN int32 `json:"ismain" xorm:"'ISMAIN'"` // 是否主账户 0-否 1-是
  158. RELATEDUSERID int64 `json:"relateduserid" xorm:"'RELATEDUSERID'"` // 关联userid
  159. ACCOUNTNAME string `json:"accountname" xorm:"'ACCOUNTNAME'"` // 账户名称
  160. PARENTACCOUNTID int64 `json:"parentaccountid" xorm:"'PARENTACCOUNTID'"` // 父账户id
  161. }
  162. func (r *ErmcpTaAccount) calc() {
  163. }
  164. func (r *ErmcpTaAccount) buildSql() string {
  165. var sqlId utils.SQLVal = "select t.accountid," +
  166. " t.currencyid," +
  167. " t.tradestatus," +
  168. " t.ismain," +
  169. " t.relateduserid," +
  170. " t.accountname," +
  171. " t.parentaccountid" +
  172. " from taaccount t" +
  173. " where 1 = 1"
  174. sqlId.And("t.relateduserid", r.RELATEDUSERID)
  175. return sqlId.String()
  176. }
  177. // GetDataEx 查询企业期货账户
  178. func (r *ErmcpTaAccount) GetDataEx() (interface{}, error) {
  179. sData := make([]ErmcpTaAccount, 0)
  180. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  181. sDataEx := make([]ErmcpTaAccountEx, 0)
  182. // 主账号
  183. for i := range sData {
  184. if sData[i].ISMAIN == 1 {
  185. val := ErmcpTaAccountEx{MainAcc: sData[i], SubAccList: make([]ErmcpTaAccount, 0)}
  186. sDataEx = append(sDataEx, val)
  187. }
  188. }
  189. // 子账号
  190. for i := range sData {
  191. if sData[i].ISMAIN == 0 {
  192. for k := range sDataEx {
  193. if sDataEx[k].MainAcc.ACCOUNTID == sData[i].PARENTACCOUNTID {
  194. sDataEx[k].SubAccList = append(sDataEx[k].SubAccList, sData[i])
  195. }
  196. }
  197. }
  198. }
  199. return sDataEx, err
  200. }
  201. // MainAccountInfo 主账号详情
  202. type MainAccountInfo struct {
  203. ACCOUNTID string `json:"accountid" xorm:"'ACCOUNTID'"` // 账号id
  204. HEDGEACCOUNTCODE string `json:"hedgeaccountcode" xorm:"'HEDGEACCOUNTCODE'"` // 外部账号代码
  205. HEDGEACCOUNTPWD string `json:"hedgeaccountpwd" xorm:"'HEDGEACCOUNTPWD'"` // 密码
  206. AUTHCODE string `json:"authcode" xorm:"'AUTHCODE'"` // 授权码
  207. APPID string `json:"appid" xorm:"'APPID'"` // AppID
  208. BROKERID string `json:"brokerid" xorm:"'BROKERID'"` // 经纪商id
  209. FCID int32 `json:"fcid" xorm:"'FCID'"` // 期货公司id
  210. FCNAME string `json:"fcname" xorm:"'FCNAME'"` // 期货公司代码
  211. ISMAIN int32 `json:"ismain" xorm:"'ISMAIN'"` // 是否主账号
  212. RELATEDUSERID int64 `json:"relateduserid" xorm:"'RELATEDUSERID'"` // 关联用户id
  213. }
  214. func (r *MainAccountInfo) calc() {
  215. r.HEDGEACCOUNTPWD = DecryptField(r.HEDGEACCOUNTPWD)
  216. }
  217. func (r *MainAccountInfo) buildSql() string {
  218. var sqlId utils.SQLVal = "select t.accountid," +
  219. " t.hedgeaccountcode," +
  220. " c.hedgeaccountpwd," +
  221. " c.authcode," +
  222. " c.appid," +
  223. " c.brokerid," +
  224. " c.fcid," +
  225. " f.fcname," +
  226. " ta.ismain," +
  227. " ta.relateduserid" +
  228. " from hedge_outtaaccount t" +
  229. " left join hedge_outmainconfig c" +
  230. " on t.accountid = c.accountid" +
  231. " left join ERMCP_FuturesCompany f" +
  232. " on c.fcid = f.fcid" +
  233. " left join taaccount ta on t.accountid=ta.accountid" +
  234. " where 1 = 1"
  235. if r.RELATEDUSERID > 0 {
  236. sqlId.And("ta.relateduserid", r.RELATEDUSERID)
  237. }
  238. if len(r.ACCOUNTID) > 0 {
  239. sqlId.And("t.ACCOUNTID", r.ACCOUNTID)
  240. }
  241. return sqlId.String()
  242. }
  243. // GetDataEx 查询主账号信息
  244. func (r *MainAccountInfo) GetDataEx() (interface{}, error) {
  245. sData := make([]MainAccountInfo, 0)
  246. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  247. for i := range sData {
  248. sData[i].calc()
  249. }
  250. return sData, err
  251. }
  252. // ErmcpRole 角色
  253. type ErmcpRole struct {
  254. AUTOID int32 `json:"autoid" xorm:"'AUTOID'"` // 角色ID(自增ID)
  255. ROLENAME string `json:"rolename" xorm:"'ROLENAME'"` // 角色名称
  256. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  257. ROLESTATUS int32 `json:"rolestatus" xorm:"'ROLESTATUS'"` // 角色状态 - 1:启用 2:停用
  258. ROLETYPE int32 `json:"roletype" xorm:"'ROLETYPE'"` // 角色类型 - 1- 管理端 2- 交易端
  259. MODIFYTIME string `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间(创建时间)
  260. MODIFIERID int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人(创建人)
  261. MODIFIERNAME string `json:"modifiername"` // 修改人名称
  262. }
  263. func (r *ErmcpRole) calc() {
  264. if r.MODIFIERID > 0 {
  265. r.MODIFIERNAME = mtpcache.GetSystemmangerLoginCode(r.MODIFIERID)
  266. // 目前看表里修改人id存的是管理员id,为防止以后终端操作存的是登录id,多做一层判断
  267. // 如果按管理员id找不到,则按登录id试试
  268. if r.MODIFIERID > 1e8 && len(r.MODIFIERNAME) == 0 {
  269. r.MODIFIERNAME = mtpcache.GetLoginCodeByLoginId(r.MODIFIERID)
  270. }
  271. }
  272. }
  273. func (r *ErmcpRole) buildSql() string {
  274. var sqlId utils.SQLVal = "SELECT t.AUTOID," +
  275. " t.ROLENAME," +
  276. " t.AREAUSERID," +
  277. " t.ROLESTATUS," +
  278. " t.ROLETYPE," +
  279. " t.SENSITIVEFIELDS," +
  280. " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
  281. " to_char(t.MODIFIERID) MODIFIERID" +
  282. " FROM SYSTEMMANAGERROLE t" +
  283. " WHERE 1 = 1"
  284. if r.AREAUSERID > 0 {
  285. sqlId.And("t.AREAUSERID", r.AREAUSERID)
  286. }
  287. return sqlId.String()
  288. }
  289. // GetData
  290. func (r *ErmcpRole) GetData() ([]ErmcpRole, error) {
  291. sData := make([]ErmcpRole, 0)
  292. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  293. for i := range sData {
  294. sData[i].calc()
  295. }
  296. sDataEx := make([]ErmcpRole, 0)
  297. // 添加固定角色22,23,24
  298. sDataEx = append(sDataEx, ErmcpRole{AREAUSERID: r.AREAUSERID, ROLENAME: "业务员", AUTOID: 22,
  299. ROLESTATUS: 1, ROLETYPE: 2, MODIFYTIME: "-", MODIFIERID: 1, MODIFIERNAME: "平台"})
  300. sDataEx = append(sDataEx, ErmcpRole{AREAUSERID: r.AREAUSERID, ROLENAME: "跟单员", AUTOID: 23,
  301. ROLESTATUS: 1, ROLETYPE: 2, MODIFYTIME: "-", MODIFIERID: 1, MODIFIERNAME: "平台"})
  302. sDataEx = append(sDataEx, ErmcpRole{AREAUSERID: r.AREAUSERID, ROLENAME: "交易员", AUTOID: 24,
  303. ROLESTATUS: 1, ROLETYPE: 2, MODIFYTIME: "-", MODIFIERID: 1, MODIFIERNAME: "平台"})
  304. sDataEx = append(sDataEx, sData...)
  305. return sDataEx, err
  306. }
  307. // GetDataEx 查询角色
  308. func (r *ErmcpRole) GetDataEx() (interface{}, error) {
  309. return r.GetData()
  310. }
  311. // ErmcpRoleMenuEx 角色菜单(分层级)
  312. type ErmcpRoleMenuEx struct {
  313. Menu ErmcpRoleMenu // 父级菜单
  314. SubMenu []ErmcpRoleMenu // 子级菜单
  315. }
  316. // add 添加子级菜单
  317. func (r *ErmcpRoleMenuEx) add(menu ErmcpRoleMenu) {
  318. if menu.PARENTCODE == r.Menu.RESOURCECODE {
  319. r.SubMenu = append(r.SubMenu, menu)
  320. }
  321. }
  322. // ErmcpRoleMenu 角色菜单
  323. type ErmcpRoleMenu struct {
  324. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  325. ROLEID int32 `json:"roleid" xorm:"'ROLEID'"` // 角色id
  326. RESOURCECODE string `json:"resourcecode" xorm:"'RESOURCECODE'"` // 菜单代码
  327. RESOURCENAME string `json:"resourcename" xorm:"'RESOURCENAME'"` // 菜单名称
  328. RESOURCELEVEL int32 `json:"resourcelevel" xorm:"'RESOURCELEVEL'"` // 级别
  329. MENUTYPE int32 `json:"menutype" xorm:"'MENUTYPE'"` // 菜单类型 1:管理端 2:交易端 3:终端(企业云平台)
  330. PARENTCODE string `json:"parentcode" xorm:"'PARENTCODE'"` // 上级资源代码
  331. URL string `json:"url" xorm:"'URL'"` // URL
  332. SORT int32 `json:"sort" xorm:"'SORT'"` // 排序
  333. ICONAME string `json:"iconame" xorm:"'ICONAME'"` // 菜单图标
  334. REMARK string `json:"remark" xorm:"'REMARK'"` // 菜单备注
  335. FilterRoleId string `json:"-"` // 查询过滤条件, 角色 - 逗号隔开
  336. }
  337. func (r *ErmcpRoleMenu) calc() {
  338. }
  339. func (r *ErmcpRoleMenu) buildSql() string {
  340. var sqlId utils.SQLVal = "select distinct t.userid," +
  341. " t.roleid," +
  342. " t.resourcecode," +
  343. " f.resourcename," +
  344. " f.resourcelevel," +
  345. " f.menutype," +
  346. " f.parentcode," +
  347. " f.url," +
  348. " f.sort," +
  349. " f.iconame," +
  350. " f.remark" +
  351. " from ermcp_memberfuncmenu t" +
  352. " inner join funcmenulist f" +
  353. " on t.resourcecode = f.resourcecode" +
  354. " where t.isvalid = 1"
  355. if r.USERID > 0 {
  356. sqlId.And("t.userid", r.USERID)
  357. }
  358. if len(r.FilterRoleId) > 0 {
  359. sqlId.Join(fmt.Sprintf(" and t.roleid in(%v)", r.FilterRoleId))
  360. }
  361. sqlId.Join(" order by f.resourcelevel, f.sort")
  362. return sqlId.String()
  363. }
  364. // GetDataEx 查询角色菜单
  365. func (r *ErmcpRoleMenu) GetDataEx() (interface{}, error) {
  366. sData := make([]ErmcpRoleMenu, 0)
  367. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  368. for i := range sData {
  369. sData[i].calc()
  370. }
  371. // 构建层级树
  372. sDataEx := make([]ErmcpRoleMenuEx, 0)
  373. // 最多构建4层
  374. for level := int32(1); level <= 4; level++ {
  375. for _, v := range sData {
  376. if v.RESOURCELEVEL == level {
  377. val := ErmcpRoleMenuEx{Menu: v, SubMenu: make([]ErmcpRoleMenu, 0)}
  378. for _, v2 := range sData {
  379. // 获取子菜单
  380. if v2.ROLEID == v.ROLEID && v2.PARENTCODE == v.RESOURCECODE {
  381. val.SubMenu = append(val.SubMenu, v2)
  382. }
  383. }
  384. // 第一层固定要, 不管有没有子菜单
  385. if val.Menu.RESOURCELEVEL == 1 {
  386. sDataEx = append(sDataEx, val)
  387. } else if val.Menu.RESOURCELEVEL > 1 && len(val.SubMenu) > 0 {
  388. // 第二层开始,有子菜单内容的才要
  389. sDataEx = append(sDataEx, val)
  390. }
  391. }
  392. }
  393. }
  394. return sDataEx, err
  395. }
  396. // ErmcpBizGroupSpotGoods 业务类型分组商品表
  397. type ErmcpBizGroupSpotGoods struct {
  398. BIZTYPE int32 `json:"biztype" xorm:"'BIZTYPE'"` // 业务类型 1-套保 2-套利
  399. BIZGROUPID int64 `json:"bizgroupid" xorm:"'BIZGROUPID'"` // 分组id
  400. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货商品id
  401. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货商品代码
  402. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货商品名称
  403. GOODSUNITID int32 `json:"unitid" xorm:"'UNITID'"` // 现货商品单位id
  404. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  405. }
  406. func (r *ErmcpBizGroupSpotGoods) calc() {
  407. }
  408. func (r *ErmcpBizGroupSpotGoods) buildSql() string {
  409. var sqlId utils.SQLVal = "select t.biztype," +
  410. " t.bizgroupid," +
  411. " t.deliverygoodsid," +
  412. " g.deliverygoodsname," +
  413. " g.deliverygoodscode," +
  414. " g.goodsunitid," +
  415. " g.areauserid" +
  416. " from ERMCP_BizGroupSpotGoods t" +
  417. " left join deliverygoods g" +
  418. " on t.deliverygoodsid = g.deliverygoodsid" +
  419. " where 1=1"
  420. sqlId.AndEx("g.areauserid", r.AREAUSERID, r.AREAUSERID > 0)
  421. return sqlId.String()
  422. }
  423. // GetDataEx 获取业务类型分组商品
  424. func (r *ErmcpBizGroupSpotGoods) GetDataEx() ([]ErmcpBizGroupSpotGoods, error) {
  425. sData := make([]ErmcpBizGroupSpotGoods, 0)
  426. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  427. for i := range sData {
  428. sData[i].calc()
  429. }
  430. return sData, err
  431. }
  432. // ErcmpBizGroupTaaccount 业务分组账号
  433. type ErmcpBizGroupTaAccount struct {
  434. BIZGROUPID int64 `json:"bizgroupid" xorm:"'BIZGROUPID'"` // 业务分组id
  435. ACCOUNTID string `json:"accountid" xorm:"'ACCOUNTID'"` // 账号id
  436. AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
  437. ACCOUNTNAME string `json:"accountname" xorm:"'ACCOUNTNAME'"` // 账号名称
  438. ISMAIN int32 `json:"ismain" xorm:"'ISMAIN'"` // 是否主账号 1-是 0-否
  439. }
  440. func (r *ErmcpBizGroupTaAccount) calc() {
  441. }
  442. func (r *ErmcpBizGroupTaAccount) buildSql() string {
  443. var sqlId utils.SQLVal = "select t.bizgroupid," +
  444. " t.accountid," +
  445. " ta.relateduserid areauserid," +
  446. " ta.accountname," +
  447. " ta.ismain" +
  448. " from ermcp_bizgrouptaaccount t" +
  449. " left join taaccount ta" +
  450. " on t.accountid = ta.accountid" +
  451. " where 1 = 1"
  452. if r.AREAUSERID > 0 {
  453. sqlId.And("ta.relateduserid", r.AREAUSERID)
  454. }
  455. return sqlId.String()
  456. }
  457. // GetDataEx 获取业务分组账号
  458. func (r *ErmcpBizGroupTaAccount) GetDataEx() ([]ErmcpBizGroupTaAccount, error) {
  459. sData := make([]ErmcpBizGroupTaAccount, 0)
  460. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  461. for i := range sData {
  462. sData[i].calc()
  463. }
  464. return sData, err
  465. }
  466. // 账户设置分组信息
  467. type ErmcpBizGroupEx struct {
  468. BIZTYPE int32 `json:"biztype" xorm:"'BIZTYPE'"` // 业务类型 1-套保 2-套利
  469. BIZGROUPID int64 `json:"bizgroupid" xorm:"'BIZGROUPID'"` // 业务分组id
  470. AccList []ErmcpBizGroupTaAccount `json:"acclist"` // 账号列表
  471. WrList []ErmcpBizGroupSpotGoods `json:"wrlist"` // 现货商品表
  472. AREAUSERID int64 `json:"-"` // 所属机构
  473. }
  474. // GetDataEx 获取账户设置分组信息
  475. func (r *ErmcpBizGroupEx) GetDataEx() (interface{}, error) {
  476. sData := make([]ErmcpBizGroupEx, 0)
  477. mWr := ErmcpBizGroupSpotGoods{AREAUSERID: r.AREAUSERID}
  478. mAcc := ErmcpBizGroupTaAccount{AREAUSERID: r.AREAUSERID}
  479. if wrLst, err := mWr.GetDataEx(); err == nil {
  480. for i := range wrLst {
  481. var bFind bool = false
  482. for k := range sData {
  483. if sData[k].BIZGROUPID == wrLst[i].BIZGROUPID &&
  484. sData[k].BIZTYPE == wrLst[i].BIZTYPE {
  485. sData[k].WrList = append(sData[k].WrList, wrLst[i])
  486. bFind = true
  487. }
  488. }
  489. if !bFind {
  490. var d = ErmcpBizGroupEx{BIZGROUPID: wrLst[i].BIZGROUPID,
  491. BIZTYPE: wrLst[i].BIZTYPE,
  492. AccList: make([]ErmcpBizGroupTaAccount, 0),
  493. WrList: make([]ErmcpBizGroupSpotGoods, 0)}
  494. d.WrList = append(d.WrList, wrLst[i])
  495. sData = append(sData, d)
  496. }
  497. }
  498. }
  499. if accLst, err := mAcc.GetDataEx(); err == nil {
  500. for i := range accLst {
  501. for k := range sData {
  502. if sData[k].BIZGROUPID == accLst[i].BIZGROUPID {
  503. sData[k].AccList = append(sData[k].AccList, accLst[i])
  504. }
  505. }
  506. }
  507. }
  508. return sData, nil
  509. }
  510. // 资金账号信息
  511. type ErmcpTaAccountInfo struct {
  512. CREDITDECREASE float64 `json:"creditdecrease" xorm:"'CREDITDECREASE'"` // 今日授信减少
  513. OTHERCREDITINCREASE float64 `json:"othercreditincrease" xorm:"'OTHERCREDITINCREASE'"` // 今日其它授信增加
  514. OTHERCREDITDECREASE float64 `json:"othercreditdecrease" xorm:"'OTHERCREDITDECREASE'"` // 今日其它授信减少
  515. TRANSFERAMOUNT float64 `json:"transferamount" xorm:"'TRANSFERAMOUNT'"` // 今日划转金额(母子账号资金划转,从划入账号为正,从账号划出为负)
  516. OTHERPAY float64 `json:"-" xorm:"'OTHERPAY'"` // 其他支出(交割付款 申购付款 全款买入 商城买入 卖家退货)
  517. OTHERINCOME float64 `json:"-" xorm:"'OTHERINCOME'"` // 其他收入(交割收款 申购收款 全款卖出 商城卖出 买家退货 会员手续费收入)
  518. OUTTHRESHOLD float64 `json:"outthreshold" xorm:"'OUTTHRESHOLD'"` // 出金阈值
  519. TRADESTATUSCHANGETIME string `json:"-" xorm:"'TRADESTATUSCHANGETIME'"` // 激活时间
  520. CHANGETIME string `json:"-" xorm:"'CHANGETIME'"` // 账户状态变更时间
  521. THIRDINAMOUNT float64 `json:"thirdinamount" xorm:"'THIRDINAMOUNT'"` // 今日三方入金
  522. THIRDOUTAMOUNT float64 `json:"thirdoutamount" xorm:"'THIRDOUTAMOUNT'"` // 今日三方出金
  523. CAPITALBALANCE float64 `json:"capitalbalance" xorm:"'CAPITALBALANCE'"` // 本金余额[外部子账户实际出入金余额]
  524. FROMACCOUNTID int64 `json:"fromaccountid" xorm:"'FROMACCOUNTID'"` // 所属上级账户
  525. SUBLEVELPATH string `json:"sublevelpath" xorm:"'SUBLEVELPATH'"` // 账号层级路径(逗号分隔,首尾加逗号)
  526. SERIVCEGROUP int64 `json:"-" xorm:"'SERIVCEGROUP'"` // 服务分组
  527. ACCOUNTNAME string `json:"accountname" xorm:"'ACCOUNTNAME'"` // 账户名称
  528. ACCOUNTFLAG int32 `json:"-" xorm:"'ACCOUNTFLAG'"` // 账户标识 - 0\1 (默认为0, 当上级账户与本账户的关联用户均为自己时更新为1)
  529. ORIDEBT float64 `json:"oridebt" xorm:"'ORIDEBT'"` // 期初欠款
  530. CURDEBT float64 `json:"curdebt" xorm:"'CURDEBT'"` // 期末欠款
  531. ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账户ID
  532. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  533. CURRENCYID int64 `json:"currencyid" xorm:"'CURRENCYID'"` // 货币ID
  534. CHANGEFLAG int32 `json:"-" xorm:"'CHANGEFLAG'"` // 变动标志(当前账户资金有任何变动更新为1系统结算时更新0;供清算时使用) 0:无变动 1:有变动
  535. PASSWORD string `json:"-" xorm:"'PASSWORD'"` // 资金密码
  536. TRADESTATUS int32 `json:"tradestatus" xorm:"'TRADESTATUS'"` // 交易状态 - 1:正常 2:受限 3:冻结 4:禁止建仓(人工受限) 5:禁止交易(人工冻结) 6:待激活 7:已注销
  537. SIGNSTATUS int32 `json:"signstatus" xorm:"'SIGNSTATUS'"` // 签约状态 - 1:未签约 2:签约待审核 3:签约中 4:已签约 5:解约待审核 6:解约中 7:已解约 8:已解绑 9:绑卡中
  538. ISMAIN int32 `json:"ismain" xorm:"'ISMAIN'"` // 是否母账号 0:不是母账户 1:是母账户
  539. PARENTACCOUNTID int64 `json:"parentaccountid" xorm:"'PARENTACCOUNTID'"` // 所属根账号
  540. RELATEDUSERID int64 `json:"relateduserid" xorm:"'RELATEDUSERID'"` // 关联用户
  541. RELATEDACCOUNTSTATUS int32 `json:"-" xorm:"'RELATEDACCOUNTSTATUS'"` // 关联用户交易权限状态 - 1:正常(可交易) 2:受限(可平仓,不可建仓) 3:冻结(不可交易)
  542. TAACCOUNTTYPE int32 `json:"taaccounttype" xorm:"'TAACCOUNTTYPE'"` // 账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号
  543. ISRECKONACCOUNT int32 `json:"-" xorm:"'ISRECKONACCOUNT'"` // 是否机构分润账号 0:不是 1:是
  544. ISMARKETACCOUNT int32 `json:"-" xorm:"'ISMARKETACCOUNT'"` // 是否机构接单账号 0:不是 1:是
  545. BALANCE float64 `json:"balance" xorm:"'BALANCE'"` // 期初余额
  546. ORIFREEZEMARGIN float64 `json:"orifreezemargin" xorm:"'ORIFREEZEMARGIN'"` // 期初冻结保证金
  547. ORIUSEDMARGIN float64 `json:"oriusedmargin" xorm:"'ORIUSEDMARGIN'"` // 期初占用保证金
  548. ORIOTHERFREEZEMARGIN float64 `json:"oriotherfreezemargin" xorm:"'ORIOTHERFREEZEMARGIN'"` // 期初其他冻结保证金(出金冻结资金 交割买方冻结 申购冻结 全款买入 商城买入)
  549. ORIFREEZECHARGE float64 `json:"orifreezecharge" xorm:"'ORIFREEZECHARGE'"` // 期初手续费冻结
  550. ORIMORTGAGECREDIT float64 `json:"orimortgagecredit" xorm:"'ORIMORTGAGECREDIT'"` // 期初授信金额
  551. ORIOTHERCREDIT float64 `json:"oriothercredit" xorm:"'ORIOTHERCREDIT'"` // 期初其它授信金额
  552. ORIOUTAMOUNTFREEZE float64 `json:"orioutamountfreeze" xorm:"'ORIOUTAMOUNTFREEZE'"` // 期初出金冻结
  553. FREEZEMARGIN float64 `json:"freezemargin" xorm:"'FREEZEMARGIN'"` // 冻结保证金
  554. USEDMARGIN float64 `json:"usedmargin" xorm:"'USEDMARGIN'"` // 占用保证金
  555. OTHERFREEZEMARGIN float64 `json:"otherfreezemargin" xorm:"'OTHERFREEZEMARGIN'"` // 其他冻结保证金(交割买方冻结 申购冻结 全款买入 商城买入)
  556. FREEZECHARGE float64 `json:"freezecharge" xorm:"'FREEZECHARGE'"` // 手续费冻结
  557. MORTGAGECREDIT float64 `json:"mortgagecredit" xorm:"'MORTGAGECREDIT'"` // 授信金额
  558. OTHERCREDIT float64 `json:"othercredit" xorm:"'OTHERCREDIT'"` // 其它授信金额
  559. OUTAMOUNTFREEZE float64 `json:"outamountfreeze" xorm:"'OUTAMOUNTFREEZE'"` // 出金冻结
  560. INAMOUNT float64 `json:"inamount" xorm:"'INAMOUNT'"` // 今日入金金额(包括三方入金)
  561. CURRENTBALANCE float64 `json:"currentbalance" xorm:"'CURRENTBALANCE'"` // 期末余额
  562. OUTAMOUNT float64 `json:"outamount" xorm:"'OUTAMOUNT'"` // 今日出金金额(包括三方出金)
  563. PAYCHARGE float64 `json:"paycharge" xorm:"'PAYCHARGE'"` // 今日手续费支出
  564. CLOSEPL float64 `json:"closepl" xorm:"'CLOSEPL'"` // 今日平仓盈亏
  565. CREDITINCREASE float64 `json:"creditincrease" xorm:"'CREDITINCREASE'"` // 今日授信增加
  566. }
  567. func (r *ErmcpTaAccountInfo) calc() {
  568. }
  569. func (r *ErmcpTaAccountInfo) buildSql() string {
  570. var sqlId utils.SQLVal = "select * from taaccount t where 1 = 1"
  571. if r.USERID > 0 {
  572. sqlId.And("t.RELATEDUSERID", r.RELATEDUSERID)
  573. }
  574. if r.ACCOUNTID > 0 {
  575. sqlId.And("t.accountid", r.ACCOUNTID)
  576. }
  577. return sqlId.String()
  578. }
  579. // 获取资金账号信息
  580. func (r *ErmcpTaAccountInfo) GetDataEx() (interface{}, error) {
  581. sData := make([]ErmcpTaAccountInfo, 0)
  582. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  583. for i := range sData {
  584. sData[i].calc()
  585. }
  586. return sData, err
  587. }