1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295 |
- 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
- }
|