123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- package roadshow
- import (
- "fmt"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/roadshow"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/utils"
- "strings"
- )
- // @Title 我的日历列表
- // @Description 我的日历列表接口
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} roadshow.CalendarListResp
- // @router /company/search [get]
- func (this *CalendarController) CompanySearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- KeyWord := this.GetString("KeyWord")
- if KeyWord == "" {
- br.Msg = "请输入搜索词!"
- return
- }
- KeyWord = "%" + KeyWord + "%"
- var groupId int
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- groupId = sysUser.GroupId
- } else {
- groupId = -1
- }
- list, err := roadshow.CompanySearchV2(sysUser.AdminId, groupId, KeyWord, sysUser.RoleTypeCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "搜索客户失败!"
- br.ErrMsg = "搜索客户失败!Err:" + err.Error()
- return
- }
- if list == nil {
- list = make([]*roadshow.CompanySearchView, 0)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // CompanyDetail
- // @Title 我的日历列表
- // @Description 我的日历列表接口
- // @Param CompanyId query int true "公司id"
- // @Param EnglishCompany query int true "是否为英文客户"
- // @Param CompanyType query string true "客户类型:'ficc','权益',传空默认为ficc,"
- // @Param RsReportRecordId query int true "路演统计Id"
- // @Success 200 {object} roadshow.CompanyDetailView
- // @router /company/detail [get]
- func (this *CalendarController) CompanyDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误!"
- return
- }
- englishCompany, _ := this.GetInt("EnglishCompany")
- companyType := this.GetString("CompanyType")
- rsReportRecordId, _ := this.GetInt("RsReportRecordId")
- productId := services.GetProductId(sysUser.RoleTypeCode)
- if productId == 0 {
- productId = 1
- }
- if companyType == utils.COMPANY_CLASSIFY_RAI {
- productId = 2
- }
- detailView := new(roadshow.CompanyDetailView)
- if englishCompany == 0 {
- var companyStatus string
- var permissionName string
- companyProductItem, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "该客户已被删除"
- return
- }
- br.Msg = "搜索客户失败!"
- br.ErrMsg = "搜索客户失败!Err:" + err.Error()
- return
- }
- if rsReportRecordId > 0 {
- rsReportRecordItem, err := roadshow.GetRsReportRecordDetailByRsReportRecordId(rsReportRecordId)
- if err != nil {
- br.Msg = "路演信息不存在!"
- br.ErrMsg = "路演信息不存在!Err:" + err.Error()
- return
- }
- companyStatus = rsReportRecordItem.CompanyStatus
- permissionName = rsReportRecordItem.PermissionName
- } else {
- permissionList, err := company.GetCompanyProductReportPermissionList(companyId, productId)
- if err != nil {
- br.Msg = "搜索客户权限失败!"
- br.ErrMsg = "搜索客户权限失败!Err:" + err.Error()
- return
- }
- var permissionArr []string
- for _, v := range permissionList {
- permissionArr = append(permissionArr, v.PermissionName)
- }
- companyStatus = companyProductItem.Status
- permissionName = strings.Join(permissionArr, "/")
- }
- detailView.CompanyId = companyProductItem.CompanyId
- detailView.CompanyName = companyProductItem.CompanyName
- detailView.Status = companyStatus
- detailView.IndustryId = companyProductItem.IndustryId
- detailView.IndustryName = companyProductItem.IndustryName
- //detailView.PermissionName = strings.Join(permissionArr, "/")
- detailView.PermissionName = permissionName
- detailView.ReportReadTotal = companyProductItem.ViewTotal //ficc报告-累计阅读次数
- if companyType == utils.COMPANY_CLASSIFY_RAI { //权益互动统计
- companyItem, err := company.GetCompanyById(companyId)
- if err != nil {
- br.Msg = "查找客户失败"
- br.ErrMsg = "查找客户失败,Err:" + err.Error()
- return
- }
- detailView.ReportReadTotal = companyItem.InteractionNum
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = detailView
- return
- }
- // 英文客户
- enItem, e := models.GetEnglishCompanyById(companyId)
- if e != nil {
- br.Msg = "搜索英文客户失败!"
- br.ErrMsg = "获取英文客户详情失败!Err:" + e.Error()
- return
- }
- detailView.CompanyId = enItem.CompanyId
- detailView.CompanyName = enItem.CompanyName
- detailView.Status = "正常"
- detailView.EnglishCompany = 1
- detailView.EnglishCountry = enItem.Country
- detailView.EnglishViewTotal = enItem.ViewTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = detailView
- }
- //func init() {
- // init16_0()
- //}
- func init16_0() {
- var condition string
- var pars []interface{}
- condition = ` AND a.company_id > 0 `
- list, err := roadshow.GetRsReportRecordList(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- var companyIds []int
- mapcompanyIds := make(map[int]bool)
- for _, v := range list {
- if mapcompanyIds[v.CompanyId] {
- continue
- }
- companyIds = append(companyIds, v.CompanyId)
- mapcompanyIds[v.CompanyId] = true
- }
- mapPermissionNameFicc := make(map[int][]string)
- mapPermissionNameRai := make(map[int][]string)
- listPermissionNameFicc, errFicc := company.GetCompanyProductReportPermissionListInit16_0(companyIds, 1) // FICC权限信息
- if errFicc != nil {
- err = errFicc
- return
- }
- mapPermissionArrFicc := make(map[string]bool)
- for _, v := range listPermissionNameFicc {
- if mapPermissionArrFicc[fmt.Sprint(v.CompanyId, v.PermissionName)] || v.PermissionName == "" {
- continue
- }
- mapPermissionNameFicc[v.CompanyId] = append(mapPermissionNameFicc[v.CompanyId], v.PermissionName)
- mapPermissionArrFicc[fmt.Sprint(v.CompanyId, v.PermissionName)] = true
- }
- listPermissionNameRai, errRai := company.GetCompanyProductReportPermissionListInit16_0(companyIds, 2) // 权益权限信息
- if errRai != nil {
- err = errRai
- return
- }
- mapPermissionArrRai := make(map[string]bool)
- for _, v := range listPermissionNameRai {
- if mapPermissionArrRai[fmt.Sprint(v.CompanyId, v.PermissionName)] || v.PermissionName == "" {
- continue
- }
- mapPermissionNameRai[v.CompanyId] = append(mapPermissionNameRai[v.CompanyId], v.PermissionName)
- mapPermissionArrRai[fmt.Sprint(v.CompanyId, v.PermissionName)] = true
- }
- adminAll, err := system.GetAdminList()
- if err != nil {
- return
- }
- //adminMap := make(map[int]*system.AdminView)
- mapRaiSllerId := make(map[int]bool) // 是否为权益销售
- for _, v := range adminAll {
- //adminMap[v.AdminId] = v
- if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- mapRaiSllerId[v.AdminId] = true
- }
- }
- var updateItems []*roadshow.RsReportRecord
- for _, v := range list {
- item := new(roadshow.RsReportRecord)
- item.RsReportRecordId = v.RsReportRecordId
- if mapRaiSllerId[v.SellerId] {
- if len(mapPermissionNameRai[v.CompanyId]) > 0 {
- item.PermissionName = strings.Join(mapPermissionNameRai[v.CompanyId], "/")
- }
- } else {
- if len(mapPermissionNameFicc[v.CompanyId]) > 0 {
- item.PermissionName = strings.Join(mapPermissionNameFicc[v.CompanyId], "/")
- }
- }
- updateItems = append(updateItems, item)
- }
- fmt.Println(len(updateItems))
- err = roadshow.UpdateRsReportRecordPermissionMulti(updateItems)
- fmt.Println(err)
- return
- }
|