ermcpAccMgr.go 28 KB

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