123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- package cygx
- import (
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/utils"
- "strings"
- )
- // 到会管理
- type ActivityLossCoAntroller struct {
- controllers.BaseAuthController
- }
- // @Title 获取流失且参加过会议的客户
- // @Description 获取流失且参加过会议的客户接口
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} cygx.CompanyNameAndIdListResp
- // @router /activityLoss/company/list [get]
- func (this *ActivityLossCoAntroller) CompanyList() {
- 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")
- keyWord = strings.Trim(keyWord, " ")
- keyWord = strings.Replace(keyWord, "'", "", -1)
- if keyWord == "" {
- br.Msg = "请输入关键词"
- br.IsSendEmail = false
- return
- }
- resp := new(company.CompanyNameAndIdListResp)
- var companyCondition string
- var companypars []interface{}
- var listResp []*company.CompanyNameAndId
- companyCondition += ` AND b.product_name = ? `
- companypars = append(companypars, "权益")
- companyCondition += ` AND b.status = ? `
- companypars = append(companypars, "流失")
- companyCondition += ` AND a.company_name LIKE '%` + keyWord + `%' `
- companyList, err := company.GetCompanyIdListByproductName(companyCondition, companypars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- companyArr := make([]int, 0)
- for _, v := range companyList {
- companyArr = append(companyArr, v.CompanyId)
- }
- companyLen := len(companyArr)
- if companyLen == 0 {
- goto Loop
- } else {
- var condition string
- var pars []interface{}
- condition += ` AND s.company_id IN (` + utils.GetOrmInReplace(companyLen) + `)`
- pars = append(pars, companyArr)
- companyUserSignUpList, err := cygx.GetCompanyByUserSignUp(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- mapcompanyUserSignUp := make(map[int]int)
- for _, v := range companyUserSignUpList {
- mapcompanyUserSignUp[v.CompanyId] = v.CompanyId
- }
- for _, v := range companyList {
- if _, ok := mapcompanyUserSignUp[v.CompanyId]; ok {
- listResp = append(listResp, v)
- }
- }
- }
- Loop:
- if len(listResp) == 0 {
- listResp = make([]*company.CompanyNameAndId, 0)
- }
- resp.List = listResp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取流失且参加过会议的客户
- // @Description 获取流失且参加过会议的客户接口
- // @Param CompanyName query string true "搜索关键词"
- // @Success 200 {object} cygx.UserSignUpLossListResp
- // @router /activityLoss/user/list [get]
- func (this *ActivityLossCoAntroller) UserList() {
- 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
- }
- companyName := this.GetString("CompanyName")
- companyName = strings.Trim(companyName, " ")
- companyName = strings.Replace(companyName, "'", "", -1)
- resp := new(cygx.UserSignUpLossListResp)
- nameItem, err := company.CheckCompanyProductByName(companyName, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验客户名称是否存在失败"
- br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
- return
- }
- var listResp []*cygx.UserSignUpLossResp
- if nameItem == nil {
- goto Loop
- } else {
- companyId := nameItem.CompanyId
- var condition string
- var pars []interface{}
- condition += ` AND s.company_id = ? `
- pars = append(pars, companyId)
- companyUserSignUpList, err := cygx.GetUserSignUpList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- mapUserSignUp := make(map[string]string)
- mapTotalMeeting := make(map[string]int)
- for _, v := range companyUserSignUpList {
- mapTotalMeeting[v.Mobile]++
- }
- for _, v := range companyUserSignUpList {
- if _, ok := mapUserSignUp[v.Mobile]; !ok {
- item := new(cygx.UserSignUpLossResp)
- item.RealName = v.RealName
- item.Mobile = v.Mobile
- item.TotalMeeting = mapTotalMeeting[v.Mobile]
- listResp = append(listResp, item)
- }
- mapUserSignUp[v.Mobile] = v.Mobile
- }
- resp.CompanyId = nameItem.CompanyId
- resp.CompanyName = nameItem.CompanyName
- resp.SellerName = nameItem.SellerName
- }
- Loop:
- if len(listResp) == 0 {
- listResp = make([]*cygx.UserSignUpLossResp, 0)
- }
- resp.List = listResp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 参会明细
- // @Description 获取流失且参加过会议的参会明细接口
- // @Param Mobile query int true "手机号"
- // @Success 200 {object} cygx.UserSignUpMeetLossListResp
- // @router /activityLoss/meet/list [get]
- func (this *ActivityLossCoAntroller) MeetList() {
- 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
- }
- mobile := this.GetString("Mobile")
- if mobile == "" {
- br.Msg = "手机号不能为空"
- br.IsSendEmail = false
- return
- }
- resp := new(cygx.UserSignUpMeetLossListResp)
- userInfo, err := models.GetWxUserByMobile(mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var list []*cygx.AttendanceDetail
- if userInfo == nil {
- goto Loop
- } else {
- var condition string
- condition = ` AND s.is_meeting = 1 GROUP BY s.activity_id `
- list, err = cygx.GetAttendanceDetailListGroupByUser(mobile, condition)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp.RealName = userInfo.RealName
- resp.Mobile = userInfo.Mobile
- }
- Loop:
- if len(list) == 0 {
- list = make([]*cygx.AttendanceDetail, 0)
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|