company.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_mobile_admin/models"
  5. "hongze/hongze_mobile_admin/models/tables/company_operation_record"
  6. "hongze/hongze_mobile_admin/services/alarm_msg"
  7. "hongze/hongze_mobile_admin/utils"
  8. "time"
  9. )
  10. //获取产品权限
  11. func GetProductId(roleTypeCode string) (productId int) {
  12. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  13. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  14. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  15. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
  16. productId = 1
  17. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  18. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  19. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  20. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  21. productId = 2
  22. } else {
  23. productId = 0
  24. }
  25. return
  26. }
  27. //校验当前操作员是否具有联系人权限是否有操作权限
  28. func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId int) (ok bool) {
  29. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  30. ok = true
  31. return
  32. }
  33. if sysUserId == itemSellerId {
  34. ok = true
  35. return
  36. } else {
  37. if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  38. //如果是ficc类型,同时当前账户是ficc管理员
  39. ok = true
  40. } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  41. //如果是权益类型,同时当前账户是 权益管理员
  42. ok = true
  43. }
  44. }
  45. return
  46. }
  47. //添加操作日志
  48. func AddCompanyOperationRecord(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveUserRealName, approveRemark, status string) (err error) {
  49. defer func() {
  50. if err != nil {
  51. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err"+err.Error(), utils.EmailSendToUsers)
  52. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecord;Err"+err.Error(), 3)
  53. }
  54. }()
  55. record := new(company_operation_record.CompanyOperationRecord)
  56. record.CompanyId = companyId
  57. record.CompanyName = companyName
  58. record.SellerId = sellerId
  59. record.SysUserId = sysUserId
  60. record.SysRealName = sysUserRealName
  61. record.Remark = remark
  62. record.Operation = operation
  63. record.CreateTime = time.Now()
  64. record.ProductId = productId
  65. record.ProductName = productName
  66. record.ApproveUserId = approveAdminId
  67. record.ApproveRealName = approveUserRealName
  68. record.ApproveContent = approveContent
  69. record.ApproveRemark = approveRemark
  70. record.Status = status
  71. _, err = company_operation_record.AddCompanyOperationRecord(record)
  72. return
  73. }
  74. func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  75. //user_view_record mobile
  76. companyViewTotal = make(map[int]int)
  77. userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
  78. if err != nil {
  79. return
  80. }
  81. for _, userView := range userViewList {
  82. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  83. }
  84. userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
  85. if err != nil {
  86. return
  87. }
  88. checkCount(companyViewTotal, userViewList)
  89. //AdvisoryArticleViewRecord mobile
  90. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  91. if err != nil {
  92. return
  93. }
  94. checkCount(companyViewTotal, userViewList)
  95. //AdvisoryArticleViewRecord email
  96. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  97. if err != nil {
  98. return
  99. }
  100. checkCount(companyViewTotal, userViewList)
  101. //ReportViewRecord mobile
  102. userViewList, err = models.GetCountReportViewRecordByCompanyIdsMobile(companyIdStr)
  103. if err != nil {
  104. return
  105. }
  106. checkCount(companyViewTotal, userViewList)
  107. //ReportViewRecord email
  108. userViewList, err = models.GetCountReportViewRecordByCompanyIdsEmail(companyIdStr)
  109. if err != nil {
  110. return
  111. }
  112. checkCount(companyViewTotal, userViewList)
  113. fmt.Println("companyViewTotal5:", companyViewTotal)
  114. return
  115. }
  116. func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
  117. for _, userView := range userViewList {
  118. if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
  119. companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
  120. } else { //如果没有数据,那么直接赋值
  121. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  122. }
  123. }
  124. return
  125. }