english_company_todo.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hz_eta_api/models"
  5. "hongze/hz_eta_api/models/system"
  6. "hongze/hz_eta_api/utils"
  7. "strconv"
  8. "time"
  9. )
  10. const (
  11. TodoButtonColorDoing = "red"
  12. TodoButtonColorDefault = "gray"
  13. TodoButtonColorCompleted = "green"
  14. )
  15. // GetEnglishCompanyTodoAuthRole 获取可操作英文客户TODO的角色列表
  16. func GetEnglishCompanyTodoAuthRole() []string {
  17. return []string{
  18. utils.ROLE_TYPE_CODE_ADMIN, // 管理员
  19. utils.ROLE_TYPE_CODE_FICC_ADMIN, // FICC管理员
  20. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, // FICC部门经理
  21. utils.ROLE_TYPE_CODE_FICC_GROUP, // FICC销售主管
  22. utils.ROLE_TYPE_CODE_FICC_TEAM, // FICC销售组长
  23. utils.ROLE_TYPE_CODE_FICC_SELLER, // FICC销售
  24. utils.ROLE_TYPE_CODE_FICC_RESEARCHR, // ficc研究员
  25. }
  26. }
  27. // CheckEnglishCompanyTodoAuth 校验当前用户对客户的操作(新增/编辑)权限
  28. func CheckEnglishCompanyTodoAuth(sysUser *system.Admin, sellerInfo *system.Admin) (ok bool, errMsg string, err error) {
  29. // 是否有权限添加/编辑任务
  30. roleCode := sysUser.RoleTypeCode
  31. authList := GetEnglishCompanyTodoAuthRole()
  32. if !utils.InArrayByStr(authList, roleCode) {
  33. errMsg = "账号角色异常,不允许操作"
  34. return
  35. }
  36. // 销售仅能操作自己的客户
  37. if roleCode == utils.ROLE_TYPE_CODE_FICC_SELLER && sellerInfo.AdminId != sysUser.AdminId {
  38. errMsg = "该客户不是当前账号所属,不允许操作"
  39. return
  40. }
  41. // 判断销售主管、组长权限, 其余管理员角色不做限制
  42. switch roleCode {
  43. case utils.ROLE_TYPE_CODE_FICC_GROUP:
  44. same, e := CheckAdminIsSameBigGroup(sysUser, sellerInfo)
  45. if e != nil {
  46. errMsg = "保存失败"
  47. err = errors.New("判断主管与客户所属销售是否属于同一大组失败, Err: " + e.Error())
  48. return
  49. }
  50. if !same {
  51. errMsg = "该客户销售不是当前账号所属组员,不允许操作"
  52. return
  53. }
  54. case utils.ROLE_TYPE_CODE_FICC_TEAM:
  55. if sellerInfo.GroupId != sysUser.GroupId {
  56. errMsg = "该客户销售不是当前账号所属组员,不允许操作"
  57. return
  58. }
  59. }
  60. ok = true
  61. return
  62. }
  63. // GetEnglishCompanyListTodoMap 获取英文客户列表TODO相关信息
  64. func GetEnglishCompanyListTodoMap(companyList []*models.EnglishCompanyListItem, sysUser *system.Admin) (todoMap map[int]*models.EnglishCompanyListTodo) {
  65. todoMap = make(map[int]*models.EnglishCompanyListTodo, 0)
  66. if len(companyList) == 0 || sysUser == nil {
  67. return
  68. }
  69. nowTime := time.Now().Local()
  70. todayTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
  71. for i := range companyList {
  72. c := companyList[i]
  73. v := new(models.EnglishCompanyListTodo)
  74. v.TodoButtonColor = TodoButtonColorDefault
  75. v.HiddenConfirm = true // 默认隐藏完成按钮
  76. if c.TodoStatusStr != models.EnglishCompanyTodoStatusNull {
  77. // 已完成
  78. if c.TodoStatusStr == models.EnglishCompanyTodoStatusCompleted {
  79. v.TodoButtonColor = TodoButtonColorCompleted
  80. }
  81. // 进行中
  82. if c.TodoStatusStr == models.EnglishCompanyTodoStatusDoing {
  83. v.TodoStatus = true
  84. v.TodoButtonColor = TodoButtonColorDoing
  85. //v.TodoEndTime = td.EndTime
  86. v.TodoEndTimeStr = c.TodoEndTime.Format(utils.FormatDate)
  87. // 截止目前还剩余的天数
  88. todoEndTime := time.Date(c.TodoEndTime.Year(), c.TodoEndTime.Month(), c.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  89. deadline := int(todoEndTime.Sub(todayTime).Hours() / 24)
  90. v.Deadline = strconv.Itoa(deadline)
  91. }
  92. // 根据当前角色判断按钮权限
  93. switch sysUser.RoleTypeCode {
  94. case utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_RESEARCHR:
  95. v.HiddenConfirm = false
  96. if c.TodoStatusStr == models.EnglishCompanyTodoStatusDoing {
  97. v.CanConfirm = true
  98. }
  99. case utils.ROLE_TYPE_CODE_FICC_TEAM:
  100. // 组长不是自己的客户则展示完成按钮
  101. if c.SellerId != sysUser.AdminId {
  102. v.HiddenConfirm = false
  103. }
  104. if c.TodoStatusStr == models.EnglishCompanyTodoStatusDoing {
  105. v.CanConfirm = true
  106. }
  107. }
  108. }
  109. todoMap[c.CompanyId] = v
  110. }
  111. return
  112. }