package cygx import ( "encoding/json" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "github.com/tealeg/xlsx" "hongze/hz_crm_api/controllers" "hongze/hz_crm_api/models" "hongze/hz_crm_api/models/cygx" "hongze/hz_crm_api/models/system" "hongze/hz_crm_api/services" cygxService "hongze/hz_crm_api/services/cygx" "hongze/hz_crm_api/utils" "html/template" "os" "path/filepath" "strconv" "strings" "time" ) // 活动 type ActivitySignupCoAntroller struct { controllers.BaseAuthController } // @Title 报名管理列表 // @Description 获取报名管理列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param ChartPermissionId query string false "行业id" // @Param ActivityTypeId query string false "活动类型id 多个用 , 隔开列如: 1,2" // @Param StartDate query string false "开始时间 ,列如2021-03-06 " // @Param EndDate query string false "结束时间,列如2021-03-06 " // @Param KeyWord query string false "搜索关键词" // @Param SearchType query int true "筛选类型 1专家/分析师电话会、2专家/分析师线下沙龙 、3公司调研/、4C类电话会、5买方线下交流" // @Param ActiveState query int false "发布状态 ,1未开始、2进行中、3已结束 ,默认1未开始" // @Param PublishStatus query int false "发布状态 ,0未发布,1已发布,3已取消,传2查询所有" // @Param IsResearch query bool true "是否为研选" // @Success 200 {object} cygx.GetCygxSignupListRep // @router /activitySignup/list [get] func (this *ActivitySignupCoAntroller) SignupList() { 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" return } pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") chartPermissionId, _ := this.GetInt("ChartPermissionId") ActivityTypeId := this.GetString("ActivityTypeId") startDate := this.GetString("StartDate") endDate := this.GetString("EndDate") keyWord := this.GetString("KeyWord") activeState, _ := this.GetInt("ActiveState") searchType, _ := this.GetInt("SearchType") publishStatus, _ := this.GetInt("PublishStatus") isResearch, _ := this.GetBool("IsResearch", false) // 是否为研选 查研观向11.0 (研选活动独立显示) if activeState == 0 { activeState = 1 } var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} if keyWord != "" { template.HTMLEscapeString(keyWord) keyWord = "%" + keyWord + "%" condition += ` AND (art.activity_name LIKE ? ) ` pars = append(pars, keyWord) } condition += ` AND art.active_state = ? ` pars = append(pars, activeState) if ActivityTypeId == "" { if searchType == 5 { condition += ` AND art.activity_type_id IN (8) ` } else if searchType == 4 { condition += ` AND art.activity_type_id IN (7) ` } else if searchType == 3 { condition += ` AND art.activity_type_id IN (3,4) ` } else if searchType == 2 { condition += ` AND art.activity_type_id IN (5,6) ` } else { condition += ` AND art.activity_type_id IN (1,2) ` //默认 } } if ActivityTypeId != "" { condition += ` AND art.activity_type_id IN (` + ActivityTypeId + `) ` } if isResearch { chartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN } else { condition += ` AND art.chart_permission_id != '` + strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) + `'` } //行业名称 if chartPermissionId > 0 { condition += ` AND art.chart_permission_id = '` + strconv.Itoa(chartPermissionId) + `'` } if startDate != "" { condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'" } if endDate != "" { condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'" } if publishStatus == 0 { condition += ` AND art.publish_status = 0 AND art.is_cancel = 0 ` } else if publishStatus == 1 { condition += ` AND art.publish_status = 1 ` } else if publishStatus == 3 { condition += ` AND art.publish_status = 0 AND art.is_cancel = 1 ` } //本组可见的活动对,非产品技术部 做权限限制 if sysUser.DepartmentId != 3 { conditionPermission, err := cygxService.GetAdminActivityPermission(sysUser, condition) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminActivityPermission Err:" + err.Error() return } condition += ` AND art.visible_range != 1 ` condition += conditionPermission pars = append(pars, pars) } //condition += ` AND a.publish_status = 1 ` total, err := cygx.GetCygxSignupCount(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if activeState == 3 { condition += ` ORDER BY art.activity_time DESC ` } else { condition += ` ORDER BY art.activity_time ASC ` } list, errList := cygx.GetCygxSignupListAll(condition, pars, startSize, pageSize) if errList != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errList.Error() return } var activityIds string for k, v := range list { if v.ChartPermissionNames != "" { list[k].ChartPermissionName = v.ChartPermissionNames } //if v.IsHideAppointment == 0 { // list[k].IsShowAppointment = cygxService.IsShowAppointmentByadminSet(v.IsCanAppointmentMinutes) //} activityIds += strconv.Itoa(v.ActivityId) + "," if v.ChartPermissionNameDeputy != "" && v.ChartPermissionNameDeputy != v.ChartPermissionName && v.YidongActivityId != "" { v.ChartPermissionName = v.ChartPermissionNameDeputy // 易董同步过来的活动展示副权限 v11.0 } } activityIds = strings.TrimRight(activityIds, ",") mapIndustrial := make(map[int]string) mapSubject := make(map[string]string) if activityIds != "" { industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetIndustrialActivityGroupListByactivityIds Err:" + err.Error() return } subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetSubjectActivityGroupListByactivityIds Err:" + err.Error() return } //合并活动对应的多个标的 for _, v := range subjectList { mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/" } //活动对应的产业 for _, v := range industrialList { var labelSubject string labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] if labelSubject != "" { mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + "," } else { mapIndustrial[v.ActivityId] += v.IndustryName + "," } } } for k, v := range list { if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" { list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], ",") } if v.IsCancel == 1 { v.PublishStatus = 3 } if v.YidongActivityId != "" { list[k].ActivityTypeName += utils.YI_DONG_NAME list[k].LimitPeopleNum = 10000 // 前端根据这个字段是否大于0来处理是新增报名还是预约外呼 } if v.IsYidongConduct == 1 { v.ActivityTypeName += utils.YI_DONG_NAME_TWO } if v.IsCanAppointmentMinutes == 1 { v.IsShowAppointment = true } } if len(list) == 0 { list = make([]*cygx.CygxSignupList, 0) } page := paging.GetPaging(currentIndex, pageSize, total) resp := new(cygx.GetCygxSignupListRep) resp.List = list resp.Paging = page br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 几种类型报名详情列表 // @Description 获取几种类型报名详情列表接口 // @Param ActivityId query int true "活动ID" // @Success 200 {object} cygx.GetAppointmentListRep // @router /activitySignup/appointmentList [get] func (this *ActivitySignupCoAntroller) AppointmentList() { 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" return } activityId, _ := this.GetInt("ActivityId") if activityId < 1 { br.Msg = "活动不存在" return } activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } memberType := "Admin" sqlStr := ` AND s.do_fail_type = 0 ` totalStr := sqlStr list, err := cygx.GetCygxAppointmentList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //根据公司ID获取对应销售 var companyIds []int for _, v := range list { companyIds = append(companyIds, v.CompanyId) } sellNameMap := services.GetSellNameMapByCompanyIds(companyIds) totalStr += " AND s.company_id != 16 " total, errtotal := cygx.GetCygxAppointmentCount(activityId, totalStr) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error() return } companyIdsPower, err := cygxService.GetAdminLookUserCompanyIds(sysUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIdsPower { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) ` myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, sqlStr) if errmyTotal != nil { br.Msg = "获取失败" br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error() return } for k, v := range list { list[k].SellerName = sellNameMap[v.CompanyId] } respList := new(cygx.GetAppointmentListRep) //销售查看自己客户,销售组长查看组员 if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 || activityInfo.IsYidongConduct == 1) { mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error() return } for _, v := range list { if _, ok := mapMobile[v.Mobile]; ok { respList.List = append(respList.List, v) } } if adminInfo.RoleTypeCode == "rai_group" { //组长查看本组所有组员 memberType = "GroupLeader" } else { //组员查看自己 memberType = "Sale" } } else { respList.List = list } if len(respList.List) == 0 { respList.List = make([]*cygx.CygxAppointmentList, 0) } respList.Total = total respList.MyTotal = myTotal respList.ActivityId = activityId respList.IsLimitPeople = activityInfo.IsLimitPeople respList.MemberType = memberType respList.IsResearchPoints = activityInfo.IsResearchPoints activityTypeId := activityInfo.ActivityTypeId //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "` if activityTypeId == 1 || activityTypeId == 2 { respList.ExcelType = "AppointmentCall" } else if activityTypeId == 5 || activityTypeId == 6 { respList.ExcelType = "ExpertSalon" } else if activityTypeId == 3 { respList.ExcelType = "Teleconference" } else if activityTypeId == 4 { respList.ExcelType = "OfflineResearch" } else if activityTypeId == 7 { respList.ExcelType = "CClass" } if activityInfo.YidongActivityId != "" { respList.ExcelType = "YiDong" } respList.IsYidongConduct = activityInfo.IsYidongConduct br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = respList } // @Title 外呼人员列表 // @Description 获取外呼人员列表接口 // @Param KeyWord query string false "搜索关键词" // @Success 200 {object} cygx.GetOutboundPersonnelListRep // @router /activitySignup/userList [get] func (this *ActivitySignupCoAntroller) OutboundPersonnelList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() keyWord := this.GetString("KeyWord") sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } if keyWord == "" { br.Msg = "请输入姓名" return } list, err := cygx.GetOutboundPersonnelList(keyWord) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } for k, v := range list { if len(v.Mobile) > 7 { list[k].Mobile = v.Mobile[0:3] + "****" + v.Mobile[7:] } } resp := new(cygx.GetOutboundPersonnelListRep) resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 新增外呼人员 // @Description 新增外呼人员接口 // @Param request body cygx.AddMeetingReminderReq true "type json string" // @Success 200 操作成功 // @router /activitySignup/addUser [post] func (this *ActivitySignupCoAntroller) AddUser() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.AddMeetingReminderReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } var items []*cygx.CygxActivitySignup var itemsYidong []*cygx.YidongActivitySignup var itemsAppointment []*cygx.CygxActivityAppointment activityIds := req.ActivityIds uidList := req.List if activityIds == "" { br.Msg = "请选择活动" br.ErrMsg = "活动ID不能为空" return } activityIdList := strings.Split(activityIds, ",") var uids string for _, v := range uidList { uids += strconv.Itoa(v.UserId) + "," } uids = strings.TrimRight(uids, ",") for _, v := range uidList { uid := v.UserId wxUser, userErr := models.GetWxUserByUserId(uid) if userErr != nil { br.Msg = "编辑失败!查询用户信息失败" br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在" return } for _, vact := range activityIdList { activityId, _ := strconv.Atoi(vact) activityInfo, err := cygx.GetAddActivityInfoById(activityId) if err != nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } if activityInfo.YidongActivityId != "" { errMsg := cygxService.CheckYidongActivitySignupTime(activityInfo) if errMsg != "" { br.Msg = errMsg br.ErrMsg = errMsg + "Err:activityId:" + strconv.Itoa(activityId) return } } limitPeopleNum, _ := strconv.Atoi(activityInfo.LimitPeopleNum) //if limitPeopleNum > 0 { if AdminUser.RoleTypeCode != "admin" { //havePower := cygxService.CheckaddSignuUserPower(wxUser.CompanyId, activityId, activityInfo) havePower, err := cygxService.GetActivityDetailUserPower(wxUser, AdminUser, activityInfo) if err != nil { br.Msg = "用户权限校验失败!" br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId) return } if !havePower { br.Msg = "当前活动对该客户不可见,无法报名" br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId)) return } //} if activityInfo.IsLimitPeople == 1 { //获取这个活动已经报名的用户数量 totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId) if errSignup != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errSignup.Error() return } //获取这个活动中输入的这些用户的报名数量 totalThisUser, errThisUser := cygx.GetActivitySignupCountByThisUser(activityId, uids) if errThisUser != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errThisUser.Error() return } //如果是限制人数的就做报名人数限制判断 if activityInfo.IsLimitPeople == 1 { if limitPeopleNum < totalSignup+len(uidList)-totalThisUser { br.Msg = "新增失败,活动人数超限" br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ActivityName return } } } } total, errtotal := cygx.GetActivitySignupCount(uid, activityId) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errtotal.Error() return } if total == 0 { infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } item := new(cygx.CygxActivitySignup) item.UserId = infoUser.UserId item.RealName = infoUser.RealName item.SellerName = infoUser.SellerName item.ActivityId = activityId item.CreateTime = time.Now() item.Mobile = infoUser.Mobile item.Email = infoUser.Email item.CompanyId = infoUser.CompanyId item.CompanyName = infoUser.CompanyName item.Source = 2 //优先绑定用户修改过的外呼手机号 if infoUser.OutboundMobile != "" { item.OutboundMobile = infoUser.OutboundMobile if infoUser.OutboundCountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = infoUser.OutboundCountryCode } } else { item.OutboundMobile = infoUser.Mobile if infoUser.CountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = infoUser.CountryCode } } item.SignupType = 1 items = append(items, item) if activityInfo.YidongActivityId != "" { //测试环境下弘则下面的用户才收到消息 if utils.RunMode != "release" && item.CompanyId == 16 { itemYidong := new(cygx.YidongActivitySignup) itemYidong.YidongActivityId = activityInfo.YidongActivityId itemYidong.Mobile = item.Mobile itemYidong.RealName = item.RealName itemYidong.CompanyName = item.CompanyName itemYidong.CountryCode = item.CountryCode itemsYidong = append(itemsYidong, itemYidong) } } } if v.IsAppointment == 1 { //var isHideAppointment bool //if activityInfo.IsHideAppointment == 0 { // isHideAppointment = cygxService.IsShowAppointmentByadminSet(activityInfo.IsCanAppointmentMinutes) //} if activityInfo.IsCanAppointmentMinutes == 0 { br.Msg = "该活动无法预约纪要" br.ErrMsg = "该活动无法预约纪要,Err:" + activityInfo.ActivityName return } total, errtotal := cygx.GetUserCygxActivityAppointmentCount(uid, activityId) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errtotal.Error() return } //判断这个用户是否报名了,如果没有报名则写入报名数据 if total == 0 { infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } itemAppointment := new(cygx.CygxActivityAppointment) itemAppointment.UserId = infoUser.UserId itemAppointment.RealName = infoUser.RealName itemAppointment.SellerName = infoUser.SellerName itemAppointment.ActivityId = activityId itemAppointment.CreateTime = time.Now() itemAppointment.Mobile = infoUser.Mobile itemAppointment.Email = infoUser.Email itemAppointment.CompanyId = infoUser.CompanyId itemAppointment.CompanyName = infoUser.CompanyName itemAppointment.AdminId = AdminUser.AdminId itemAppointment.Source = 2 itemsAppointment = append(itemsAppointment, itemAppointment) } } } } mapYidongActivity := make(map[int]int) err = cygx.AddCygxActivitySignup(items, itemsAppointment, mapYidongActivity) if err != nil { br.Msg = "操作失败" br.ErrMsg = "新增用户失败,Err:" + err.Error() return } //如果有值就向易董推送后台添加的报名信息 if len(itemsYidong) > 0 { go cygxService.YidongActivityUserSingnUp(itemsYidong) } //添加操作日志记录 br.Ret = 200 br.Success = true br.Msg = "操作成功" br.IsAddLog = true } // @Title 报名失败详情列表 // @Description 获取沙龙报名失败详情列表接口 // @Param ActivityId query int true "活动ID" // @Success 200 {object} cygx.GetFailSignupListRep // @router /activitySignup/salonFailSignupList [get] func (this *ActivitySignupCoAntroller) SalonFailSignupList() { 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" return } respList := new(cygx.GetFailSignupListRep) activityId, _ := this.GetInt("ActivityId") activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } memberType := "Admin" sqlStr := "" sqlStr += ` AND s.fail_type >0 ` list, err := cygx.GetFailSignupList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //根据公司ID获取对应销售 var sellerCompanyIds []int for _, v := range list { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds) sqlStrtotal := ` AND s.fail_type >0 ` total, errtotal := cygx.GetCygxAppointmentCount(activityId, sqlStrtotal) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error() return } //权益申请销售只能看到自己名下的客户的申请 查研观向11.1 companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIds { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } myTotalsqlStr := ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) AND s.fail_type >0 ` myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, myTotalsqlStr) if errmyTotal != nil { br.Msg = "获取失败" br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error() return } if activityInfo.IsLimitPeople > 0 { //获取这个活动已经报名的用户数量 totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId) if errSignup != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取数量失败,Err:" + errSignup.Error() return } limitPeopleNum, err := strconv.Atoi(activityInfo.LimitPeopleNum) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "数据转换失败,Err:" + err.Error() return } //如果报名人数不小于限制人数,则报名人数已满 if limitPeopleNum <= totalSignup { respList.IsFull = true } } for k, v := range list { list[k].SellerName = sellNameMap[v.CompanyId] if v.DoFailType == 0 { list[k].SalonOperation = true list[k].CallOperation = v.SignupType } else { list[k].CallOperation = 3 } } //销售查看自己客户,销售组长查看组员 if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) { mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error() return } for _, v := range list { if _, ok := mapMobile[v.Mobile]; ok { respList.List = append(respList.List, v) } } if adminInfo.RoleTypeCode == "rai_group" { //组长查看本组所有组员 memberType = "GroupLeader" } else { //组员查看自己 memberType = "Sale" } } else { respList.List = list } if len(respList.List) == 0 { respList.List = make([]*cygx.FailSignupListRep, 0) } respList.Total = total respList.MyTotal = myTotal respList.IsLimitPeople = activityInfo.IsLimitPeople respList.MemberType = memberType activityTypeId := activityInfo.ActivityTypeId if activityTypeId == 1 || activityTypeId == 2 { respList.ExcelType = "AppointmentCall" } else if activityTypeId == 5 || activityTypeId == 6 { respList.ExcelType = "ExpertSalon" } else if activityTypeId == 3 { respList.ExcelType = "Teleconference" } else if activityTypeId == 4 { respList.ExcelType = "OfflineResearch" } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = respList } // @Title 沙龙限制报名、加入报名 // @Description 修改沙龙限制报名、加入报名接口 // @Param request body cygx.SignupId true "type json string" // @Success 200 操作成功 // @router /activitySignup/salonSignupEdit [post] func (this *ActivitySignupCoAntroller) SalonSignupEdit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.SignupId err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } id := req.Id total, err := cygx.GetCygxSignupCountFile(id) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if total == 0 { br.Msg = "获取报名信息失败" br.ErrMsg = "获取失败,id:" + strconv.Itoa(id) return } detail, err := cygx.GetCygxSignupDetailById(id) if err != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + err.Error() return } newIsAdminAddSignup := 0 if detail.IsAdminAddSignup == 1 { newIsAdminAddSignup = 0 } else { newIsAdminAddSignup = 1 activityInfo, err := cygx.GetAddActivityInfoById(detail.ActivityId) if err != nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(detail.ActivityId) return } if activityInfo.IsLimitPeople > 0 { //获取这个活动已经报名的用户数量 totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(detail.ActivityId) if errSignup != nil { br.Msg = "操作失败" br.ErrMsg = "获取数量失败,Err:" + errSignup.Error() return } limitPeopleNum, err := strconv.Atoi(activityInfo.LimitPeopleNum) if err != nil { br.Msg = "操作失败" br.ErrMsg = "数据转换失败,Err:" + err.Error() return } if limitPeopleNum <= totalSignup { br.Msg = "新增失败,活动人数超限" return } adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } //如果操作的不是管理员就做下面的限制 if adminInfo.Role != "admin" { activityId := detail.ActivityId //单机构两人限制 { totalSignupCompany, err := cygx.GetActivitySignupCompanyCount(activityId, detail.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取客户信息失败,Err:" + err.Error() return } if totalSignupCompany >= 2 { br.Msg = "新增失败,单机构最多2人报名同一活动。" br.ErrMsg = "新增失败,单机构最多2人报名同一活动。" + fmt.Sprint("activityId:", activityId, detail.Mobile) return } } //爽约限制 //{ // totalRestrict, err := cygx.GetUserRestrictCount(detail.Mobile) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取客户信息失败,Err:" + err.Error() // return // } // if totalRestrict >= 1 { // br.Msg = "新增失败," + detail.RealName + "爽约次数过多。" // br.ErrMsg = detail.RealName + "由于爽约次数过多,暂时被限制报名资格" // return // } //} } } } var doFailType int if newIsAdminAddSignup == 1 { doFailType = 0 } else { doFailType = detail.FailType } infoUser, err := cygx.GetUserAndCompanyNameList(detail.UserId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } item := new(cygx.CygxActivitySignup) item.UserId = infoUser.UserId item.RealName = infoUser.RealName item.SellerName = infoUser.SellerName item.ActivityId = detail.ActivityId item.CreateTime = time.Now() item.Mobile = infoUser.Mobile item.Email = infoUser.Email item.CompanyId = infoUser.CompanyId item.CompanyName = infoUser.CompanyName err = cygx.SalonSignupEdit(newIsAdminAddSignup, doFailType, id, item) if err != nil { br.Msg = "修改失败" br.ErrMsg = "修改失败 Err:" + err.Error() return } var itemsSendWxMsg []*cygx.CygxSignupUser itemsSendWxMsg = append(itemsSendWxMsg, &cygx.CygxSignupUser{UserId: infoUser.UserId, ActivityId: detail.ActivityId}) //销售或后台管理员给用户添加报名之后,进行模版消息推送 if doFailType == 0 { go cygxService.SendWxMsgWithCygxActivitySignUpBySell(itemsSendWxMsg) go services.SendWxCategoryMsgWithCygxActivitySignUpBySell(itemsSendWxMsg) } //添加操作日志记录 br.Ret = 200 br.Success = true br.Msg = "操作成功" br.IsAddLog = true } // @Title 公司调研电话会报名失败详情列表 // @Description 获取公司调研电话会报名失败详情列表接口 // @Param ActivityId query int true "活动ID" // @Success 200 {object} cygx.GetFailSignupListRep // @router /activitySignup/callFailSignupList [get] func (this *ActivitySignupCoAntroller) FailSignupList() { 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" return } activityId, _ := this.GetInt("ActivityId") activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } var list []*cygx.FailSignupListRep memberType := "Admin" var err error sqlStr := "" sqlStr += ` AND s.fail_type >0 ` listSeller, errSeller := cygx.GetFailSignupList(activityId, sqlStr) list = listSeller err = errSeller if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } total, errtotal := cygx.GetCygxAppointmentCount(activityId, "") if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error() return } //权益申请销售只能看到自己名下的客户的申请 查研观向11.1 companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIds { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } myTotalsqlStr := ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) AND s.fail_type >0 ` myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, myTotalsqlStr) if errmyTotal != nil { br.Msg = "获取失败" br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error() return } var listNew []*cygx.FailSignupListRep for k, v := range list { if k > 0 && list[k].Id == list[k-1].Id { list[k-1].SellerName = list[k-1].SellerName + "/" + v.SellerName } } for k, v := range list { if k > 0 && list[k].Id != list[k-1].Id { listNew = append(listNew, v) } if k == 0 && len(list) >= 2 && list[1].Id == list[0].Id { listNew = append(listNew, v) } } for k, v := range listNew { if v.IsAdminAddSignup == 0 { listNew[k].CallOperation = 3 } else { listNew[k].CallOperation = v.MeetingType } } respList := new(cygx.GetFailSignupListRep) //销售查看自己客户,销售组长查看组员 if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) { mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error() return } for _, v := range listNew { if _, ok := mapMobile[v.Mobile]; ok { respList.List = append(respList.List, v) } } if adminInfo.RoleTypeCode == "rai_group" { //组长查看本组所有组员 memberType = "GroupLeader" } else { //组员查看自己 memberType = "Sale" } } else { respList.List = listNew } if len(respList.List) == 0 { respList.List = make([]*cygx.FailSignupListRep, 0) } respList.List = listNew respList.Total = total respList.MyTotal = myTotal respList.IsLimitPeople = activityInfo.IsLimitPeople respList.MemberType = memberType activityTypeId := activityInfo.ActivityTypeId //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "` if activityTypeId == 1 || activityTypeId == 2 { respList.ExcelType = "AppointmentCall" } else if activityTypeId == 5 || activityTypeId == 6 { respList.ExcelType = "ExpertSalon" } else if activityTypeId == 3 { respList.ExcelType = "Teleconference" } else if activityTypeId == 4 { respList.ExcelType = "OfflineResearch" } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = respList } // @Title 修改公司调研电话会限制报名、预约外呼、自主拨入 // @Description 修改公司调研电话会限制报名、预约外呼、自主拨入接口 // @Param request body cygx.SignupIdCall true "type json string" // @Success 200 操作成功 // @router /activitySignup/callSignupEdit [post] func (this *ActivitySignupCoAntroller) CallSignupEdit() { 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" return } var req cygx.SignupIdCall err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } id := req.Id operationStatus := req.OperationStatus total, err := cygx.GetCygxSignupCountFile(id) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if total == 0 { br.Msg = "获取报名信息失败" br.ErrMsg = "获取失败,id:" + strconv.Itoa(id) return } detail, err := cygx.GetCygxSignupDetailById(id) if err != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + err.Error() return } uid := detail.UserId var doFailType int infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } item := new(cygx.CygxMySchedule) item.UserId = infoUser.UserId item.CreateTime = time.Now() item.Mobile = infoUser.Mobile item.ActivityId = detail.ActivityId item.Email = infoUser.Email item.CompanyId = infoUser.CompanyId item.CompanyName = infoUser.CompanyName if operationStatus == 1 { doFailType = 0 } else { doFailType = detail.FailType } var errEdit error if operationStatus == 3 { err3 := cygx.CallSignupEditByStatus3(id, doFailType, item) errEdit = err3 } else { err1_2 := cygx.CallSignupEditByStatus1_2(operationStatus, id, item) errEdit = err1_2 } if errEdit != nil { br.Msg = "修改失败" br.ErrMsg = "修改失败 Err:" + errEdit.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" br.IsAddLog = true } // @Title 预约外呼详情、公司调研电话会excel表格下载 // @Description 获取预约外呼详情、公司调研电话会excel表格下载接口 // @Param ActivityId query int true "活动ID" // @Success 200 导出成功 // @router /activitySignup/callExport [get] func (this *ActivitySignupCoAntroller) CallExport() { 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" return } activityId, _ := this.GetInt("ActivityId") activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } //var err error sqlStr := " " if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) { //权益申请销售只能看到自己名下的客户的申请 查研观向11.1 companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIds { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) ` } //公司调研电话会下载全部 if activityInfo.ActivityTypeId != 3 { sqlStr += " AND s.signup_type = 1 " } list, err := cygx.GetCygxAppointmentList(activityId, sqlStr) //err = errSeller if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //会议提醒 listReminder, err := cygx.GetCygxActivityMeetingReminderList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //预约纪要 listSummary, err := cygx.GetCygxAppointmentSummaryList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //根据公司ID获取对应销售 var sellerCompanyIds []int for _, v := range list { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } for _, v := range listReminder { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } for _, v := range listSummary { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds) //创建excel dir, err := os.Executable() exPath := filepath.Dir(dir) downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx" xlsxFile := xlsx.NewFile() if err != nil { br.Msg = "生成文件失败" br.ErrMsg = "生成文件失败" return } style := xlsx.NewStyle() alignment := xlsx.Alignment{ Horizontal: "center", Vertical: "center", WrapText: true, } style.Alignment = alignment style.ApplyAlignment = true for pidIndex := 0; pidIndex <= 2; pidIndex++ { var sheetName string var listDate []*cygx.CygxAppointmentList if pidIndex == 0 { if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 { sheetName = "预约外呼" } else { sheetName = "名单" } listDate = list } else if pidIndex == 1 { sheetName = "会议提醒" listDate = listReminder } else { sheetName = "预约纪要" listDate = listSummary } sheet, err := xlsxFile.AddSheet(sheetName) if err != nil { br.Msg = "新增Sheet失败" br.ErrMsg = "新增Sheet失败,Err:" + err.Error() return } //标头 if pidIndex == 0 { //如果是公司调研电话会就下载邮箱 if activityInfo.ActivityTypeId == 3 { rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "外呼号码" cellC := rowTitle.AddCell() cellC.Value = "国际代码" cellD := rowTitle.AddCell() cellD.Value = "邮箱" cellE := rowTitle.AddCell() cellE.Value = "公司名称" cellF := rowTitle.AddCell() cellF.Value = "所属销售" for _, item := range listDate { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.OutboundMobile cellC := row.AddCell() if item.CountryCode == "" { cellC.Value = "86" } else { cellC.Value = item.CountryCode } cellD := row.AddCell() cellD.Value = item.Email cellE := row.AddCell() cellE.Value = item.CompanyName cellF := row.AddCell() cellF.Value = sellNameMap[item.CompanyId] } } else { rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "外呼号码" cellC := rowTitle.AddCell() cellC.Value = "国际代码" cellD := rowTitle.AddCell() cellD.Value = "公司名称" cellE := rowTitle.AddCell() cellE.Value = "所属销售" for _, item := range listDate { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.OutboundMobile cellC := row.AddCell() if item.CountryCode == "" { cellC.Value = "86" } else { cellC.Value = item.CountryCode } cellD := row.AddCell() cellD.Value = item.CompanyName cellE := row.AddCell() cellE.Value = sellNameMap[item.CompanyId] } } } else { rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "公司名称" cellC := rowTitle.AddCell() cellC.Value = "所属销售" for _, item := range listDate { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.CompanyName cellC := row.AddCell() cellC.Value = sellNameMap[item.CompanyId] } } } err = xlsxFile.Save(downLoadnFilePath) if err != nil { br.Msg = "保存文件失败" br.ErrMsg = "保存文件失败" return } //randStr := time.Now().Format(utils.FormatDateTimeUnSpace) downloadFileName := activityInfo.ActivityName + ".xlsx" this.Ctx.Output.Download(downLoadnFilePath, downloadFileName) defer func() { os.Remove(downLoadnFilePath) }() br.Success = true br.Ret = 200 br.IsAddLog = true } // @Title 公司线下调研、报名excel表格下载 // @Description 获取公司线下调研、报名excel表格下载接口 // @Param ActivityId query int true "活动ID" // @Param ExcelType query int true "下载方式 0:全部名单、1:预约外呼名单、2:自主入会(自主拨入)名单" // @Success 200 导出成功 // @router /activitySignup/signupFailExport [get] func (this *ActivitySignupCoAntroller) SignupFailExport() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } activityId, _ := this.GetInt("ActivityId") excelType, _ := this.GetInt("ExcelType") //signupType := this.GetString("SignupType") activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } sqlStr := "" if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 || activityInfo.IsYidongConduct == 1) { //权益申请销售只能看到自己名下的客户的申请 查研观向11.1 companyIds, err := cygxService.GetAdminLookUserCompanyIds(AdminUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIds { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `)` } sqlStrOther := sqlStr var listReminder []*cygx.CygxAppointmentList var summaryList []*cygx.CygxAppointmentList var err error //消息提醒 listReminder, err = cygx.GetCygxActivityMeetingReminderList(activityId, sqlStrOther) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //预约纪要 summaryList, err = cygx.GetCygxAppointmentSummaryList(activityId, sqlStrOther) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if excelType == 1 { sqlStr += ` AND s.signup_type = 1 ` } else if excelType == 2 { sqlStr += ` AND s.signup_type IN (2,4) ` } //} list, err := cygx.GetCygxAppointmentList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //根据公司ID获取对应销售 var sellerCompanyIds []int for _, v := range listReminder { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } for _, v := range summaryList { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } for _, v := range list { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds) //创建excel dir, err := os.Executable() exPath := filepath.Dir(dir) downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx" xlsxFile := xlsx.NewFile() if err != nil { br.Msg = "生成文件失败" br.ErrMsg = "生成文件失败" return } style := xlsx.NewStyle() alignment := xlsx.Alignment{ Horizontal: "center", Vertical: "center", WrapText: true, } style.Alignment = alignment style.ApplyAlignment = true for pidIndex := 0; pidIndex <= 2; pidIndex++ { //只做专家电话会,分析师电话会的多Sheel下载 if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 2 { if pidIndex > 0 { continue } } var sheetName string var listDate []*cygx.CygxAppointmentList if pidIndex == 0 { sheetName = "报名名单" listDate = list } else if pidIndex == 1 { sheetName = "消息提醒名单" listDate = listReminder } else if pidIndex == 2 { sheetName = "预约纪要名单" listDate = summaryList } sheet, err := xlsxFile.AddSheet(sheetName) if err != nil { br.Msg = "新增Sheet失败" br.ErrMsg = "新增Sheet失败,Err:" + err.Error() return } //标头 if pidIndex == 0 { if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 || (activityInfo.ActivityTypeId == 7 && activityInfo.IsYidongConduct == 1) { rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "外呼号码" cellC := rowTitle.AddCell() cellC.Value = "国际代码" cellD := rowTitle.AddCell() cellD.Value = "邮箱" cellE := rowTitle.AddCell() cellE.Value = "公司名称" cellF := rowTitle.AddCell() cellF.Value = "所属销售" for _, item := range listDate { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.OutboundMobile cellC := row.AddCell() cellC.Value = item.CountryCode cellD := row.AddCell() cellD.Value = item.Email cellE := row.AddCell() cellE.Value = item.CompanyName cellF := row.AddCell() cellF.Value = sellNameMap[item.CompanyId] } } else { rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "公司名称" cellC := rowTitle.AddCell() cellC.Value = "所属销售" for _, item := range listDate { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.CompanyName cellC := row.AddCell() cellC.Value = sellNameMap[item.CompanyId] } } } else { rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "公司名称" cellC := rowTitle.AddCell() cellC.Value = "所属销售" for _, item := range listDate { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.CompanyName cellC := row.AddCell() cellC.Value = sellNameMap[item.CompanyId] } } } err = xlsxFile.Save(downLoadnFilePath) if err != nil { br.Msg = "保存文件失败" br.ErrMsg = "保存文件失败" return } //randStr := time.Now().Format(utils.FormatDateTimeUnSpace) downloadFileName := activityInfo.ActivityName + ".xlsx" this.Ctx.Output.Download(downLoadnFilePath, downloadFileName) defer func() { os.Remove(downLoadnFilePath) }() //添加操作日志记录 br.Success = true br.Ret = 200 br.Msg = "导出成功" br.IsAddLog = true } // @Title 修改外呼号码 // @Description 修改外呼号码接口 // @Param request body cygx.OutboundMobileEditResp true "type json string" // @Success 200 操作成功 // @router /activitySignup/outboundMobileEdit [post] func (this *ActivitySignupCoAntroller) OutboundMobileEdit() { 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" return } var req cygx.OutboundMobileEditResp err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } id := req.Id outboundMobile := req.OutboundMobile countryCode := req.CountryCode total, err := cygx.GetCygxSignupCountFile(id) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if total == 0 { br.Msg = "获取报名信息失败" br.ErrMsg = "获取失败,id:" + strconv.Itoa(id) return } err = cygx.OutboundMobileEdit(id, outboundMobile, countryCode) if err != nil { br.Msg = "修改失败" br.ErrMsg = "修改失败 Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" br.IsAddLog = true } // @Title 单条报名详情 // @Description 获取单条报名详情接口 // @Param Id query int true "报名ID" // @Success Ret=200 {object} cygx.CygxActivitySignup // @router /activitySignup/signupDetail [get] func (this *ActivitySignupCoAntroller) SignupDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } id, _ := this.GetInt("Id") if id < 1 { br.Msg = "请输入报名ID" return } detail, err := cygx.GetActivitySignupInfoById(id) if err != nil { br.Msg = "报名信息不存在" br.ErrMsg = "报名信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(id) return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = detail } // @Title 新增报名人员 // @Description 新增报名人员接口 // @Param request body cygx.AddMeetingReminderReq true "type json string" // @Success 200 操作成功 // @router /activitySignup/addSignuUser [post] func (this *ActivitySignupCoAntroller) AddSignuUser() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.AddMeetingReminderReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } adminInfo, err := system.GetSysUserById(AdminUser.AdminId) if err != nil { br.Msg = "添加失败" br.ErrMsg = "获取管理员信息失败,Err:" + err.Error() return } var items []*cygx.CygxActivitySignup var itemsYidong []*cygx.YidongActivitySignup var itemsAppointment []*cygx.CygxActivityAppointment mapYidongActivity := make(map[int]int) activityIds := req.ActivityIds uidList := req.List if activityIds == "" { br.Msg = "请选择活动" br.ErrMsg = "活动ID不能为空" return } //获取已经报名成功的用户,给没有成功的或者没有报名的用户发送模版消息 mapSignupSuccess := make(map[string]int) var itemsSendWxMsg []*cygx.CygxSignupUser var condition string var pars []interface{} condition = ` AND do_fail_type = 0 AND activity_id IN (` + activityIds + `) ` listSignup, err := cygx.GetActivitySignupList(condition, pars) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "添加报名失败" br.ErrMsg = "添加报名失败,Err:GetActivitySignupList:" + err.Error() } for _, v := range listSignup { mapSignupSuccess[fmt.Sprint("UID_", v.UserId, "AID_", v.ActivityId)] = v.ActivityId } activityIdList := strings.Split(activityIds, ",") var uids string for _, v := range uidList { uids += strconv.Itoa(v.UserId) + "," } uids = strings.TrimRight(uids, ",") mapCompanyPeople := make(map[string]int) checkIsYidongConduct := make(map[string]int) for _, v := range uidList { uid := v.UserId wxUser, userErr := models.GetWxUserByUserId(uid) if userErr != nil { br.Msg = "编辑失败!查询用户信息失败" br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在" return } for _, vact := range activityIdList { activityId, _ := strconv.Atoi(vact) activityInfo, err := cygx.GetAddActivityInfoById(activityId) if err != nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } // 如果是易董的办会,且不提供外呼,而且管理员还勾选了预约外呼,那么做判断 if activityInfo.IsYidongConduct == 1 && activityInfo.IsCanOutboundCall == 0 && v.SignupType == 1 { br.Msg = "此活动不提供外呼" br.ErrMsg = "此活动不提供外呼,Err:activityId:" + strconv.Itoa(activityId) return } //同时 勾选一个易懂办会,一个非易懂办会的活动 的判断 checkIsYidongConduct[strconv.Itoa(activityInfo.IsYidongConduct)] = activityInfo.IsYidongConduct if len(checkIsYidongConduct) > 1 { br.Msg = "活动类型不同,无法同时新增报名" br.ErrMsg = "活动类型不同,Err:activityIds:" + activityIds return } if activityInfo.YidongActivityId != "" { errMsg := cygxService.CheckYidongActivitySignupTime(activityInfo) if errMsg != "" { br.Msg = errMsg br.ErrMsg = errMsg + "Err:activityId:" + strconv.Itoa(activityId) return } mapYidongActivity[activityInfo.ActivityId] = activityInfo.ActivityId } activityTypeId := activityInfo.ActivityTypeId if adminInfo.RoleTypeCode != "admin" { havePower, err := cygxService.GetActivityDetailUserPower(wxUser, adminInfo, activityInfo) if err != nil { br.Msg = "用户权限校验失败!" br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId) return } if !havePower { br.Msg = "当前活动对该客户不可见,无法报名" br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId)) return } popupMsg, err := cygxService.CheckActivityUserAll(activityInfo, wxUser) if err != nil { br.Msg = "报名失败!" br.ErrMsg = "CheckActivityUserAll,Err:" + err.Error() return } if popupMsg != "" { br.Msg = fmt.Sprint("报名失败!用户:", wxUser.RealName, popupMsg) return } if activityInfo.YidongActivityId == "" { if activityTypeId == 1 || activityTypeId == 2 { resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式 if time.Now().After(resultTime.Add(-time.Minute * 60)) { br.Msg = "报名名单已发送至办会平台,请联系相关人员处理。" return } } } //弘则的不做校验 if activityInfo.IsLimitPeople == 1 && wxUser.CompanyId != utils.HZ_COMPANY_ID { //单机构两人限制 { sqlStr := ` AND s.do_fail_type = 0` listSignUp, err := cygx.GetCygxAppointmentList(activityId, sqlStr) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } for _, v := range listSignUp { mapCompanyPeople[fmt.Sprint("CID_", v.CompanyId, "AID_", activityId)]++ } mapCompanyPeople[fmt.Sprint("CID_", wxUser.CompanyId, "AID_", activityId)]++ if mapCompanyPeople[fmt.Sprint("CID_", wxUser.CompanyId, "AID_", activityId)] > 2 { br.Msg = "新增失败," + wxUser.RealName + "单机构2人限制。" br.ErrMsg = wxUser.RealName + "单机构2人限制" return } } //爽约限制 //{ // totalRestrict, err := cygx.GetUserRestrictCount(wxUser.Mobile) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取客户信息失败,Err:" + err.Error() // return // } // if totalRestrict >= 1 { // br.Msg = "新增失败," + wxUser.RealName + "爽约次数过多。" // br.ErrMsg = wxUser.RealName + "由于爽约次数过多,暂时被限制报名资格" // return // } //} } } limitPeopleNum, _ := strconv.Atoi(activityInfo.LimitPeopleNum) //获取这个活动已经报名的用户数量 totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId) if errSignup != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errSignup.Error() return } //获取这个活动中输入的这些用户的报名数量 totalThisUser, errThisUser := cygx.GetActivitySignupCountByThisUser(activityId, uids) if errThisUser != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errThisUser.Error() return } //如果是限制人数的就做报名人数限制判断 if activityInfo.IsLimitPeople == 1 { if limitPeopleNum < totalSignup+len(uidList)-totalThisUser { br.Msg = "新增失败,活动人数超限" br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ActivityName return } } total, errtotal := cygx.GetActivitySignupCount(uid, activityId) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errtotal.Error() return } //判断这个用户是否报名了,如果没有报名则写入报名数据 if total == 0 { infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } item := new(cygx.CygxActivitySignup) item.UserId = infoUser.UserId item.RealName = infoUser.RealName item.SellerName = infoUser.SellerName item.ActivityId = activityId item.CreateTime = time.Now() item.Mobile = infoUser.Mobile item.Mobile = infoUser.Mobile item.Email = infoUser.Email item.CompanyId = infoUser.CompanyId item.CompanyName = infoUser.CompanyName //优先绑定用户修改过的外呼手机号 if infoUser.OutboundMobile != "" { item.OutboundMobile = infoUser.OutboundMobile if infoUser.OutboundCountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = infoUser.OutboundCountryCode } } else { item.OutboundMobile = infoUser.Mobile if infoUser.CountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = infoUser.CountryCode } } //如果不填报名方式,则默认为我要报名这种方式 if v.SignupType == 0 { item.SignupType = 3 } else { item.SignupType = v.SignupType } item.Source = 2 items = append(items, item) if activityInfo.YidongActivityId != "" { itemYidong := new(cygx.YidongActivitySignup) itemYidong.YidongActivityId = activityInfo.YidongActivityId itemYidong.Mobile = item.Mobile itemYidong.RealName = item.RealName itemYidong.CompanyName = item.CompanyName itemYidong.CountryCode = item.CountryCode itemYidong.ActivityJoinType = activityInfo.ActivityJoinType itemsYidong = append(itemsYidong, itemYidong) } } if v.IsAppointment == 1 { total, errtotal := cygx.GetUserCygxActivityAppointmentCount(uid, activityId) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errtotal.Error() return } //var isHideAppointment bool //if activityInfo.IsCanAppointmentMinutes == 1 { // isHideAppointment = cygxService.IsShowAppointmentByadminSet(activityInfo.IsCanAppointmentMinutes) //} if activityInfo.IsCanAppointmentMinutes == 0 { br.Msg = "该活动无法预约纪要" br.ErrMsg = "该活动无法预约纪要,Err:" + activityInfo.ActivityName return } //判断这个用户是否报名了,如果没有报名则写入报名数据 if total == 0 { infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } itemAppointment := new(cygx.CygxActivityAppointment) itemAppointment.UserId = infoUser.UserId itemAppointment.RealName = infoUser.RealName itemAppointment.SellerName = infoUser.SellerName itemAppointment.ActivityId = activityId itemAppointment.CreateTime = time.Now() itemAppointment.Mobile = infoUser.Mobile itemAppointment.Email = infoUser.Email itemAppointment.CompanyId = infoUser.CompanyId itemAppointment.CompanyName = infoUser.CompanyName itemAppointment.Source = 2 itemAppointment.AdminId = adminInfo.AdminId itemsAppointment = append(itemsAppointment, itemAppointment) } } if mapSignupSuccess[fmt.Sprint("UID_", uid, "AID_", activityId)] == 0 { itemsSendWxMsg = append(itemsSendWxMsg, &cygx.CygxSignupUser{UserId: uid, ActivityId: activityId}) } } } //mapYidongActivity := make(map[int]int) err = cygx.AddCygxActivitySignup(items, itemsAppointment, mapYidongActivity) if err != nil { br.Msg = "操作失败" br.ErrMsg = "新增用户失败,Err:" + err.Error() return } //如果有值就向易董推送后台添加的报名信息 if len(itemsYidong) > 0 { go cygxService.YidongActivityUserSingnUp(itemsYidong) } //销售或后台管理员给用户添加报名之后,进行模版消息推送 if len(itemsSendWxMsg) > 0 { go cygxService.SendWxMsgWithCygxActivitySignUpBySell(itemsSendWxMsg) go services.SendWxCategoryMsgWithCygxActivitySignUpBySell(itemsSendWxMsg) } if len(items) > 0 { //1用户报名添加到处理研选扣点 for _, v := range items { time.Sleep(100 * time.Millisecond) // 添加0.1秒的延时 cygxService.YanXuanActivityPointsBillSignupAdd(v.ActivityId, v.UserId, adminInfo.AdminId) } go cygxService.AddctivitySignupDetailListByAdminSignup(req.ActivityIds) //已结束的活动,管理员手动添加报名,把信息写入到联系人列表参会信息中 } //添加操作日志记录 br.IsAddLog = true br.IsSendEmail = false br.Ret = 200 br.Success = true br.Msg = "操作成功" } // @Title 带问列表详情 // @Description 获取带问列表详情接口 // @Param ActivityId query int true "活动ID" // @Success 200 {object} cygx.ActivityHelpAskListResp // @router /activitySignup/askList [get] func (this *ActivitySignupCoAntroller) AskList() { 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" return } activityId, _ := this.GetInt("ActivityId") activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } list, err := cygx.GetActivityHelpAskList(activityId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } var userIds []string for _, v := range list { userIds = append(userIds, strconv.Itoa(v.UserId)) } // 查询留言相关的用户 var userOthers []*models.WxUser if len(userIds) > 0 { userOthers, err = models.GetWxUserListByUserIds(strings.Join(userIds, ",")) if err != nil { br.Msg = "查询留言用户出错" br.ErrMsg = "查询留言用户出错,Err:" + err.Error() return } } usersMapName := make(map[int]string) for _, v := range userOthers { usersMapName[int(v.UserId)] = v.RealName } for _, v := range list { v.RealName = usersMapName[v.UserId] } respist := new(cygx.ActivityHelpAskListResp) respist.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = respist } // @Title 带问详情excel表格下载 // @Description 带问详情excel表格下载接口 // @Param ActivityId query int true "活动ID" // @Success 200 导出成功 // @router /activitySignup/askListExport [get] func (this *ActivitySignupCoAntroller) AskListExport() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } activityId, _ := this.GetInt("ActivityId") activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } list, err := cygx.GetActivityHelpAskList(activityId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } var userIds []string for _, v := range list { userIds = append(userIds, strconv.Itoa(v.UserId)) } // 查询留言相关的用户 var userOthers []*models.WxUser if len(userIds) > 0 { userOthers, err = models.GetWxUserListByUserIds(strings.Join(userIds, ",")) if err != nil { br.Msg = "查询留言用户出错" br.ErrMsg = "查询留言用户出错,Err:" + err.Error() return } } usersMapName := make(map[int]string) for _, v := range userOthers { usersMapName[int(v.UserId)] = v.RealName } for _, v := range list { v.RealName = usersMapName[v.UserId] } //创建excel dir, err := os.Executable() exPath := filepath.Dir(dir) downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx" xlsxFile := xlsx.NewFile() if err != nil { br.Msg = "生成文件失败" br.ErrMsg = "生成文件失败" return } style := xlsx.NewStyle() alignment := xlsx.Alignment{ Horizontal: "center", Vertical: "center", WrapText: true, } style.Alignment = alignment style.ApplyAlignment = true sheet, err := xlsxFile.AddSheet("名单") if err != nil { br.Msg = "新增Sheet失败" br.ErrMsg = "新增Sheet失败,Err:" + err.Error() return } //标头 rowTitle := sheet.AddRow() cellA := rowTitle.AddCell() cellA.Value = "姓名" cellB := rowTitle.AddCell() cellB.Value = "公司名称" cellC := rowTitle.AddCell() cellC.Value = "问题" cellD := rowTitle.AddCell() cellD.Value = "提交时间" for _, item := range list { row := sheet.AddRow() cellA := row.AddCell() cellA.Value = item.RealName cellB := row.AddCell() cellB.Value = item.CompanyName cellC := row.AddCell() cellC.Value = item.Content cellD := row.AddCell() cellD.Value = item.CreateTime } err = xlsxFile.Save(downLoadnFilePath) if err != nil { br.Msg = "保存文件失败" br.ErrMsg = "保存文件失败" return } randStr := time.Now().Format(utils.FormatDateTimeUnSpace) downloadFileName := "问题列表" + randStr + ".xlsx" this.Ctx.Output.Download(downLoadnFilePath, downloadFileName) defer func() { os.Remove(downLoadnFilePath) }() //添加操作日志记录 br.IsAddLog = true br.Success = true br.Ret = 200 br.Msg = "导出成功" } // @Title 新增报名人员(可择报名方式) // @Description 新增报名人员(可择报名方式)接口 // @Param request body cygx.AddOutboundPersonnelJsonItm true "type json string" // @Success 200 操作成功 // @router /activitySignup/addSignuUserOptType [post] func (this *ActivitySignupCoAntroller) AddSignuUserOptType() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.AddOutboundPersonnelJsonItm err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } adminInfo, err := system.GetSysUserById(AdminUser.AdminId) if err != nil { br.Msg = "添加失败" br.ErrMsg = "获取管理员信息失败,Err:" + err.Error() return } jsonStr := req.JsonStar var config cygx.RequestCommonPolicyConfig err = json.Unmarshal([]byte(jsonStr), &config.CommonPolicyconfigs) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } var uids string for _, v := range config.CommonPolicyconfigs { uids += strconv.Itoa(v.Uid) + "," } uids = strings.TrimRight(uids, ",") var items []*cygx.CygxActivitySignup activityIds := req.ActivityIds uidList := strings.Split(uids, ",") activityIdList := strings.Split(activityIds, ",") for _, v := range config.CommonPolicyconfigs { uid := v.Uid wxUser, userErr := models.GetWxUserByUserId(uid) if userErr != nil { br.Msg = "编辑失败!查询用户信息失败" br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在" return } for _, vact := range activityIdList { activityId, _ := strconv.Atoi(vact) activityInfo, err := cygx.GetAddActivityInfoById(activityId) if err != nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } if adminInfo.RoleTypeCode != "admin" { havePower := cygxService.CheckaddSignuUserPower(wxUser.CompanyId, activityId, activityInfo) if !havePower { br.Msg = "当前活动对该客户不可见,无法报名" br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId)) return } } limitPeopleNum, _ := strconv.Atoi(activityInfo.LimitPeopleNum) //获取这个活动已经报名的用户数量 totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId) if errSignup != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errSignup.Error() return } //获取这个活动中输入的这些用户的报名数量 totalThisUser, errThisUser := cygx.GetActivitySignupCountByThisUser(activityId, uids) if errThisUser != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errThisUser.Error() return } if limitPeopleNum < totalSignup+len(uidList)-totalThisUser { br.Msg = "当前活动报名人数已满" br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ActivityName return } total, errtotal := cygx.GetActivitySignupCount(uid, activityId) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errtotal.Error() return } //判断这个用户是否报名了,如果没有报名则写入报名数据 if total == 0 { infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } item := new(cygx.CygxActivitySignup) item.UserId = infoUser.UserId item.RealName = infoUser.RealName item.SellerName = infoUser.SellerName item.ActivityId = activityId item.CreateTime = time.Now() item.Mobile = infoUser.Mobile item.Email = infoUser.Email item.CompanyId = infoUser.CompanyId item.CompanyName = infoUser.CompanyName //优先绑定用户修改过的外呼手机号 if infoUser.OutboundMobile != "" { item.OutboundMobile = infoUser.OutboundMobile if infoUser.OutboundCountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = infoUser.OutboundCountryCode } } else { item.OutboundMobile = infoUser.Mobile if infoUser.CountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = infoUser.CountryCode } } signupType, _ := strconv.Atoi(v.Type) item.SignupType = signupType item.Source = 2 items = append(items, item) } } } err = cygx.AddCygxActivitySignupUser(items) if err != nil { br.Msg = "操作失败" br.ErrMsg = "新增用户失败,Err:" + err.Error() return } //添加操作日志记录 br.IsAddLog = true br.Ret = 200 br.Success = true br.Msg = "操作成功" } // @Title 活动取消报名 // @Description 活动取消报名接口 // @Param request body cygx.CygxSignupId true "type json string" // @Success Ret=200 // @router /activitySignup/cancel [post] func (this *ActivitySignupCoAntroller) SignupCancel() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.CygxSignupId err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } adminInfo, err := system.GetSysUserById(AdminUser.AdminId) if err != nil { br.Msg = "添加失败" br.ErrMsg = "获取管理员信息失败,Err:" + err.Error() return } signupId := req.SignupId cancelClass := req.CancelClass detail, err := cygx.GetActivitySignupInfoById(signupId) if err != nil { br.Msg = "报名信息不存在" br.ErrMsg = "报名信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(signupId) return } activityInfo, err := cygx.GetAddActivityInfoById(detail.ActivityId) if err != nil { br.Msg = "操作失败" br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detail.ActivityId) return } if cancelClass == 1 { resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式 if time.Now().After(resultTime.Add(-time.Minute * 60)) { br.Msg = "活动开始前1小时内无法取消外呼,提示:外呼名单已发送专家组,请联系专家组取消" return } } activityTypeId := activityInfo.ActivityTypeId if adminInfo.RoleTypeCode != "admin" { if activityTypeId == 1 || activityTypeId == 2 { resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式 if time.Now().After(resultTime.Add(-time.Minute * 60)) { br.Msg = "报名名单已发送至办会平台,请联系相关人员处理。" br.ErrMsg = fmt.Sprint("UserId:", detail.UserId, "ActivityId:", detail.ActivityId) return } } //取消报名截止时间校验 //if activityInfo.CancelDeadline != utils.EmptyDateTimeStr { // cancelDeadline := utils.StrTimeToTime(activityInfo.CancelDeadline) //时间字符串格式转时间格式 // if time.Now().After(cancelDeadline) { // br.Msg = "当前时间晚于取消报名截止时间,已无法取消报名。" // br.ErrMsg = fmt.Sprint("UserId:", detail.UserId, "ActivityId:", detail.ActivityId) // return // } //} } _, err = cygx.CancelActivitySignup(detail) if err != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + err.Error() return } go cygxService.YanXuanActivityPointsBillSignupCancel(detail.ActivityId, detail.UserId, adminInfo.AdminId) if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { go services.SendWxCategoryMsgWithYxActivityCancelSignUpBySell(detail.UserId, activityInfo.ActivityId) } //添加操作日志记录 br.IsAddLog = true br.Ret = 200 br.Success = true br.Msg = "操作成功" } // @Title 预约纪要详情 // @Description 预约纪要详情列表接口 // @Param ActivityId query int true "活动ID" // @Success 200 {object} cygx.GetAppointmentListRep // @router /activitySignup/appointment/summaryList [get] func (this *ActivitySignupCoAntroller) SummaryList() { 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" return } activityId, _ := this.GetInt("ActivityId") if activityId < 1 { br.Msg = "活动不存在" return } activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } var isShowMobile bool if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 { isShowMobile = true } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } memberType := "Admin" sqlStr := "" totalStr := sqlStr if isShowMobile { if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) { //权益申请销售只能看到自己名下的客户的申请 companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIds { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) ` if adminInfo.RoleTypeCode == "rai_group" { //组长查看本组所有组员 memberType = "GroupLeader" } else { //组员查看自己 memberType = "Sale" } } } list, err := cygx.GetCygxAppointmentSummaryList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //根据公司ID获取对应销售 var sellerCompanyIds []int for _, v := range list { sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) } sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds) total, errtotal := cygx.GetCygxAppointmentSummaryCount(activityId, totalStr) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error() return } myTotal, errmyTotal := cygx.GetCygxAppointmentSummaryCount(activityId, sqlStr) if errmyTotal != nil { br.Msg = "获取失败" br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error() return } for k, v := range list { list[k].SellerName = sellNameMap[v.CompanyId] if !isShowMobile { list[k].Mobile = "" } } respList := new(cygx.GetAppointmentListRep) respList.List = list respList.Total = total respList.MyTotal = myTotal respList.ActivityId = activityId respList.IsLimitPeople = activityInfo.IsLimitPeople respList.MemberType = memberType activityTypeId := activityInfo.ActivityTypeId //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "` if activityTypeId == 1 || activityTypeId == 2 { respList.ExcelType = "AppointmentCall" } else if activityTypeId == 5 || activityTypeId == 6 { respList.ExcelType = "ExpertSalon" } else if activityTypeId == 3 { respList.ExcelType = "Teleconference" } else if activityTypeId == 4 { respList.ExcelType = "OfflineResearch" } if isShowMobile { respList.ActivityType = 1 } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = respList } // @Title 新增预约纪要人员 // @Description 新增预约纪要人员接口 // @Param request body cygx.AddOutboundPersonnelItm true "type json string" // @Success 200 操作成功 // @router /activitySignup/appointment/addSummaryUser [post] func (this *ActivitySignupCoAntroller) AddSummaryUser() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.AddOutboundPersonnelItm err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } adminInfo, err := system.GetSysUserById(AdminUser.AdminId) if err != nil { br.Msg = "添加失败" br.ErrMsg = "获取管理员信息失败,Err:" + err.Error() return } var items []*cygx.CygxActivityAppointment uids := req.UserIds activityIds := req.ActivityIds uidList := strings.Split(uids, ",") activityIdList := strings.Split(activityIds, ",") for _, v := range uidList { uid, err := strconv.Atoi(v) if err != nil { br.Msg = "操作失败" br.ErrMsg = "查询用户信息失败,Err:" + err.Error() return } wxUser, userErr := models.GetWxUserByUserId(uid) if userErr != nil { br.Msg = "编辑失败!查询用户信息失败" br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在" return } for _, vact := range activityIdList { activityId, _ := strconv.Atoi(vact) activityInfo, err := cygx.GetAddActivityInfoById(activityId) if err != nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } if adminInfo.RoleTypeCode != "admin" { //havePower := cygxService.CheckaddSignuUserPower(wxUser.CompanyId, activityId, activityInfo) havePower, err := cygxService.GetActivityDetailUserPower(wxUser, AdminUser, activityInfo) if err != nil { br.Msg = "用户权限校验失败!" br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId) return } if !havePower { br.Msg = "当前活动对该客户不可见,无法报名" br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId)) return } } //isHideAppointment := cygxService.IsShowAppointmentByadminSet(activityInfo.IsCanAppointmentMinutes) if activityInfo.IsCanAppointmentMinutes == 0 { br.Msg = "当前活动无法新增预约纪要" + activityInfo.ActivityName return } //if cygxService.CheckActivityAddAppointment(activityInfo) { // br.Msg = "当前活动无法新增预约纪要" + activityInfo.ActivityName // return //} total, errtotal := cygx.GetUserCygxActivityAppointmentCount(uid, activityId) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errtotal.Error() return } //判断这个用户是否报名了,如果没有报名则写入报名数据 if total == 0 { infoUser, err := cygx.GetUserAndCompanyNameList(uid) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } item := new(cygx.CygxActivityAppointment) item.UserId = infoUser.UserId item.RealName = infoUser.RealName item.SellerName = infoUser.SellerName item.ActivityId = activityId item.CreateTime = time.Now() item.Mobile = infoUser.Mobile item.Email = infoUser.Email item.CompanyId = infoUser.CompanyId item.CompanyName = infoUser.CompanyName item.Source = 2 items = append(items, item) } } } err = cygx.AddCygxActivityAppointmentUser(items) if err != nil { br.Msg = "操作失败" br.ErrMsg = "新增用户失败,Err:" + err.Error() return } //添加操作日志记录 br.IsAddLog = true br.Ret = 200 br.Success = true br.Msg = "操作成功" } // @Title 取消纪要纪要预约 // @Description 取消纪要纪要预约接口 // @Param request body cygx.CygxSignupId true "type json string" // @Success Ret=200 // @router /activitySignup/appointment/cancel [post] func (this *ActivitySignupCoAntroller) SummaryCancel() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.CygxSignupId err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } signupId := req.SignupId detail, err := cygx.GetCygxAppointmentSummaryInfoById(signupId) if err != nil { br.Msg = "预约信息不存在" br.ErrMsg = "预约信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(signupId) return } _, err = cygx.CancelcygxActivityAppointment(detail) if err != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + err.Error() return } //添加操作日志记录 br.IsAddLog = true br.Ret = 200 br.Success = true br.Msg = "操作成功" } // @Title 会议提醒人数详情 // @Description 会议提醒人数详情列表接口 // @Param ActivityId query int true "活动ID" // @Success 200 {object} cygx.GetAppointmentListRep // @router /activitySignup/reminder/list [get] func (this *ActivitySignupCoAntroller) ReminderList() { 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" return } activityId, _ := this.GetInt("ActivityId") if activityId < 1 { br.Msg = "活动不存在" return } activityInfo, _ := cygx.GetAddActivityInfoById(activityId) if activityInfo == nil { br.Msg = "活动不存在" br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId) return } //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户 resp := new(cygx.CanDownload) adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId) if errAdmin != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + errAdmin.Error() return } if adminInfo.Role == "admin" || adminInfo.Role == "researcher" { resp.IsCanDownload = true } memberType := "Admin" sqlStr := "" totalStr := sqlStr if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) { //权益申请销售只能看到自己名下的客户的申请 companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error() return } var companyIdstr []string for _, v := range companyIds { companyIdstr = append(companyIdstr, strconv.Itoa(v)) } sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) ` if adminInfo.RoleTypeCode == "rai_group" { //组长查看本组所有组员 memberType = "GroupLeader" } else { //组员查看自己 memberType = "Sale" } } list, err := cygx.GetCygxActivityMeetingReminderList(activityId, sqlStr) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //根据公司ID获取对应销售 //var sellerCompanyIds []int var userIds []int for _, v := range list { //sellerCompanyIds = append(sellerCompanyIds, v.CompanyId) userIds = append(userIds, v.UserId) } listUser, err := models.GetWxUserRaiSllerListByUserIds(userIds) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } //拼接用户相关信息 mapUser := make(map[int]*models.WxUserSller) for _, v := range listUser { mapUser[v.UserId] = v } for _, v := range list { if mapUser[v.UserId] != nil { v.RealName = mapUser[v.UserId].RealName v.Mobile = mapUser[v.UserId].Mobile v.CompanyName = mapUser[v.UserId].CompanyName v.SellerName = mapUser[v.UserId].SellerName } } //sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds) total, errtotal := cygx.GetCygxActivityMeetingReminderCount(activityId, totalStr) if errtotal != nil { br.Msg = "获取失败" br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error() return } myTotal, errmyTotal := cygx.GetCygxActivityMeetingReminderCount(activityId, sqlStr) if errmyTotal != nil { br.Msg = "获取失败" br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error() return } if len(list) > 0 { //for k, v := range list { // list[k].SellerName = sellNameMap[v.CompanyId] //} } else { list = make([]*cygx.CygxAppointmentList, 0) } respList := new(cygx.GetAppointmentListRep) respList.List = list respList.Total = total respList.MyTotal = myTotal respList.ActivityId = activityId respList.IsLimitPeople = activityInfo.IsLimitPeople respList.MemberType = memberType activityTypeId := activityInfo.ActivityTypeId //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "` if activityTypeId == 1 || activityTypeId == 2 { respList.ExcelType = "AppointmentCall" } else if activityTypeId == 5 || activityTypeId == 6 { respList.ExcelType = "ExpertSalon" } else if activityTypeId == 3 { respList.ExcelType = "Teleconference" } else if activityTypeId == 4 { respList.ExcelType = "OfflineResearch" } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = respList } // @Title 取消会议提醒 // @Description 取消会议提醒接口 // @Param request body cygx.CygxSignupId true "type json string" // @Success Ret=200 // @router /activitySignup/reminder/cancel [post] func (this *ActivitySignupCoAntroller) ReminderCancel() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.CygxSignupId err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } signupId := req.SignupId detail, err := cygx.GetCygxActivityMeetingReminderInfoById(signupId) if err != nil { br.Msg = "预约信息不存在" br.ErrMsg = "预约信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(signupId) return } _, err = cygx.CancelActivityMeetingReminder(detail) if err != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + err.Error() return } //添加操作日志记录 br.IsAddLog = true br.Ret = 200 br.Success = true br.Msg = "操作成功" } // @Title 发送模版消息 // @Description 发送模版消息接口 // @Param request body cygx.AddOutboundPersonnelItm true "type json string" // @Success 200 操作成功 // @router /activitySignup/tempMsg [post] func (this *ActivitySignupCoAntroller) TempMsg() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } var req cygx.ActivitySignupTempMsgReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } //adminInfo, err := system.GetSysUserById(AdminUser.AdminId) //if err != nil { // br.Msg = "添加失败" // br.ErrMsg = "获取管理员信息失败,Err:" + err.Error() // return //} idSlice := strings.Split(req.ActivityIds, ",") for _, sId := range idSlice { id, e := strconv.Atoi(sId) if e != nil { br.Msg = "活动Id参数异常" br.ErrMsg = "参数解析异常, Err:" + e.Error() return } var openIdList []*cygx.OpenIdList idMap := make(map[string]string, 0) if strings.Contains(req.SendGroup, "1") { list, err := cygx.GetCygxUserIndustryFllowOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, idList := range list { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } if strings.Contains(req.SendGroup, "2") { var condition string var pars []interface{} condition = " AND p.STATUS IN ('永续') " listmobileYongxu, err := models.GetActivitySpecialOpenIdListMobile(condition, pars) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } mapMobileYongxu := make(map[string]string) for _, v := range listmobileYongxu { mapMobileYongxu[v.Mobile] = v.Mobile } var mobiles []string listFllow, err := cygx.GetCygxForeverUserIndustryFllowOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, v := range listFllow { if mapMobileYongxu[v.Mobile] != "" { mobiles = append(mobiles, v.Mobile) } } list, err := cygx.GetUserRecordListByMobileArr(mobiles) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,GetUserRecordListByMobileArr Err:" + err.Error() return } for _, idList := range openIdList { idMap[idList.OpenId] = idList.OpenId } for _, idList := range list { if _, ok := idMap[idList.OpenId]; !ok { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } } if strings.Contains(req.SendGroup, "3") { list, err := cygxService.GetCygxBigTypeUserIndustryFllowOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, idList := range openIdList { idMap[idList.OpenId] = idList.OpenId } for _, idList := range list { if _, ok := idMap[idList.OpenId]; !ok { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } } if strings.Contains(req.SendGroup, "4") { list, err := cygxService.GetCygxIndustryPackageUserIndustryFllowOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, idList := range openIdList { idMap[idList.OpenId] = idList.OpenId } for _, idList := range list { if _, ok := idMap[idList.OpenId]; !ok { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } } if strings.Contains(req.SendGroup, "5") { list, err := cygxService.GetCygxOtherIndustryPackageUserIndustryFllowOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, idList := range openIdList { idMap[idList.OpenId] = idList.OpenId } for _, idList := range list { if _, ok := idMap[idList.OpenId]; !ok { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } } if strings.Contains(req.SendGroup, "6") { //list, err := models.GetCygxTryOutUserIndustryFllowOpneidByActivityIds(id) //if err != nil { // br.Msg = "查询openId失败" // br.ErrMsg = "查询openId失败,Err:" + err.Error() // return //} var condition string var pars []interface{} condition = " AND p.STATUS IN ('试用') " listmobileShiyong, err := models.GetActivitySpecialOpenIdListMobile(condition, pars) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } mapMobileShiyong := make(map[string]string) for _, v := range listmobileShiyong { mapMobileShiyong[v.Mobile] = v.Mobile } var mobiles []string listFllow, err := cygx.GetCygxForeverUserIndustryFllowOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, v := range listFllow { if mapMobileShiyong[v.Mobile] != "" { mobiles = append(mobiles, v.Mobile) } } list, err := cygx.GetUserRecordListByMobileArr(mobiles) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,GetUserRecordListByMobileArr Err:" + err.Error() return } for _, idList := range openIdList { idMap[idList.OpenId] = idList.OpenId } for _, idList := range list { if _, ok := idMap[idList.OpenId]; !ok { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } } if strings.Contains(req.SendGroup, "7") { list, err := cygxService.GetCygxInteractiveUserOpneidByActivityIds(id) if err != nil { br.Msg = "查询openId失败" br.ErrMsg = "查询openId失败,Err:" + err.Error() return } for _, idList := range openIdList { idMap[idList.OpenId] = idList.OpenId } for _, idList := range list { if _, ok := idMap[idList.OpenId]; !ok { openIdList = append(openIdList, idList) idMap[idList.OpenId] = idList.OpenId } } } if len(openIdList) > 0 { openIdArr := make([]string, len(openIdList)) for i, v := range openIdList { openIdArr[i] = v.OpenId } sendInfo := new(services.SendWxTemplate) //sendInfo.First = req.FirstText sendInfo.Keyword1 = req.ActivityName sendInfo.Keyword2 = req.Content //sendInfo.Keyword3 = meetingTime sendInfo.Remark = "点击查看活动详情" sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs sendInfo.RedirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(id) sendInfo.RedirectTarget = 3 sendInfo.Resource = strconv.Itoa(id) sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_CUSTOMIZE sendInfo.OpenIdArr = openIdArr e = services.SendTemplateMsg(sendInfo) if e != nil { br.Msg = "推送模板消息失败!" br.ErrMsg = "参数解析失败,Err:" + e.Error() return } } } br.Ret = 200 br.Success = true br.Msg = "发送成功" } // @Title 模版消息发送客户类型列表 // @Description 模版消息发送客户类型列表接口 // @Success Ret=200 // @router /activitySignup/tempMsg/sendGroupList [get] func (this *ActivitySignupCoAntroller) SendGroupList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } list := make([]cygx.SendGroup, 0) list = append(list, cygx.SendGroup{ Id: 1, Name: "全部客户", }) list = append(list, cygx.SendGroup{ Id: 2, Name: "永续客户", }) list = append(list, cygx.SendGroup{ Id: 3, Name: "大套餐客户", }) list = append(list, cygx.SendGroup{ Id: 4, Name: "行业套餐客户", }) list = append(list, cygx.SendGroup{ Id: 5, Name: "其他行业正式客户", }) list = append(list, cygx.SendGroup{ Id: 6, Name: "试用客户", }) list = append(list, cygx.SendGroup{ Id: 7, Name: "已参与互动的客户", }) br.Ret = 200 br.Success = true br.Data = list }