package english_report import ( "fmt" "hongze/hongze_yb_en_api/models/en_classify_permission" "hongze/hongze_yb_en_api/models/en_company_permission" "hongze/hongze_yb_en_api/models/english_company" "hongze/hongze_yb_en_api/models/english_report" "hongze/hongze_yb_en_api/models/english_report_email" "hongze/hongze_yb_en_api/services/alarm_msg" "hongze/hongze_yb_en_api/utils" "time" ) func DealEmail(reportItem *english_report.Report, reportCode string, shareEmailId int) (err error, errMsg string) { defer func() { if err != nil { alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, ErrMsg: "+errMsg, 2) } }() emailItem := new(english_report_email.Email) userEmail, err := emailItem.GetById(shareEmailId) if err != nil && err != utils.ErrNoRow { errMsg = "获取客户邮箱信息失败, Err:" + err.Error() return } if userEmail == nil { return } // 更新报告邮箱pv(冗余) if err = reportItem.UpdatePvEmailByReportCode(reportCode); err != nil { errMsg = "更新报告邮箱PV失败, Err:" + err.Error() return } count, err := reportItem.GetUvEmailByReportIdAndEmailId(int(reportItem.Id), int(userEmail.Id)) if err != nil { errMsg = "获取邮箱阅读量失败, Err:" + err.Error() return } if count == 0 { if err = reportItem.UpdateUvEmailByReportCode(reportCode); err != nil { errMsg = "更新报告邮箱UV失败, Err:" + err.Error() return } } // 记录邮箱PV pv := &english_report_email.EmailPv{ ReportId: reportItem.Id, EmailId: userEmail.Id, CreateTime: time.Now().Local(), } if err = pv.Add(); err != nil { errMsg = "新增邮箱PV失败, Err: " + err.Error() return } // 更新阅读量 if err = emailItem.UpdateViewTotalById(userEmail.Id); err != nil { errMsg = "更新英文联系人阅读量失败, Err: " + err.Error() return } if userEmail.CompanyId > 0 { companyItem := new(english_company.Company) if err = companyItem.UpdateViewTotalByCompanyId(userEmail.CompanyId); err != nil { errMsg = "更新英文客户阅读量, Err: " + err.Error() return } } return } // CheckUserReportAuthByCompanyAndClassify 校验用户报告权限 func CheckUserReportAuthByCompanyAndClassify(companyId, classifyId int) (authOk bool, err error) { if companyId <= 0 || classifyId <= 0 { return } // 客户权限 hasPermissions := make([]*en_company_permission.EnCompanyPermission, 0) { cond := `en_company_id = ?` pars := make([]interface{}, 0) pars = append(pars, companyId) ob := new(en_company_permission.EnCompanyPermission) list, e := ob.GetList(cond, pars) if e != nil { err = fmt.Errorf("company permission GetList err: %s", e.Error()) return } hasPermissions = list } // 报告权限 reportPermissions := make([]*en_classify_permission.EnClassifyPermission, 0) { cond := `en_classify_id = ?` pars := make([]interface{}, 0) pars = append(pars, classifyId) ob := new(en_classify_permission.EnClassifyPermission) list, e := ob.GetList(cond, pars) if e != nil { err = fmt.Errorf("classify permission GetList err: %s", e.Error()) return } reportPermissions = list } for _, r := range reportPermissions { for _, p := range hasPermissions { if r.EnPermissionId == p.EnPermissionId { authOk = true return } } } return }