123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package services
- import (
- "fmt"
- "hongze/hongze_mobile_admin/models"
- "hongze/hongze_mobile_admin/models/tables/company_operation_record"
- "hongze/hongze_mobile_admin/services/alarm_msg"
- "hongze/hongze_mobile_admin/utils"
- "time"
- )
- //获取产品权限
- func GetProductId(roleTypeCode string) (productId int) {
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
- productId = 1
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
- productId = 2
- } else {
- productId = 0
- }
- return
- }
- //校验当前操作员是否具有联系人权限是否有操作权限
- func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId int) (ok bool) {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- ok = true
- return
- }
- if sysUserId == itemSellerId {
- ok = true
- return
- } else {
- if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- //如果是ficc类型,同时当前账户是ficc管理员
- ok = true
- } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- //如果是权益类型,同时当前账户是 权益管理员
- ok = true
- }
- }
- return
- }
- //添加操作日志
- func AddCompanyOperationRecord(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveUserRealName, approveRemark, status string) (err error) {
- defer func() {
- if err != nil {
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecord;Err"+err.Error(), 3)
- }
- }()
- record := new(company_operation_record.CompanyOperationRecord)
- record.CompanyId = companyId
- record.CompanyName = companyName
- record.SellerId = sellerId
- record.SysUserId = sysUserId
- record.SysRealName = sysUserRealName
- record.Remark = remark
- record.Operation = operation
- record.CreateTime = time.Now()
- record.ProductId = productId
- record.ProductName = productName
- record.ApproveUserId = approveAdminId
- record.ApproveRealName = approveUserRealName
- record.ApproveContent = approveContent
- record.ApproveRemark = approveRemark
- record.Status = status
- _, err = company_operation_record.AddCompanyOperationRecord(record)
- return
- }
- func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
- //user_view_record mobile
- companyViewTotal = make(map[int]int)
- userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- for _, userView := range userViewList {
- companyViewTotal[userView.CompanyId] = userView.ViewTotal
- }
- userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //AdvisoryArticleViewRecord mobile
- userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //AdvisoryArticleViewRecord email
- userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //ReportViewRecord mobile
- userViewList, err = models.GetCountReportViewRecordByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //ReportViewRecord email
- userViewList, err = models.GetCountReportViewRecordByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- fmt.Println("companyViewTotal5:", companyViewTotal)
- return
- }
- func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
- for _, userView := range userViewList {
- if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
- companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
- } else { //如果没有数据,那么直接赋值
- companyViewTotal[userView.CompanyId] = userView.ViewTotal
- }
- }
- return
- }
|