session.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package services
  2. import (
  3. "errors"
  4. "eta_gn/eta_bridge/models/eta"
  5. "eta_gn/eta_bridge/models/response"
  6. "eta_gn/eta_bridge/utils"
  7. "time"
  8. )
  9. func CreateEtaSession(sysUser *eta.Admin) (login response.LoginResp, session *eta.SysSession, err error, errMsg string) {
  10. errMsg = `登录失败`
  11. login = response.LoginResp{}
  12. var token string
  13. account := utils.MD5(sysUser.AdminName)
  14. token = utils.GenToken(account)
  15. session = new(eta.SysSession)
  16. session.UserName = sysUser.AdminName
  17. session.SysUserId = sysUser.AdminId
  18. session.ExpiredTime = time.Now().AddDate(0, 0, 90)
  19. session.IsRemember = 1
  20. session.CreatedTime = time.Now()
  21. session.LastUpdatedTime = time.Now()
  22. session.AccessToken = token
  23. if e := eta.AddSysSession(session); e != nil {
  24. errMsg = "新增session失败, err: "
  25. err = errors.New("新增session失败, err: " + e.Error())
  26. return
  27. }
  28. login.Authorization = token
  29. login.Authorization = "authorization=" + token
  30. login.RealName = sysUser.RealName
  31. login.AdminId = sysUser.AdminId
  32. login.AdminName = sysUser.AdminName
  33. login.RoleName = sysUser.RoleName
  34. login.SysRoleTypeCode = sysUser.RoleTypeCode //系统角色编码
  35. login.RoleTypeCode = sysUser.RoleTypeCode
  36. login.Authority = sysUser.Authority
  37. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  38. login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
  39. }
  40. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  41. login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
  42. }
  43. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
  44. login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
  45. }
  46. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  47. login.RoleTypeCode = utils.ROLE_TYPE_CODE_RAI_SELLER
  48. }
  49. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  50. login.RoleTypeCode = utils.ROLE_TYPE_CODE_RAI_SELLER
  51. }
  52. if sysUser.RoleName == utils.ROLE_NAME_FICC_DIRECTOR {
  53. login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
  54. }
  55. productId := GetProductId(sysUser.RoleTypeCode)
  56. productIdName := map[int]string{
  57. 0: "admin",
  58. utils.COMPANY_PRODUCT_FICC_ID: utils.COMPANY_PRODUCT_FICC_NAME,
  59. utils.COMPANY_PRODUCT_RAI_ID: utils.COMPANY_PRODUCT_RAI_NAME,
  60. }
  61. login.ProductName = productIdName[productId]
  62. return
  63. }