activity_signup.go 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/cygx"
  10. "hongze/hz_crm_api/models/system"
  11. "hongze/hz_crm_api/services"
  12. cygxService "hongze/hz_crm_api/services/cygx"
  13. "hongze/hz_crm_api/utils"
  14. "html/template"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // 活动
  22. type ActivitySignupCoAntroller struct {
  23. controllers.BaseAuthController
  24. }
  25. // @Title 报名管理列表
  26. // @Description 获取报名管理列表接口
  27. // @Param PageSize query int true "每页数据条数"
  28. // @Param CurrentIndex query int true "当前页页码,从1开始"
  29. // @Param ChartPermissionId query string false "行业id"
  30. // @Param ActivityTypeId query string false "活动类型id 多个用 , 隔开列如: 1,2"
  31. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  32. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  33. // @Param KeyWord query string false "搜索关键词"
  34. // @Param SearchType query int true "筛选类型 1专家/分析师电话会、2专家/分析师线下沙龙 、3公司调研/、4C类电话会、5买方线下交流"
  35. // @Param ActiveState query int false "发布状态 ,1未开始、2进行中、3已结束 ,默认1未开始"
  36. // @Param PublishStatus query int false "发布状态 ,0未发布,1已发布,3已取消,传2查询所有"
  37. // @Param IsResearch query bool true "是否为研选"
  38. // @Success 200 {object} cygx.GetCygxSignupListRep
  39. // @router /activitySignup/list [get]
  40. func (this *ActivitySignupCoAntroller) SignupList() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. sysUser := this.SysUser
  47. if sysUser == nil {
  48. br.Msg = "请登录"
  49. br.ErrMsg = "请登录,SysUser Is Empty"
  50. return
  51. }
  52. pageSize, _ := this.GetInt("PageSize")
  53. currentIndex, _ := this.GetInt("CurrentIndex")
  54. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  55. ActivityTypeId := this.GetString("ActivityTypeId")
  56. startDate := this.GetString("StartDate")
  57. endDate := this.GetString("EndDate")
  58. keyWord := this.GetString("KeyWord")
  59. activeState, _ := this.GetInt("ActiveState")
  60. searchType, _ := this.GetInt("SearchType")
  61. publishStatus, _ := this.GetInt("PublishStatus")
  62. isResearch, _ := this.GetBool("IsResearch", false) // 是否为研选 查研观向11.0 (研选活动独立显示)
  63. if activeState == 0 {
  64. activeState = 1
  65. }
  66. var startSize int
  67. if pageSize <= 0 {
  68. pageSize = utils.PageSize20
  69. }
  70. if currentIndex <= 0 {
  71. currentIndex = 1
  72. }
  73. startSize = utils.StartIndex(currentIndex, pageSize)
  74. var condition string
  75. var pars []interface{}
  76. if keyWord != "" {
  77. template.HTMLEscapeString(keyWord)
  78. keyWord = "%" + keyWord + "%"
  79. condition += ` AND (art.activity_name LIKE ? ) `
  80. pars = append(pars, keyWord)
  81. }
  82. condition += ` AND art.active_state = ? `
  83. pars = append(pars, activeState)
  84. if ActivityTypeId == "" {
  85. if searchType == 5 {
  86. condition += ` AND art.activity_type_id IN (8) `
  87. } else if searchType == 4 {
  88. condition += ` AND art.activity_type_id IN (7) `
  89. } else if searchType == 3 {
  90. condition += ` AND art.activity_type_id IN (3,4) `
  91. } else if searchType == 2 {
  92. condition += ` AND art.activity_type_id IN (5,6) `
  93. } else {
  94. condition += ` AND art.activity_type_id IN (1,2) ` //默认
  95. }
  96. }
  97. if ActivityTypeId != "" {
  98. condition += ` AND art.activity_type_id IN (` + ActivityTypeId + `) `
  99. }
  100. if isResearch {
  101. chartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  102. } else {
  103. condition += ` AND art.chart_permission_id != '` + strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) + `'`
  104. }
  105. //行业名称
  106. if chartPermissionId > 0 {
  107. condition += ` AND art.chart_permission_id = '` + strconv.Itoa(chartPermissionId) + `'`
  108. }
  109. if startDate != "" {
  110. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  111. }
  112. if endDate != "" {
  113. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  114. }
  115. if publishStatus == 0 {
  116. condition += ` AND art.publish_status = 0 AND art.is_cancel = 0 `
  117. } else if publishStatus == 1 {
  118. condition += ` AND art.publish_status = 1 `
  119. } else if publishStatus == 3 {
  120. condition += ` AND art.publish_status = 0 AND art.is_cancel = 1 `
  121. }
  122. //本组可见的活动对,非产品技术部 做权限限制
  123. if sysUser.DepartmentId != 3 {
  124. conditionPermission, err := cygxService.GetAdminActivityPermission(sysUser, condition)
  125. if err != nil {
  126. br.Msg = "获取失败"
  127. br.ErrMsg = "获取失败,GetAdminActivityPermission Err:" + err.Error()
  128. return
  129. }
  130. condition += ` AND art.visible_range != 1 `
  131. condition += conditionPermission
  132. pars = append(pars, pars)
  133. }
  134. //condition += ` AND a.publish_status = 1 `
  135. total, err := cygx.GetCygxSignupCount(condition, pars)
  136. if err != nil {
  137. br.Msg = "获取失败"
  138. br.ErrMsg = "获取失败,Err:" + err.Error()
  139. return
  140. }
  141. if activeState == 3 {
  142. condition += ` ORDER BY art.activity_time DESC `
  143. } else {
  144. condition += ` ORDER BY art.activity_time ASC `
  145. }
  146. list, errList := cygx.GetCygxSignupListAll(condition, pars, startSize, pageSize)
  147. if errList != nil {
  148. br.Msg = "获取失败"
  149. br.ErrMsg = "获取失败,Err:" + errList.Error()
  150. return
  151. }
  152. var activityIds string
  153. for k, v := range list {
  154. if v.ChartPermissionNames != "" {
  155. list[k].ChartPermissionName = v.ChartPermissionNames
  156. }
  157. //if v.IsHideAppointment == 0 {
  158. // list[k].IsShowAppointment = cygxService.IsShowAppointmentByadminSet(v.IsCanAppointmentMinutes)
  159. //}
  160. activityIds += strconv.Itoa(v.ActivityId) + ","
  161. if v.ChartPermissionNameDeputy != "" && v.ChartPermissionNameDeputy != v.ChartPermissionName && v.YidongActivityId != "" {
  162. v.ChartPermissionName = v.ChartPermissionNameDeputy // 易董同步过来的活动展示副权限 v11.0
  163. }
  164. }
  165. activityIds = strings.TrimRight(activityIds, ",")
  166. mapIndustrial := make(map[int]string)
  167. mapSubject := make(map[string]string)
  168. if activityIds != "" {
  169. industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds)
  170. if err != nil {
  171. br.Msg = "获取失败"
  172. br.ErrMsg = "获取失败,GetIndustrialActivityGroupListByactivityIds Err:" + err.Error()
  173. return
  174. }
  175. subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds)
  176. if err != nil {
  177. br.Msg = "获取失败"
  178. br.ErrMsg = "获取失败,GetSubjectActivityGroupListByactivityIds Err:" + err.Error()
  179. return
  180. }
  181. //合并活动对应的多个标的
  182. for _, v := range subjectList {
  183. mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  184. }
  185. //活动对应的产业
  186. for _, v := range industrialList {
  187. var labelSubject string
  188. labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)]
  189. if labelSubject != "" {
  190. mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  191. } else {
  192. mapIndustrial[v.ActivityId] += v.IndustryName + ","
  193. }
  194. }
  195. }
  196. for k, v := range list {
  197. if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" {
  198. list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], ",")
  199. }
  200. if v.IsCancel == 1 {
  201. v.PublishStatus = 3
  202. }
  203. if v.YidongActivityId != "" {
  204. list[k].ActivityTypeName += utils.YI_DONG_NAME
  205. list[k].LimitPeopleNum = 10000 // 前端根据这个字段是否大于0来处理是新增报名还是预约外呼
  206. }
  207. if v.IsYidongConduct == 1 {
  208. v.ActivityTypeName += utils.YI_DONG_NAME_TWO
  209. }
  210. if v.IsCanAppointmentMinutes == 1 {
  211. v.IsShowAppointment = true
  212. }
  213. }
  214. if len(list) == 0 {
  215. list = make([]*cygx.CygxSignupList, 0)
  216. }
  217. page := paging.GetPaging(currentIndex, pageSize, total)
  218. resp := new(cygx.GetCygxSignupListRep)
  219. resp.List = list
  220. resp.Paging = page
  221. br.Ret = 200
  222. br.Success = true
  223. br.Msg = "获取成功"
  224. br.Data = resp
  225. }
  226. // @Title 几种类型报名详情列表
  227. // @Description 获取几种类型报名详情列表接口
  228. // @Param ActivityId query int true "活动ID"
  229. // @Success 200 {object} cygx.GetAppointmentListRep
  230. // @router /activitySignup/appointmentList [get]
  231. func (this *ActivitySignupCoAntroller) AppointmentList() {
  232. br := new(models.BaseResponse).Init()
  233. defer func() {
  234. this.Data["json"] = br
  235. this.ServeJSON()
  236. }()
  237. sysUser := this.SysUser
  238. if sysUser == nil {
  239. br.Msg = "请登录"
  240. br.ErrMsg = "请登录,SysUser Is Empty"
  241. return
  242. }
  243. activityId, _ := this.GetInt("ActivityId")
  244. if activityId < 1 {
  245. br.Msg = "活动不存在"
  246. return
  247. }
  248. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  249. if activityInfo == nil {
  250. br.Msg = "活动不存在"
  251. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  252. return
  253. }
  254. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  255. resp := new(cygx.CanDownload)
  256. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  257. if errAdmin != nil {
  258. br.Msg = "获取失败"
  259. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  260. return
  261. }
  262. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  263. resp.IsCanDownload = true
  264. }
  265. memberType := "Admin"
  266. sqlStr := ` AND s.do_fail_type = 0 `
  267. totalStr := sqlStr
  268. list, err := cygx.GetCygxAppointmentList(activityId, sqlStr)
  269. if err != nil {
  270. br.Msg = "获取失败"
  271. br.ErrMsg = "获取失败,Err:" + err.Error()
  272. return
  273. }
  274. //根据公司ID获取对应销售
  275. var companyIds []int
  276. for _, v := range list {
  277. companyIds = append(companyIds, v.CompanyId)
  278. }
  279. sellNameMap := services.GetSellNameMapByCompanyIds(companyIds)
  280. totalStr += " AND s.company_id != 16 "
  281. total, errtotal := cygx.GetCygxAppointmentCount(activityId, totalStr)
  282. if errtotal != nil {
  283. br.Msg = "获取失败"
  284. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  285. return
  286. }
  287. companyIdsPower, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  288. if err != nil {
  289. br.Msg = "获取失败"
  290. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  291. return
  292. }
  293. var companyIdstr []string
  294. for _, v := range companyIdsPower {
  295. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  296. }
  297. sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) `
  298. myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, sqlStr)
  299. if errmyTotal != nil {
  300. br.Msg = "获取失败"
  301. br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error()
  302. return
  303. }
  304. for k, v := range list {
  305. list[k].SellerName = sellNameMap[v.CompanyId]
  306. }
  307. respList := new(cygx.GetAppointmentListRep)
  308. //销售查看自己客户,销售组长查看组员
  309. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 || activityInfo.IsYidongConduct == 1) {
  310. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  311. if err != nil {
  312. br.Msg = "获取失败"
  313. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  314. return
  315. }
  316. for _, v := range list {
  317. if _, ok := mapMobile[v.Mobile]; ok {
  318. respList.List = append(respList.List, v)
  319. }
  320. }
  321. if adminInfo.RoleTypeCode == "rai_group" {
  322. //组长查看本组所有组员
  323. memberType = "GroupLeader"
  324. } else {
  325. //组员查看自己
  326. memberType = "Sale"
  327. }
  328. } else {
  329. respList.List = list
  330. }
  331. if len(respList.List) == 0 {
  332. respList.List = make([]*cygx.CygxAppointmentList, 0)
  333. }
  334. respList.Total = total
  335. respList.MyTotal = myTotal
  336. respList.ActivityId = activityId
  337. respList.IsLimitPeople = activityInfo.IsLimitPeople
  338. respList.MemberType = memberType
  339. respList.IsResearchPoints = activityInfo.IsResearchPoints
  340. activityTypeId := activityInfo.ActivityTypeId
  341. //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "`
  342. if activityTypeId == 1 || activityTypeId == 2 {
  343. respList.ExcelType = "AppointmentCall"
  344. } else if activityTypeId == 5 || activityTypeId == 6 {
  345. respList.ExcelType = "ExpertSalon"
  346. } else if activityTypeId == 3 {
  347. respList.ExcelType = "Teleconference"
  348. } else if activityTypeId == 4 {
  349. respList.ExcelType = "OfflineResearch"
  350. } else if activityTypeId == 7 {
  351. respList.ExcelType = "CClass"
  352. }
  353. if activityInfo.YidongActivityId != "" {
  354. respList.ExcelType = "YiDong"
  355. }
  356. respList.IsYidongConduct = activityInfo.IsYidongConduct
  357. br.Ret = 200
  358. br.Success = true
  359. br.Msg = "获取成功"
  360. br.Data = respList
  361. }
  362. // @Title 外呼人员列表
  363. // @Description 获取外呼人员列表接口
  364. // @Param KeyWord query string false "搜索关键词"
  365. // @Success 200 {object} cygx.GetOutboundPersonnelListRep
  366. // @router /activitySignup/userList [get]
  367. func (this *ActivitySignupCoAntroller) OutboundPersonnelList() {
  368. br := new(models.BaseResponse).Init()
  369. defer func() {
  370. this.Data["json"] = br
  371. this.ServeJSON()
  372. }()
  373. keyWord := this.GetString("KeyWord")
  374. sysUser := this.SysUser
  375. if sysUser == nil {
  376. br.Msg = "请登录"
  377. br.ErrMsg = "请登录,SysUser Is Empty"
  378. return
  379. }
  380. if keyWord == "" {
  381. br.Msg = "请输入姓名"
  382. return
  383. }
  384. list, err := cygx.GetOutboundPersonnelList(keyWord)
  385. if err != nil {
  386. br.Msg = "获取失败"
  387. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  388. return
  389. }
  390. for k, v := range list {
  391. if len(v.Mobile) > 7 {
  392. list[k].Mobile = v.Mobile[0:3] + "****" + v.Mobile[7:]
  393. }
  394. }
  395. resp := new(cygx.GetOutboundPersonnelListRep)
  396. resp.List = list
  397. br.Ret = 200
  398. br.Success = true
  399. br.Msg = "获取成功"
  400. br.Data = resp
  401. }
  402. // @Title 新增外呼人员
  403. // @Description 新增外呼人员接口
  404. // @Param request body cygx.AddMeetingReminderReq true "type json string"
  405. // @Success 200 操作成功
  406. // @router /activitySignup/addUser [post]
  407. func (this *ActivitySignupCoAntroller) AddUser() {
  408. br := new(models.BaseResponse).Init()
  409. defer func() {
  410. this.Data["json"] = br
  411. this.ServeJSON()
  412. }()
  413. AdminUser := this.SysUser
  414. if AdminUser == nil {
  415. br.Msg = "请登录"
  416. br.ErrMsg = "请登录,SysUser Is Empty"
  417. return
  418. }
  419. var req cygx.AddMeetingReminderReq
  420. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  421. if err != nil {
  422. br.Msg = "参数解析异常!"
  423. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  424. return
  425. }
  426. var items []*cygx.CygxActivitySignup
  427. var itemsYidong []*cygx.YidongActivitySignup
  428. var itemsAppointment []*cygx.CygxActivityAppointment
  429. activityIds := req.ActivityIds
  430. uidList := req.List
  431. if activityIds == "" {
  432. br.Msg = "请选择活动"
  433. br.ErrMsg = "活动ID不能为空"
  434. return
  435. }
  436. activityIdList := strings.Split(activityIds, ",")
  437. var uids string
  438. for _, v := range uidList {
  439. uids += strconv.Itoa(v.UserId) + ","
  440. }
  441. uids = strings.TrimRight(uids, ",")
  442. for _, v := range uidList {
  443. uid := v.UserId
  444. wxUser, userErr := models.GetWxUserByUserId(uid)
  445. if userErr != nil {
  446. br.Msg = "编辑失败!查询用户信息失败"
  447. br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在"
  448. return
  449. }
  450. for _, vact := range activityIdList {
  451. activityId, _ := strconv.Atoi(vact)
  452. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  453. if err != nil {
  454. br.Msg = "活动不存在"
  455. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  456. return
  457. }
  458. if activityInfo.YidongActivityId != "" {
  459. errMsg := cygxService.CheckYidongActivitySignupTime(activityInfo)
  460. if errMsg != "" {
  461. br.Msg = errMsg
  462. br.ErrMsg = errMsg + "Err:activityId:" + strconv.Itoa(activityId)
  463. return
  464. }
  465. }
  466. limitPeopleNum, _ := strconv.Atoi(activityInfo.LimitPeopleNum)
  467. //if limitPeopleNum > 0 {
  468. if AdminUser.RoleTypeCode != "admin" {
  469. //havePower := cygxService.CheckaddSignuUserPower(wxUser.CompanyId, activityId, activityInfo)
  470. havePower, err := cygxService.GetActivityDetailUserPower(wxUser, AdminUser, activityInfo)
  471. if err != nil {
  472. br.Msg = "用户权限校验失败!"
  473. br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId)
  474. return
  475. }
  476. if !havePower {
  477. br.Msg = "当前活动对该客户不可见,无法报名"
  478. br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId))
  479. return
  480. }
  481. //}
  482. if activityInfo.IsLimitPeople == 1 {
  483. //获取这个活动已经报名的用户数量
  484. totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId)
  485. if errSignup != nil {
  486. br.Msg = "获取失败"
  487. br.ErrMsg = "获取失败,Err:" + errSignup.Error()
  488. return
  489. }
  490. //获取这个活动中输入的这些用户的报名数量
  491. totalThisUser, errThisUser := cygx.GetActivitySignupCountByThisUser(activityId, uids)
  492. if errThisUser != nil {
  493. br.Msg = "获取失败"
  494. br.ErrMsg = "获取失败,Err:" + errThisUser.Error()
  495. return
  496. }
  497. //如果是限制人数的就做报名人数限制判断
  498. if activityInfo.IsLimitPeople == 1 {
  499. if limitPeopleNum < totalSignup+len(uidList)-totalThisUser {
  500. br.Msg = "新增失败,活动人数超限"
  501. br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ActivityName
  502. return
  503. }
  504. }
  505. }
  506. }
  507. total, errtotal := cygx.GetActivitySignupCount(uid, activityId)
  508. if errtotal != nil {
  509. br.Msg = "获取失败"
  510. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  511. return
  512. }
  513. if total == 0 {
  514. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  515. if err != nil {
  516. br.Msg = "获取失败"
  517. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  518. return
  519. }
  520. item := new(cygx.CygxActivitySignup)
  521. item.UserId = infoUser.UserId
  522. item.RealName = infoUser.RealName
  523. item.SellerName = infoUser.SellerName
  524. item.ActivityId = activityId
  525. item.CreateTime = time.Now()
  526. item.Mobile = infoUser.Mobile
  527. item.Email = infoUser.Email
  528. item.CompanyId = infoUser.CompanyId
  529. item.CompanyName = infoUser.CompanyName
  530. item.Source = 2
  531. //优先绑定用户修改过的外呼手机号
  532. if infoUser.OutboundMobile != "" {
  533. item.OutboundMobile = infoUser.OutboundMobile
  534. if infoUser.OutboundCountryCode == "" {
  535. item.CountryCode = "86"
  536. } else {
  537. item.CountryCode = infoUser.OutboundCountryCode
  538. }
  539. } else {
  540. item.OutboundMobile = infoUser.Mobile
  541. if infoUser.CountryCode == "" {
  542. item.CountryCode = "86"
  543. } else {
  544. item.CountryCode = infoUser.CountryCode
  545. }
  546. }
  547. item.SignupType = 1
  548. items = append(items, item)
  549. if activityInfo.YidongActivityId != "" {
  550. //测试环境下弘则下面的用户才收到消息
  551. if utils.RunMode != "release" && item.CompanyId == 16 {
  552. itemYidong := new(cygx.YidongActivitySignup)
  553. itemYidong.YidongActivityId = activityInfo.YidongActivityId
  554. itemYidong.Mobile = item.Mobile
  555. itemYidong.RealName = item.RealName
  556. itemYidong.CompanyName = item.CompanyName
  557. itemYidong.CountryCode = item.CountryCode
  558. itemsYidong = append(itemsYidong, itemYidong)
  559. }
  560. }
  561. }
  562. if v.IsAppointment == 1 {
  563. //var isHideAppointment bool
  564. //if activityInfo.IsHideAppointment == 0 {
  565. // isHideAppointment = cygxService.IsShowAppointmentByadminSet(activityInfo.IsCanAppointmentMinutes)
  566. //}
  567. if activityInfo.IsCanAppointmentMinutes == 0 {
  568. br.Msg = "该活动无法预约纪要"
  569. br.ErrMsg = "该活动无法预约纪要,Err:" + activityInfo.ActivityName
  570. return
  571. }
  572. total, errtotal := cygx.GetUserCygxActivityAppointmentCount(uid, activityId)
  573. if errtotal != nil {
  574. br.Msg = "获取失败"
  575. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  576. return
  577. }
  578. //判断这个用户是否报名了,如果没有报名则写入报名数据
  579. if total == 0 {
  580. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  581. if err != nil {
  582. br.Msg = "获取失败"
  583. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  584. return
  585. }
  586. itemAppointment := new(cygx.CygxActivityAppointment)
  587. itemAppointment.UserId = infoUser.UserId
  588. itemAppointment.RealName = infoUser.RealName
  589. itemAppointment.SellerName = infoUser.SellerName
  590. itemAppointment.ActivityId = activityId
  591. itemAppointment.CreateTime = time.Now()
  592. itemAppointment.Mobile = infoUser.Mobile
  593. itemAppointment.Email = infoUser.Email
  594. itemAppointment.CompanyId = infoUser.CompanyId
  595. itemAppointment.CompanyName = infoUser.CompanyName
  596. itemAppointment.AdminId = AdminUser.AdminId
  597. itemAppointment.Source = 2
  598. itemsAppointment = append(itemsAppointment, itemAppointment)
  599. }
  600. }
  601. }
  602. }
  603. mapYidongActivity := make(map[int]int)
  604. err = cygx.AddCygxActivitySignup(items, itemsAppointment, mapYidongActivity)
  605. if err != nil {
  606. br.Msg = "操作失败"
  607. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  608. return
  609. }
  610. //如果有值就向易董推送后台添加的报名信息
  611. if len(itemsYidong) > 0 {
  612. go cygxService.YidongActivityUserSingnUp(itemsYidong)
  613. }
  614. //添加操作日志记录
  615. br.Ret = 200
  616. br.Success = true
  617. br.Msg = "操作成功"
  618. br.IsAddLog = true
  619. }
  620. // @Title 报名失败详情列表
  621. // @Description 获取沙龙报名失败详情列表接口
  622. // @Param ActivityId query int true "活动ID"
  623. // @Success 200 {object} cygx.GetFailSignupListRep
  624. // @router /activitySignup/salonFailSignupList [get]
  625. func (this *ActivitySignupCoAntroller) SalonFailSignupList() {
  626. br := new(models.BaseResponse).Init()
  627. defer func() {
  628. this.Data["json"] = br
  629. this.ServeJSON()
  630. }()
  631. sysUser := this.SysUser
  632. if sysUser == nil {
  633. br.Msg = "请登录"
  634. br.ErrMsg = "请登录,SysUser Is Empty"
  635. return
  636. }
  637. respList := new(cygx.GetFailSignupListRep)
  638. activityId, _ := this.GetInt("ActivityId")
  639. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  640. if activityInfo == nil {
  641. br.Msg = "活动不存在"
  642. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  643. return
  644. }
  645. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  646. resp := new(cygx.CanDownload)
  647. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  648. if errAdmin != nil {
  649. br.Msg = "获取失败"
  650. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  651. return
  652. }
  653. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  654. resp.IsCanDownload = true
  655. }
  656. memberType := "Admin"
  657. sqlStr := ""
  658. sqlStr += ` AND s.fail_type >0 `
  659. list, err := cygx.GetFailSignupList(activityId, sqlStr)
  660. if err != nil {
  661. br.Msg = "获取失败"
  662. br.ErrMsg = "获取失败,Err:" + err.Error()
  663. return
  664. }
  665. //根据公司ID获取对应销售
  666. var sellerCompanyIds []int
  667. for _, v := range list {
  668. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  669. }
  670. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  671. sqlStrtotal := ` AND s.fail_type >0 `
  672. total, errtotal := cygx.GetCygxAppointmentCount(activityId, sqlStrtotal)
  673. if errtotal != nil {
  674. br.Msg = "获取失败"
  675. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  676. return
  677. }
  678. //权益申请销售只能看到自己名下的客户的申请 查研观向11.1
  679. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  680. if err != nil {
  681. br.Msg = "获取失败"
  682. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  683. return
  684. }
  685. var companyIdstr []string
  686. for _, v := range companyIds {
  687. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  688. }
  689. myTotalsqlStr := ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) AND s.fail_type >0 `
  690. myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, myTotalsqlStr)
  691. if errmyTotal != nil {
  692. br.Msg = "获取失败"
  693. br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error()
  694. return
  695. }
  696. if activityInfo.IsLimitPeople > 0 {
  697. //获取这个活动已经报名的用户数量
  698. totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId)
  699. if errSignup != nil {
  700. br.Msg = "获取信息失败"
  701. br.ErrMsg = "获取数量失败,Err:" + errSignup.Error()
  702. return
  703. }
  704. limitPeopleNum, err := strconv.Atoi(activityInfo.LimitPeopleNum)
  705. if err != nil {
  706. br.Msg = "获取信息失败"
  707. br.ErrMsg = "数据转换失败,Err:" + err.Error()
  708. return
  709. }
  710. //如果报名人数不小于限制人数,则报名人数已满
  711. if limitPeopleNum <= totalSignup {
  712. respList.IsFull = true
  713. }
  714. }
  715. for k, v := range list {
  716. list[k].SellerName = sellNameMap[v.CompanyId]
  717. if v.DoFailType == 0 {
  718. list[k].SalonOperation = true
  719. list[k].CallOperation = v.SignupType
  720. } else {
  721. list[k].CallOperation = 3
  722. }
  723. }
  724. //销售查看自己客户,销售组长查看组员
  725. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) {
  726. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  727. if err != nil {
  728. br.Msg = "获取失败"
  729. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  730. return
  731. }
  732. for _, v := range list {
  733. if _, ok := mapMobile[v.Mobile]; ok {
  734. respList.List = append(respList.List, v)
  735. }
  736. }
  737. if adminInfo.RoleTypeCode == "rai_group" {
  738. //组长查看本组所有组员
  739. memberType = "GroupLeader"
  740. } else {
  741. //组员查看自己
  742. memberType = "Sale"
  743. }
  744. } else {
  745. respList.List = list
  746. }
  747. if len(respList.List) == 0 {
  748. respList.List = make([]*cygx.FailSignupListRep, 0)
  749. }
  750. respList.Total = total
  751. respList.MyTotal = myTotal
  752. respList.IsLimitPeople = activityInfo.IsLimitPeople
  753. respList.MemberType = memberType
  754. activityTypeId := activityInfo.ActivityTypeId
  755. if activityTypeId == 1 || activityTypeId == 2 {
  756. respList.ExcelType = "AppointmentCall"
  757. } else if activityTypeId == 5 || activityTypeId == 6 {
  758. respList.ExcelType = "ExpertSalon"
  759. } else if activityTypeId == 3 {
  760. respList.ExcelType = "Teleconference"
  761. } else if activityTypeId == 4 {
  762. respList.ExcelType = "OfflineResearch"
  763. }
  764. br.Ret = 200
  765. br.Success = true
  766. br.Msg = "获取成功"
  767. br.Data = respList
  768. }
  769. // @Title 沙龙限制报名、加入报名
  770. // @Description 修改沙龙限制报名、加入报名接口
  771. // @Param request body cygx.SignupId true "type json string"
  772. // @Success 200 操作成功
  773. // @router /activitySignup/salonSignupEdit [post]
  774. func (this *ActivitySignupCoAntroller) SalonSignupEdit() {
  775. br := new(models.BaseResponse).Init()
  776. defer func() {
  777. this.Data["json"] = br
  778. this.ServeJSON()
  779. }()
  780. AdminUser := this.SysUser
  781. if AdminUser == nil {
  782. br.Msg = "请登录"
  783. br.ErrMsg = "请登录,SysUser Is Empty"
  784. return
  785. }
  786. var req cygx.SignupId
  787. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  788. if err != nil {
  789. br.Msg = "参数解析异常!"
  790. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  791. return
  792. }
  793. id := req.Id
  794. total, err := cygx.GetCygxSignupCountFile(id)
  795. if err != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取失败,Err:" + err.Error()
  798. return
  799. }
  800. if total == 0 {
  801. br.Msg = "获取报名信息失败"
  802. br.ErrMsg = "获取失败,id:" + strconv.Itoa(id)
  803. return
  804. }
  805. detail, err := cygx.GetCygxSignupDetailById(id)
  806. if err != nil {
  807. br.Msg = "操作失败"
  808. br.ErrMsg = "操作失败,Err:" + err.Error()
  809. return
  810. }
  811. newIsAdminAddSignup := 0
  812. if detail.IsAdminAddSignup == 1 {
  813. newIsAdminAddSignup = 0
  814. } else {
  815. newIsAdminAddSignup = 1
  816. activityInfo, err := cygx.GetAddActivityInfoById(detail.ActivityId)
  817. if err != nil {
  818. br.Msg = "活动不存在"
  819. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(detail.ActivityId)
  820. return
  821. }
  822. if activityInfo.IsLimitPeople > 0 {
  823. //获取这个活动已经报名的用户数量
  824. totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(detail.ActivityId)
  825. if errSignup != nil {
  826. br.Msg = "操作失败"
  827. br.ErrMsg = "获取数量失败,Err:" + errSignup.Error()
  828. return
  829. }
  830. limitPeopleNum, err := strconv.Atoi(activityInfo.LimitPeopleNum)
  831. if err != nil {
  832. br.Msg = "操作失败"
  833. br.ErrMsg = "数据转换失败,Err:" + err.Error()
  834. return
  835. }
  836. if limitPeopleNum <= totalSignup {
  837. br.Msg = "新增失败,活动人数超限"
  838. return
  839. }
  840. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  841. if errAdmin != nil {
  842. br.Msg = "获取失败"
  843. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  844. return
  845. }
  846. //如果操作的不是管理员就做下面的限制
  847. if adminInfo.Role != "admin" {
  848. activityId := detail.ActivityId
  849. //单机构两人限制
  850. {
  851. totalSignupCompany, err := cygx.GetActivitySignupCompanyCount(activityId, detail.CompanyId)
  852. if err != nil {
  853. br.Msg = "获取信息失败"
  854. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  855. return
  856. }
  857. if totalSignupCompany >= 2 {
  858. br.Msg = "新增失败,单机构最多2人报名同一活动。"
  859. br.ErrMsg = "新增失败,单机构最多2人报名同一活动。" + fmt.Sprint("activityId:", activityId, detail.Mobile)
  860. return
  861. }
  862. }
  863. //爽约限制
  864. //{
  865. // totalRestrict, err := cygx.GetUserRestrictCount(detail.Mobile)
  866. // if err != nil {
  867. // br.Msg = "获取信息失败"
  868. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  869. // return
  870. // }
  871. // if totalRestrict >= 1 {
  872. // br.Msg = "新增失败," + detail.RealName + "爽约次数过多。"
  873. // br.ErrMsg = detail.RealName + "由于爽约次数过多,暂时被限制报名资格"
  874. // return
  875. // }
  876. //}
  877. }
  878. }
  879. }
  880. var doFailType int
  881. if newIsAdminAddSignup == 1 {
  882. doFailType = 0
  883. } else {
  884. doFailType = detail.FailType
  885. }
  886. infoUser, err := cygx.GetUserAndCompanyNameList(detail.UserId)
  887. if err != nil {
  888. br.Msg = "获取失败"
  889. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  890. return
  891. }
  892. item := new(cygx.CygxActivitySignup)
  893. item.UserId = infoUser.UserId
  894. item.RealName = infoUser.RealName
  895. item.SellerName = infoUser.SellerName
  896. item.ActivityId = detail.ActivityId
  897. item.CreateTime = time.Now()
  898. item.Mobile = infoUser.Mobile
  899. item.Email = infoUser.Email
  900. item.CompanyId = infoUser.CompanyId
  901. item.CompanyName = infoUser.CompanyName
  902. err = cygx.SalonSignupEdit(newIsAdminAddSignup, doFailType, id, item)
  903. if err != nil {
  904. br.Msg = "修改失败"
  905. br.ErrMsg = "修改失败 Err:" + err.Error()
  906. return
  907. }
  908. var itemsSendWxMsg []*cygx.CygxSignupUser
  909. itemsSendWxMsg = append(itemsSendWxMsg, &cygx.CygxSignupUser{UserId: infoUser.UserId, ActivityId: detail.ActivityId})
  910. //销售或后台管理员给用户添加报名之后,进行模版消息推送
  911. if doFailType == 0 {
  912. go cygxService.SendWxMsgWithCygxActivitySignUpBySell(itemsSendWxMsg)
  913. go services.SendWxCategoryMsgWithCygxActivitySignUpBySell(itemsSendWxMsg)
  914. }
  915. //添加操作日志记录
  916. br.Ret = 200
  917. br.Success = true
  918. br.Msg = "操作成功"
  919. br.IsAddLog = true
  920. }
  921. // @Title 公司调研电话会报名失败详情列表
  922. // @Description 获取公司调研电话会报名失败详情列表接口
  923. // @Param ActivityId query int true "活动ID"
  924. // @Success 200 {object} cygx.GetFailSignupListRep
  925. // @router /activitySignup/callFailSignupList [get]
  926. func (this *ActivitySignupCoAntroller) FailSignupList() {
  927. br := new(models.BaseResponse).Init()
  928. defer func() {
  929. this.Data["json"] = br
  930. this.ServeJSON()
  931. }()
  932. sysUser := this.SysUser
  933. if sysUser == nil {
  934. br.Msg = "请登录"
  935. br.ErrMsg = "请登录,SysUser Is Empty"
  936. return
  937. }
  938. activityId, _ := this.GetInt("ActivityId")
  939. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  940. if activityInfo == nil {
  941. br.Msg = "活动不存在"
  942. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  943. return
  944. }
  945. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  946. resp := new(cygx.CanDownload)
  947. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  948. if errAdmin != nil {
  949. br.Msg = "获取失败"
  950. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  951. return
  952. }
  953. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  954. resp.IsCanDownload = true
  955. }
  956. var list []*cygx.FailSignupListRep
  957. memberType := "Admin"
  958. var err error
  959. sqlStr := ""
  960. sqlStr += ` AND s.fail_type >0 `
  961. listSeller, errSeller := cygx.GetFailSignupList(activityId, sqlStr)
  962. list = listSeller
  963. err = errSeller
  964. if err != nil {
  965. br.Msg = "获取失败"
  966. br.ErrMsg = "获取失败,Err:" + err.Error()
  967. return
  968. }
  969. total, errtotal := cygx.GetCygxAppointmentCount(activityId, "")
  970. if errtotal != nil {
  971. br.Msg = "获取失败"
  972. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  973. return
  974. }
  975. //权益申请销售只能看到自己名下的客户的申请 查研观向11.1
  976. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  977. if err != nil {
  978. br.Msg = "获取失败"
  979. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  980. return
  981. }
  982. var companyIdstr []string
  983. for _, v := range companyIds {
  984. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  985. }
  986. myTotalsqlStr := ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) AND s.fail_type >0 `
  987. myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, myTotalsqlStr)
  988. if errmyTotal != nil {
  989. br.Msg = "获取失败"
  990. br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error()
  991. return
  992. }
  993. var listNew []*cygx.FailSignupListRep
  994. for k, v := range list {
  995. if k > 0 && list[k].Id == list[k-1].Id {
  996. list[k-1].SellerName = list[k-1].SellerName + "/" + v.SellerName
  997. }
  998. }
  999. for k, v := range list {
  1000. if k > 0 && list[k].Id != list[k-1].Id {
  1001. listNew = append(listNew, v)
  1002. }
  1003. if k == 0 && len(list) >= 2 && list[1].Id == list[0].Id {
  1004. listNew = append(listNew, v)
  1005. }
  1006. }
  1007. for k, v := range listNew {
  1008. if v.IsAdminAddSignup == 0 {
  1009. listNew[k].CallOperation = 3
  1010. } else {
  1011. listNew[k].CallOperation = v.MeetingType
  1012. }
  1013. }
  1014. respList := new(cygx.GetFailSignupListRep)
  1015. //销售查看自己客户,销售组长查看组员
  1016. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) {
  1017. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  1018. if err != nil {
  1019. br.Msg = "获取失败"
  1020. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  1021. return
  1022. }
  1023. for _, v := range listNew {
  1024. if _, ok := mapMobile[v.Mobile]; ok {
  1025. respList.List = append(respList.List, v)
  1026. }
  1027. }
  1028. if adminInfo.RoleTypeCode == "rai_group" {
  1029. //组长查看本组所有组员
  1030. memberType = "GroupLeader"
  1031. } else {
  1032. //组员查看自己
  1033. memberType = "Sale"
  1034. }
  1035. } else {
  1036. respList.List = listNew
  1037. }
  1038. if len(respList.List) == 0 {
  1039. respList.List = make([]*cygx.FailSignupListRep, 0)
  1040. }
  1041. respList.List = listNew
  1042. respList.Total = total
  1043. respList.MyTotal = myTotal
  1044. respList.IsLimitPeople = activityInfo.IsLimitPeople
  1045. respList.MemberType = memberType
  1046. activityTypeId := activityInfo.ActivityTypeId
  1047. //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "`
  1048. if activityTypeId == 1 || activityTypeId == 2 {
  1049. respList.ExcelType = "AppointmentCall"
  1050. } else if activityTypeId == 5 || activityTypeId == 6 {
  1051. respList.ExcelType = "ExpertSalon"
  1052. } else if activityTypeId == 3 {
  1053. respList.ExcelType = "Teleconference"
  1054. } else if activityTypeId == 4 {
  1055. respList.ExcelType = "OfflineResearch"
  1056. }
  1057. br.Ret = 200
  1058. br.Success = true
  1059. br.Msg = "获取成功"
  1060. br.Data = respList
  1061. }
  1062. // @Title 修改公司调研电话会限制报名、预约外呼、自主拨入
  1063. // @Description 修改公司调研电话会限制报名、预约外呼、自主拨入接口
  1064. // @Param request body cygx.SignupIdCall true "type json string"
  1065. // @Success 200 操作成功
  1066. // @router /activitySignup/callSignupEdit [post]
  1067. func (this *ActivitySignupCoAntroller) CallSignupEdit() {
  1068. br := new(models.BaseResponse).Init()
  1069. defer func() {
  1070. this.Data["json"] = br
  1071. this.ServeJSON()
  1072. }()
  1073. sysUser := this.SysUser
  1074. if sysUser == nil {
  1075. br.Msg = "请登录"
  1076. br.ErrMsg = "请登录,SysUser Is Empty"
  1077. return
  1078. }
  1079. var req cygx.SignupIdCall
  1080. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1081. if err != nil {
  1082. br.Msg = "参数解析异常!"
  1083. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1084. return
  1085. }
  1086. id := req.Id
  1087. operationStatus := req.OperationStatus
  1088. total, err := cygx.GetCygxSignupCountFile(id)
  1089. if err != nil {
  1090. br.Msg = "获取失败"
  1091. br.ErrMsg = "获取失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. if total == 0 {
  1095. br.Msg = "获取报名信息失败"
  1096. br.ErrMsg = "获取失败,id:" + strconv.Itoa(id)
  1097. return
  1098. }
  1099. detail, err := cygx.GetCygxSignupDetailById(id)
  1100. if err != nil {
  1101. br.Msg = "操作失败"
  1102. br.ErrMsg = "操作失败,Err:" + err.Error()
  1103. return
  1104. }
  1105. uid := detail.UserId
  1106. var doFailType int
  1107. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  1108. if err != nil {
  1109. br.Msg = "获取失败"
  1110. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1111. return
  1112. }
  1113. item := new(cygx.CygxMySchedule)
  1114. item.UserId = infoUser.UserId
  1115. item.CreateTime = time.Now()
  1116. item.Mobile = infoUser.Mobile
  1117. item.ActivityId = detail.ActivityId
  1118. item.Email = infoUser.Email
  1119. item.CompanyId = infoUser.CompanyId
  1120. item.CompanyName = infoUser.CompanyName
  1121. if operationStatus == 1 {
  1122. doFailType = 0
  1123. } else {
  1124. doFailType = detail.FailType
  1125. }
  1126. var errEdit error
  1127. if operationStatus == 3 {
  1128. err3 := cygx.CallSignupEditByStatus3(id, doFailType, item)
  1129. errEdit = err3
  1130. } else {
  1131. err1_2 := cygx.CallSignupEditByStatus1_2(operationStatus, id, item)
  1132. errEdit = err1_2
  1133. }
  1134. if errEdit != nil {
  1135. br.Msg = "修改失败"
  1136. br.ErrMsg = "修改失败 Err:" + errEdit.Error()
  1137. return
  1138. }
  1139. br.Ret = 200
  1140. br.Success = true
  1141. br.Msg = "操作成功"
  1142. br.IsAddLog = true
  1143. }
  1144. // @Title 预约外呼详情、公司调研电话会excel表格下载
  1145. // @Description 获取预约外呼详情、公司调研电话会excel表格下载接口
  1146. // @Param ActivityId query int true "活动ID"
  1147. // @Success 200 导出成功
  1148. // @router /activitySignup/callExport [get]
  1149. func (this *ActivitySignupCoAntroller) CallExport() {
  1150. br := new(models.BaseResponse).Init()
  1151. defer func() {
  1152. this.Data["json"] = br
  1153. this.ServeJSON()
  1154. }()
  1155. sysUser := this.SysUser
  1156. if sysUser == nil {
  1157. br.Msg = "请登录"
  1158. br.ErrMsg = "请登录,SysUser Is Empty"
  1159. return
  1160. }
  1161. activityId, _ := this.GetInt("ActivityId")
  1162. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  1163. if activityInfo == nil {
  1164. br.Msg = "活动不存在"
  1165. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  1166. return
  1167. }
  1168. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1169. resp := new(cygx.CanDownload)
  1170. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  1171. if errAdmin != nil {
  1172. br.Msg = "获取失败"
  1173. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  1174. return
  1175. }
  1176. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  1177. resp.IsCanDownload = true
  1178. }
  1179. //var err error
  1180. sqlStr := " "
  1181. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) {
  1182. //权益申请销售只能看到自己名下的客户的申请 查研观向11.1
  1183. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  1184. if err != nil {
  1185. br.Msg = "获取失败"
  1186. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  1187. return
  1188. }
  1189. var companyIdstr []string
  1190. for _, v := range companyIds {
  1191. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  1192. }
  1193. sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) `
  1194. }
  1195. //公司调研电话会下载全部
  1196. if activityInfo.ActivityTypeId != 3 {
  1197. sqlStr += " AND s.signup_type = 1 "
  1198. }
  1199. list, err := cygx.GetCygxAppointmentList(activityId, sqlStr)
  1200. //err = errSeller
  1201. if err != nil {
  1202. br.Msg = "获取失败"
  1203. br.ErrMsg = "获取失败,Err:" + err.Error()
  1204. return
  1205. }
  1206. //会议提醒
  1207. listReminder, err := cygx.GetCygxActivityMeetingReminderList(activityId, sqlStr)
  1208. if err != nil {
  1209. br.Msg = "获取失败"
  1210. br.ErrMsg = "获取失败,Err:" + err.Error()
  1211. return
  1212. }
  1213. //预约纪要
  1214. listSummary, err := cygx.GetCygxAppointmentSummaryList(activityId, sqlStr)
  1215. if err != nil {
  1216. br.Msg = "获取失败"
  1217. br.ErrMsg = "获取失败,Err:" + err.Error()
  1218. return
  1219. }
  1220. //根据公司ID获取对应销售
  1221. var sellerCompanyIds []int
  1222. for _, v := range list {
  1223. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1224. }
  1225. for _, v := range listReminder {
  1226. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1227. }
  1228. for _, v := range listSummary {
  1229. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1230. }
  1231. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  1232. //创建excel
  1233. dir, err := os.Executable()
  1234. exPath := filepath.Dir(dir)
  1235. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1236. xlsxFile := xlsx.NewFile()
  1237. if err != nil {
  1238. br.Msg = "生成文件失败"
  1239. br.ErrMsg = "生成文件失败"
  1240. return
  1241. }
  1242. style := xlsx.NewStyle()
  1243. alignment := xlsx.Alignment{
  1244. Horizontal: "center",
  1245. Vertical: "center",
  1246. WrapText: true,
  1247. }
  1248. style.Alignment = alignment
  1249. style.ApplyAlignment = true
  1250. for pidIndex := 0; pidIndex <= 2; pidIndex++ {
  1251. var sheetName string
  1252. var listDate []*cygx.CygxAppointmentList
  1253. if pidIndex == 0 {
  1254. if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 {
  1255. sheetName = "预约外呼"
  1256. } else {
  1257. sheetName = "名单"
  1258. }
  1259. listDate = list
  1260. } else if pidIndex == 1 {
  1261. sheetName = "会议提醒"
  1262. listDate = listReminder
  1263. } else {
  1264. sheetName = "预约纪要"
  1265. listDate = listSummary
  1266. }
  1267. sheet, err := xlsxFile.AddSheet(sheetName)
  1268. if err != nil {
  1269. br.Msg = "新增Sheet失败"
  1270. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1271. return
  1272. }
  1273. //标头
  1274. if pidIndex == 0 {
  1275. //如果是公司调研电话会就下载邮箱
  1276. if activityInfo.ActivityTypeId == 3 {
  1277. rowTitle := sheet.AddRow()
  1278. cellA := rowTitle.AddCell()
  1279. cellA.Value = "姓名"
  1280. cellB := rowTitle.AddCell()
  1281. cellB.Value = "外呼号码"
  1282. cellC := rowTitle.AddCell()
  1283. cellC.Value = "国际代码"
  1284. cellD := rowTitle.AddCell()
  1285. cellD.Value = "邮箱"
  1286. cellE := rowTitle.AddCell()
  1287. cellE.Value = "公司名称"
  1288. cellF := rowTitle.AddCell()
  1289. cellF.Value = "所属销售"
  1290. for _, item := range listDate {
  1291. row := sheet.AddRow()
  1292. cellA := row.AddCell()
  1293. cellA.Value = item.RealName
  1294. cellB := row.AddCell()
  1295. cellB.Value = item.OutboundMobile
  1296. cellC := row.AddCell()
  1297. if item.CountryCode == "" {
  1298. cellC.Value = "86"
  1299. } else {
  1300. cellC.Value = item.CountryCode
  1301. }
  1302. cellD := row.AddCell()
  1303. cellD.Value = item.Email
  1304. cellE := row.AddCell()
  1305. cellE.Value = item.CompanyName
  1306. cellF := row.AddCell()
  1307. cellF.Value = sellNameMap[item.CompanyId]
  1308. }
  1309. } else {
  1310. rowTitle := sheet.AddRow()
  1311. cellA := rowTitle.AddCell()
  1312. cellA.Value = "姓名"
  1313. cellB := rowTitle.AddCell()
  1314. cellB.Value = "外呼号码"
  1315. cellC := rowTitle.AddCell()
  1316. cellC.Value = "国际代码"
  1317. cellD := rowTitle.AddCell()
  1318. cellD.Value = "公司名称"
  1319. cellE := rowTitle.AddCell()
  1320. cellE.Value = "所属销售"
  1321. for _, item := range listDate {
  1322. row := sheet.AddRow()
  1323. cellA := row.AddCell()
  1324. cellA.Value = item.RealName
  1325. cellB := row.AddCell()
  1326. cellB.Value = item.OutboundMobile
  1327. cellC := row.AddCell()
  1328. if item.CountryCode == "" {
  1329. cellC.Value = "86"
  1330. } else {
  1331. cellC.Value = item.CountryCode
  1332. }
  1333. cellD := row.AddCell()
  1334. cellD.Value = item.CompanyName
  1335. cellE := row.AddCell()
  1336. cellE.Value = sellNameMap[item.CompanyId]
  1337. }
  1338. }
  1339. } else {
  1340. rowTitle := sheet.AddRow()
  1341. cellA := rowTitle.AddCell()
  1342. cellA.Value = "姓名"
  1343. cellB := rowTitle.AddCell()
  1344. cellB.Value = "公司名称"
  1345. cellC := rowTitle.AddCell()
  1346. cellC.Value = "所属销售"
  1347. for _, item := range listDate {
  1348. row := sheet.AddRow()
  1349. cellA := row.AddCell()
  1350. cellA.Value = item.RealName
  1351. cellB := row.AddCell()
  1352. cellB.Value = item.CompanyName
  1353. cellC := row.AddCell()
  1354. cellC.Value = sellNameMap[item.CompanyId]
  1355. }
  1356. }
  1357. }
  1358. err = xlsxFile.Save(downLoadnFilePath)
  1359. if err != nil {
  1360. br.Msg = "保存文件失败"
  1361. br.ErrMsg = "保存文件失败"
  1362. return
  1363. }
  1364. //randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1365. downloadFileName := activityInfo.ActivityName + ".xlsx"
  1366. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1367. defer func() {
  1368. os.Remove(downLoadnFilePath)
  1369. }()
  1370. br.Success = true
  1371. br.Ret = 200
  1372. br.IsAddLog = true
  1373. }
  1374. // @Title 公司线下调研、报名excel表格下载
  1375. // @Description 获取公司线下调研、报名excel表格下载接口
  1376. // @Param ActivityId query int true "活动ID"
  1377. // @Param ExcelType query int true "下载方式 0:全部名单、1:预约外呼名单、2:自主入会(自主拨入)名单"
  1378. // @Success 200 导出成功
  1379. // @router /activitySignup/signupFailExport [get]
  1380. func (this *ActivitySignupCoAntroller) SignupFailExport() {
  1381. br := new(models.BaseResponse).Init()
  1382. defer func() {
  1383. this.Data["json"] = br
  1384. this.ServeJSON()
  1385. }()
  1386. AdminUser := this.SysUser
  1387. if AdminUser == nil {
  1388. br.Msg = "请登录"
  1389. br.ErrMsg = "请登录,SysUser Is Empty"
  1390. return
  1391. }
  1392. activityId, _ := this.GetInt("ActivityId")
  1393. excelType, _ := this.GetInt("ExcelType")
  1394. //signupType := this.GetString("SignupType")
  1395. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  1396. if activityInfo == nil {
  1397. br.Msg = "活动不存在"
  1398. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  1399. return
  1400. }
  1401. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1402. resp := new(cygx.CanDownload)
  1403. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  1404. if errAdmin != nil {
  1405. br.Msg = "获取失败"
  1406. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  1407. return
  1408. }
  1409. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  1410. resp.IsCanDownload = true
  1411. }
  1412. sqlStr := ""
  1413. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 || activityInfo.IsYidongConduct == 1) {
  1414. //权益申请销售只能看到自己名下的客户的申请 查研观向11.1
  1415. companyIds, err := cygxService.GetAdminLookUserCompanyIds(AdminUser)
  1416. if err != nil {
  1417. br.Msg = "获取失败"
  1418. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  1419. return
  1420. }
  1421. var companyIdstr []string
  1422. for _, v := range companyIds {
  1423. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  1424. }
  1425. sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `)`
  1426. }
  1427. sqlStrOther := sqlStr
  1428. var listReminder []*cygx.CygxAppointmentList
  1429. var summaryList []*cygx.CygxAppointmentList
  1430. var err error
  1431. //消息提醒
  1432. listReminder, err = cygx.GetCygxActivityMeetingReminderList(activityId, sqlStrOther)
  1433. if err != nil {
  1434. br.Msg = "获取失败"
  1435. br.ErrMsg = "获取失败,Err:" + err.Error()
  1436. return
  1437. }
  1438. //预约纪要
  1439. summaryList, err = cygx.GetCygxAppointmentSummaryList(activityId, sqlStrOther)
  1440. if err != nil {
  1441. br.Msg = "获取失败"
  1442. br.ErrMsg = "获取失败,Err:" + err.Error()
  1443. return
  1444. }
  1445. if excelType == 1 {
  1446. sqlStr += ` AND s.signup_type = 1 `
  1447. } else if excelType == 2 {
  1448. sqlStr += ` AND s.signup_type IN (2,4) `
  1449. }
  1450. //}
  1451. list, err := cygx.GetCygxAppointmentList(activityId, sqlStr)
  1452. if err != nil {
  1453. br.Msg = "获取失败"
  1454. br.ErrMsg = "获取失败,Err:" + err.Error()
  1455. return
  1456. }
  1457. //根据公司ID获取对应销售
  1458. var sellerCompanyIds []int
  1459. for _, v := range listReminder {
  1460. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1461. }
  1462. for _, v := range summaryList {
  1463. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1464. }
  1465. for _, v := range list {
  1466. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1467. }
  1468. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  1469. //创建excel
  1470. dir, err := os.Executable()
  1471. exPath := filepath.Dir(dir)
  1472. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1473. xlsxFile := xlsx.NewFile()
  1474. if err != nil {
  1475. br.Msg = "生成文件失败"
  1476. br.ErrMsg = "生成文件失败"
  1477. return
  1478. }
  1479. style := xlsx.NewStyle()
  1480. alignment := xlsx.Alignment{
  1481. Horizontal: "center",
  1482. Vertical: "center",
  1483. WrapText: true,
  1484. }
  1485. style.Alignment = alignment
  1486. style.ApplyAlignment = true
  1487. for pidIndex := 0; pidIndex <= 2; pidIndex++ {
  1488. //只做专家电话会,分析师电话会的多Sheel下载
  1489. if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 2 {
  1490. if pidIndex > 0 {
  1491. continue
  1492. }
  1493. }
  1494. var sheetName string
  1495. var listDate []*cygx.CygxAppointmentList
  1496. if pidIndex == 0 {
  1497. sheetName = "报名名单"
  1498. listDate = list
  1499. } else if pidIndex == 1 {
  1500. sheetName = "消息提醒名单"
  1501. listDate = listReminder
  1502. } else if pidIndex == 2 {
  1503. sheetName = "预约纪要名单"
  1504. listDate = summaryList
  1505. }
  1506. sheet, err := xlsxFile.AddSheet(sheetName)
  1507. if err != nil {
  1508. br.Msg = "新增Sheet失败"
  1509. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1510. return
  1511. }
  1512. //标头
  1513. if pidIndex == 0 {
  1514. if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 || (activityInfo.ActivityTypeId == 7 && activityInfo.IsYidongConduct == 1) {
  1515. rowTitle := sheet.AddRow()
  1516. cellA := rowTitle.AddCell()
  1517. cellA.Value = "姓名"
  1518. cellB := rowTitle.AddCell()
  1519. cellB.Value = "外呼号码"
  1520. cellC := rowTitle.AddCell()
  1521. cellC.Value = "国际代码"
  1522. cellD := rowTitle.AddCell()
  1523. cellD.Value = "邮箱"
  1524. cellE := rowTitle.AddCell()
  1525. cellE.Value = "公司名称"
  1526. cellF := rowTitle.AddCell()
  1527. cellF.Value = "所属销售"
  1528. for _, item := range listDate {
  1529. row := sheet.AddRow()
  1530. cellA := row.AddCell()
  1531. cellA.Value = item.RealName
  1532. cellB := row.AddCell()
  1533. cellB.Value = item.OutboundMobile
  1534. cellC := row.AddCell()
  1535. cellC.Value = item.CountryCode
  1536. cellD := row.AddCell()
  1537. cellD.Value = item.Email
  1538. cellE := row.AddCell()
  1539. cellE.Value = item.CompanyName
  1540. cellF := row.AddCell()
  1541. cellF.Value = sellNameMap[item.CompanyId]
  1542. }
  1543. } else {
  1544. rowTitle := sheet.AddRow()
  1545. cellA := rowTitle.AddCell()
  1546. cellA.Value = "姓名"
  1547. cellB := rowTitle.AddCell()
  1548. cellB.Value = "公司名称"
  1549. cellC := rowTitle.AddCell()
  1550. cellC.Value = "所属销售"
  1551. for _, item := range listDate {
  1552. row := sheet.AddRow()
  1553. cellA := row.AddCell()
  1554. cellA.Value = item.RealName
  1555. cellB := row.AddCell()
  1556. cellB.Value = item.CompanyName
  1557. cellC := row.AddCell()
  1558. cellC.Value = sellNameMap[item.CompanyId]
  1559. }
  1560. }
  1561. } else {
  1562. rowTitle := sheet.AddRow()
  1563. cellA := rowTitle.AddCell()
  1564. cellA.Value = "姓名"
  1565. cellB := rowTitle.AddCell()
  1566. cellB.Value = "公司名称"
  1567. cellC := rowTitle.AddCell()
  1568. cellC.Value = "所属销售"
  1569. for _, item := range listDate {
  1570. row := sheet.AddRow()
  1571. cellA := row.AddCell()
  1572. cellA.Value = item.RealName
  1573. cellB := row.AddCell()
  1574. cellB.Value = item.CompanyName
  1575. cellC := row.AddCell()
  1576. cellC.Value = sellNameMap[item.CompanyId]
  1577. }
  1578. }
  1579. }
  1580. err = xlsxFile.Save(downLoadnFilePath)
  1581. if err != nil {
  1582. br.Msg = "保存文件失败"
  1583. br.ErrMsg = "保存文件失败"
  1584. return
  1585. }
  1586. //randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1587. downloadFileName := activityInfo.ActivityName + ".xlsx"
  1588. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1589. defer func() {
  1590. os.Remove(downLoadnFilePath)
  1591. }()
  1592. //添加操作日志记录
  1593. br.Success = true
  1594. br.Ret = 200
  1595. br.Msg = "导出成功"
  1596. br.IsAddLog = true
  1597. }
  1598. // @Title 修改外呼号码
  1599. // @Description 修改外呼号码接口
  1600. // @Param request body cygx.OutboundMobileEditResp true "type json string"
  1601. // @Success 200 操作成功
  1602. // @router /activitySignup/outboundMobileEdit [post]
  1603. func (this *ActivitySignupCoAntroller) OutboundMobileEdit() {
  1604. br := new(models.BaseResponse).Init()
  1605. defer func() {
  1606. this.Data["json"] = br
  1607. this.ServeJSON()
  1608. }()
  1609. sysUser := this.SysUser
  1610. if sysUser == nil {
  1611. br.Msg = "请登录"
  1612. br.ErrMsg = "请登录,SysUser Is Empty"
  1613. return
  1614. }
  1615. var req cygx.OutboundMobileEditResp
  1616. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1617. if err != nil {
  1618. br.Msg = "参数解析异常!"
  1619. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1620. return
  1621. }
  1622. id := req.Id
  1623. outboundMobile := req.OutboundMobile
  1624. countryCode := req.CountryCode
  1625. total, err := cygx.GetCygxSignupCountFile(id)
  1626. if err != nil {
  1627. br.Msg = "获取失败"
  1628. br.ErrMsg = "获取失败,Err:" + err.Error()
  1629. return
  1630. }
  1631. if total == 0 {
  1632. br.Msg = "获取报名信息失败"
  1633. br.ErrMsg = "获取失败,id:" + strconv.Itoa(id)
  1634. return
  1635. }
  1636. err = cygx.OutboundMobileEdit(id, outboundMobile, countryCode)
  1637. if err != nil {
  1638. br.Msg = "修改失败"
  1639. br.ErrMsg = "修改失败 Err:" + err.Error()
  1640. return
  1641. }
  1642. br.Ret = 200
  1643. br.Success = true
  1644. br.Msg = "操作成功"
  1645. br.IsAddLog = true
  1646. }
  1647. // @Title 单条报名详情
  1648. // @Description 获取单条报名详情接口
  1649. // @Param Id query int true "报名ID"
  1650. // @Success Ret=200 {object} cygx.CygxActivitySignup
  1651. // @router /activitySignup/signupDetail [get]
  1652. func (this *ActivitySignupCoAntroller) SignupDetail() {
  1653. br := new(models.BaseResponse).Init()
  1654. defer func() {
  1655. this.Data["json"] = br
  1656. this.ServeJSON()
  1657. }()
  1658. AdminUser := this.SysUser
  1659. if AdminUser == nil {
  1660. br.Msg = "请登录"
  1661. br.ErrMsg = "请登录,用户信息为空"
  1662. br.Ret = 408
  1663. return
  1664. }
  1665. id, _ := this.GetInt("Id")
  1666. if id < 1 {
  1667. br.Msg = "请输入报名ID"
  1668. return
  1669. }
  1670. detail, err := cygx.GetActivitySignupInfoById(id)
  1671. if err != nil {
  1672. br.Msg = "报名信息不存在"
  1673. br.ErrMsg = "报名信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(id)
  1674. return
  1675. }
  1676. br.Ret = 200
  1677. br.Success = true
  1678. br.Msg = "获取成功"
  1679. br.Data = detail
  1680. }
  1681. // @Title 新增报名人员
  1682. // @Description 新增报名人员接口
  1683. // @Param request body cygx.AddMeetingReminderReq true "type json string"
  1684. // @Success 200 操作成功
  1685. // @router /activitySignup/addSignuUser [post]
  1686. func (this *ActivitySignupCoAntroller) AddSignuUser() {
  1687. br := new(models.BaseResponse).Init()
  1688. defer func() {
  1689. this.Data["json"] = br
  1690. this.ServeJSON()
  1691. }()
  1692. AdminUser := this.SysUser
  1693. if AdminUser == nil {
  1694. br.Msg = "请登录"
  1695. br.ErrMsg = "请登录,SysUser Is Empty"
  1696. return
  1697. }
  1698. var req cygx.AddMeetingReminderReq
  1699. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1700. if err != nil {
  1701. br.Msg = "参数解析异常!"
  1702. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1703. return
  1704. }
  1705. adminInfo, err := system.GetSysUserById(AdminUser.AdminId)
  1706. if err != nil {
  1707. br.Msg = "添加失败"
  1708. br.ErrMsg = "获取管理员信息失败,Err:" + err.Error()
  1709. return
  1710. }
  1711. var items []*cygx.CygxActivitySignup
  1712. var itemsYidong []*cygx.YidongActivitySignup
  1713. var itemsAppointment []*cygx.CygxActivityAppointment
  1714. mapYidongActivity := make(map[int]int)
  1715. activityIds := req.ActivityIds
  1716. uidList := req.List
  1717. if activityIds == "" {
  1718. br.Msg = "请选择活动"
  1719. br.ErrMsg = "活动ID不能为空"
  1720. return
  1721. }
  1722. //获取已经报名成功的用户,给没有成功的或者没有报名的用户发送模版消息
  1723. mapSignupSuccess := make(map[string]int)
  1724. var itemsSendWxMsg []*cygx.CygxSignupUser
  1725. var condition string
  1726. var pars []interface{}
  1727. condition = ` AND do_fail_type = 0 AND activity_id IN (` + activityIds + `) `
  1728. listSignup, err := cygx.GetActivitySignupList(condition, pars)
  1729. if err != nil && err.Error() != utils.ErrNoRow() {
  1730. br.Msg = "添加报名失败"
  1731. br.ErrMsg = "添加报名失败,Err:GetActivitySignupList:" + err.Error()
  1732. }
  1733. for _, v := range listSignup {
  1734. mapSignupSuccess[fmt.Sprint("UID_", v.UserId, "AID_", v.ActivityId)] = v.ActivityId
  1735. }
  1736. activityIdList := strings.Split(activityIds, ",")
  1737. var uids string
  1738. for _, v := range uidList {
  1739. uids += strconv.Itoa(v.UserId) + ","
  1740. }
  1741. uids = strings.TrimRight(uids, ",")
  1742. mapCompanyPeople := make(map[string]int)
  1743. checkIsYidongConduct := make(map[string]int)
  1744. for _, v := range uidList {
  1745. uid := v.UserId
  1746. wxUser, userErr := models.GetWxUserByUserId(uid)
  1747. if userErr != nil {
  1748. br.Msg = "编辑失败!查询用户信息失败"
  1749. br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在"
  1750. return
  1751. }
  1752. for _, vact := range activityIdList {
  1753. activityId, _ := strconv.Atoi(vact)
  1754. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  1755. if err != nil {
  1756. br.Msg = "活动不存在"
  1757. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  1758. return
  1759. }
  1760. // 如果是易董的办会,且不提供外呼,而且管理员还勾选了预约外呼,那么做判断
  1761. if activityInfo.IsYidongConduct == 1 && activityInfo.IsCanOutboundCall == 0 && v.SignupType == 1 {
  1762. br.Msg = "此活动不提供外呼"
  1763. br.ErrMsg = "此活动不提供外呼,Err:activityId:" + strconv.Itoa(activityId)
  1764. return
  1765. }
  1766. //同时 勾选一个易懂办会,一个非易懂办会的活动 的判断
  1767. checkIsYidongConduct[strconv.Itoa(activityInfo.IsYidongConduct)] = activityInfo.IsYidongConduct
  1768. if len(checkIsYidongConduct) > 1 {
  1769. br.Msg = "活动类型不同,无法同时新增报名"
  1770. br.ErrMsg = "活动类型不同,Err:activityIds:" + activityIds
  1771. return
  1772. }
  1773. if activityInfo.YidongActivityId != "" {
  1774. errMsg := cygxService.CheckYidongActivitySignupTime(activityInfo)
  1775. if errMsg != "" {
  1776. br.Msg = errMsg
  1777. br.ErrMsg = errMsg + "Err:activityId:" + strconv.Itoa(activityId)
  1778. return
  1779. }
  1780. mapYidongActivity[activityInfo.ActivityId] = activityInfo.ActivityId
  1781. }
  1782. activityTypeId := activityInfo.ActivityTypeId
  1783. if adminInfo.RoleTypeCode != "admin" {
  1784. havePower, err := cygxService.GetActivityDetailUserPower(wxUser, adminInfo, activityInfo)
  1785. if err != nil {
  1786. br.Msg = "用户权限校验失败!"
  1787. br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId)
  1788. return
  1789. }
  1790. if !havePower {
  1791. br.Msg = "当前活动对该客户不可见,无法报名"
  1792. br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId))
  1793. return
  1794. }
  1795. popupMsg, err := cygxService.CheckActivityUserAll(activityInfo, wxUser)
  1796. if err != nil {
  1797. br.Msg = "报名失败!"
  1798. br.ErrMsg = "CheckActivityUserAll,Err:" + err.Error()
  1799. return
  1800. }
  1801. if popupMsg != "" {
  1802. br.Msg = fmt.Sprint("报名失败!用户:", wxUser.RealName, popupMsg)
  1803. return
  1804. }
  1805. if activityInfo.YidongActivityId == "" {
  1806. if activityTypeId == 1 || activityTypeId == 2 {
  1807. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1808. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1809. br.Msg = "报名名单已发送至办会平台,请联系相关人员处理。"
  1810. return
  1811. }
  1812. }
  1813. }
  1814. //弘则的不做校验
  1815. if activityInfo.IsLimitPeople == 1 && wxUser.CompanyId != utils.HZ_COMPANY_ID {
  1816. //单机构两人限制
  1817. {
  1818. sqlStr := ` AND s.do_fail_type = 0`
  1819. listSignUp, err := cygx.GetCygxAppointmentList(activityId, sqlStr)
  1820. if err != nil && err.Error() != utils.ErrNoRow() {
  1821. br.Msg = "获取失败"
  1822. br.ErrMsg = "获取失败,Err:" + err.Error()
  1823. return
  1824. }
  1825. for _, v := range listSignUp {
  1826. mapCompanyPeople[fmt.Sprint("CID_", v.CompanyId, "AID_", activityId)]++
  1827. }
  1828. mapCompanyPeople[fmt.Sprint("CID_", wxUser.CompanyId, "AID_", activityId)]++
  1829. if mapCompanyPeople[fmt.Sprint("CID_", wxUser.CompanyId, "AID_", activityId)] > 2 {
  1830. br.Msg = "新增失败," + wxUser.RealName + "单机构2人限制。"
  1831. br.ErrMsg = wxUser.RealName + "单机构2人限制"
  1832. return
  1833. }
  1834. }
  1835. //爽约限制
  1836. //{
  1837. // totalRestrict, err := cygx.GetUserRestrictCount(wxUser.Mobile)
  1838. // if err != nil {
  1839. // br.Msg = "获取信息失败"
  1840. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1841. // return
  1842. // }
  1843. // if totalRestrict >= 1 {
  1844. // br.Msg = "新增失败," + wxUser.RealName + "爽约次数过多。"
  1845. // br.ErrMsg = wxUser.RealName + "由于爽约次数过多,暂时被限制报名资格"
  1846. // return
  1847. // }
  1848. //}
  1849. }
  1850. }
  1851. limitPeopleNum, _ := strconv.Atoi(activityInfo.LimitPeopleNum)
  1852. //获取这个活动已经报名的用户数量
  1853. totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId)
  1854. if errSignup != nil {
  1855. br.Msg = "获取失败"
  1856. br.ErrMsg = "获取失败,Err:" + errSignup.Error()
  1857. return
  1858. }
  1859. //获取这个活动中输入的这些用户的报名数量
  1860. totalThisUser, errThisUser := cygx.GetActivitySignupCountByThisUser(activityId, uids)
  1861. if errThisUser != nil {
  1862. br.Msg = "获取失败"
  1863. br.ErrMsg = "获取失败,Err:" + errThisUser.Error()
  1864. return
  1865. }
  1866. //如果是限制人数的就做报名人数限制判断
  1867. if activityInfo.IsLimitPeople == 1 {
  1868. if limitPeopleNum < totalSignup+len(uidList)-totalThisUser {
  1869. br.Msg = "新增失败,活动人数超限"
  1870. br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ActivityName
  1871. return
  1872. }
  1873. }
  1874. total, errtotal := cygx.GetActivitySignupCount(uid, activityId)
  1875. if errtotal != nil {
  1876. br.Msg = "获取失败"
  1877. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  1878. return
  1879. }
  1880. //判断这个用户是否报名了,如果没有报名则写入报名数据
  1881. if total == 0 {
  1882. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  1883. if err != nil {
  1884. br.Msg = "获取失败"
  1885. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1886. return
  1887. }
  1888. item := new(cygx.CygxActivitySignup)
  1889. item.UserId = infoUser.UserId
  1890. item.RealName = infoUser.RealName
  1891. item.SellerName = infoUser.SellerName
  1892. item.ActivityId = activityId
  1893. item.CreateTime = time.Now()
  1894. item.Mobile = infoUser.Mobile
  1895. item.Mobile = infoUser.Mobile
  1896. item.Email = infoUser.Email
  1897. item.CompanyId = infoUser.CompanyId
  1898. item.CompanyName = infoUser.CompanyName
  1899. //优先绑定用户修改过的外呼手机号
  1900. if infoUser.OutboundMobile != "" {
  1901. item.OutboundMobile = infoUser.OutboundMobile
  1902. if infoUser.OutboundCountryCode == "" {
  1903. item.CountryCode = "86"
  1904. } else {
  1905. item.CountryCode = infoUser.OutboundCountryCode
  1906. }
  1907. } else {
  1908. item.OutboundMobile = infoUser.Mobile
  1909. if infoUser.CountryCode == "" {
  1910. item.CountryCode = "86"
  1911. } else {
  1912. item.CountryCode = infoUser.CountryCode
  1913. }
  1914. }
  1915. //如果不填报名方式,则默认为我要报名这种方式
  1916. if v.SignupType == 0 {
  1917. item.SignupType = 3
  1918. } else {
  1919. item.SignupType = v.SignupType
  1920. }
  1921. item.Source = 2
  1922. items = append(items, item)
  1923. if activityInfo.YidongActivityId != "" {
  1924. itemYidong := new(cygx.YidongActivitySignup)
  1925. itemYidong.YidongActivityId = activityInfo.YidongActivityId
  1926. itemYidong.Mobile = item.Mobile
  1927. itemYidong.RealName = item.RealName
  1928. itemYidong.CompanyName = item.CompanyName
  1929. itemYidong.CountryCode = item.CountryCode
  1930. itemYidong.ActivityJoinType = activityInfo.ActivityJoinType
  1931. itemsYidong = append(itemsYidong, itemYidong)
  1932. }
  1933. }
  1934. if v.IsAppointment == 1 {
  1935. total, errtotal := cygx.GetUserCygxActivityAppointmentCount(uid, activityId)
  1936. if errtotal != nil {
  1937. br.Msg = "获取失败"
  1938. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  1939. return
  1940. }
  1941. //var isHideAppointment bool
  1942. //if activityInfo.IsCanAppointmentMinutes == 1 {
  1943. // isHideAppointment = cygxService.IsShowAppointmentByadminSet(activityInfo.IsCanAppointmentMinutes)
  1944. //}
  1945. if activityInfo.IsCanAppointmentMinutes == 0 {
  1946. br.Msg = "该活动无法预约纪要"
  1947. br.ErrMsg = "该活动无法预约纪要,Err:" + activityInfo.ActivityName
  1948. return
  1949. }
  1950. //判断这个用户是否报名了,如果没有报名则写入报名数据
  1951. if total == 0 {
  1952. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  1953. if err != nil {
  1954. br.Msg = "获取失败"
  1955. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1956. return
  1957. }
  1958. itemAppointment := new(cygx.CygxActivityAppointment)
  1959. itemAppointment.UserId = infoUser.UserId
  1960. itemAppointment.RealName = infoUser.RealName
  1961. itemAppointment.SellerName = infoUser.SellerName
  1962. itemAppointment.ActivityId = activityId
  1963. itemAppointment.CreateTime = time.Now()
  1964. itemAppointment.Mobile = infoUser.Mobile
  1965. itemAppointment.Email = infoUser.Email
  1966. itemAppointment.CompanyId = infoUser.CompanyId
  1967. itemAppointment.CompanyName = infoUser.CompanyName
  1968. itemAppointment.Source = 2
  1969. itemAppointment.AdminId = adminInfo.AdminId
  1970. itemsAppointment = append(itemsAppointment, itemAppointment)
  1971. }
  1972. }
  1973. if mapSignupSuccess[fmt.Sprint("UID_", uid, "AID_", activityId)] == 0 {
  1974. itemsSendWxMsg = append(itemsSendWxMsg, &cygx.CygxSignupUser{UserId: uid, ActivityId: activityId})
  1975. }
  1976. }
  1977. }
  1978. //mapYidongActivity := make(map[int]int)
  1979. err = cygx.AddCygxActivitySignup(items, itemsAppointment, mapYidongActivity)
  1980. if err != nil {
  1981. br.Msg = "操作失败"
  1982. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  1983. return
  1984. }
  1985. //如果有值就向易董推送后台添加的报名信息
  1986. if len(itemsYidong) > 0 {
  1987. go cygxService.YidongActivityUserSingnUp(itemsYidong)
  1988. }
  1989. //销售或后台管理员给用户添加报名之后,进行模版消息推送
  1990. if len(itemsSendWxMsg) > 0 {
  1991. go cygxService.SendWxMsgWithCygxActivitySignUpBySell(itemsSendWxMsg)
  1992. go services.SendWxCategoryMsgWithCygxActivitySignUpBySell(itemsSendWxMsg)
  1993. }
  1994. if len(items) > 0 {
  1995. //1用户报名添加到处理研选扣点
  1996. for _, v := range items {
  1997. time.Sleep(100 * time.Millisecond) // 添加0.1秒的延时
  1998. cygxService.YanXuanActivityPointsBillSignupAdd(v.ActivityId, v.UserId, adminInfo.AdminId)
  1999. }
  2000. go cygxService.AddctivitySignupDetailListByAdminSignup(req.ActivityIds) //已结束的活动,管理员手动添加报名,把信息写入到联系人列表参会信息中
  2001. }
  2002. //添加操作日志记录
  2003. br.IsAddLog = true
  2004. br.IsSendEmail = false
  2005. br.Ret = 200
  2006. br.Success = true
  2007. br.Msg = "操作成功"
  2008. }
  2009. // @Title 带问列表详情
  2010. // @Description 获取带问列表详情接口
  2011. // @Param ActivityId query int true "活动ID"
  2012. // @Success 200 {object} cygx.ActivityHelpAskListResp
  2013. // @router /activitySignup/askList [get]
  2014. func (this *ActivitySignupCoAntroller) AskList() {
  2015. br := new(models.BaseResponse).Init()
  2016. defer func() {
  2017. this.Data["json"] = br
  2018. this.ServeJSON()
  2019. }()
  2020. sysUser := this.SysUser
  2021. if sysUser == nil {
  2022. br.Msg = "请登录"
  2023. br.ErrMsg = "请登录,SysUser Is Empty"
  2024. return
  2025. }
  2026. activityId, _ := this.GetInt("ActivityId")
  2027. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  2028. if activityInfo == nil {
  2029. br.Msg = "活动不存在"
  2030. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  2031. return
  2032. }
  2033. list, err := cygx.GetActivityHelpAskList(activityId)
  2034. if err != nil {
  2035. br.Msg = "获取失败"
  2036. br.ErrMsg = "获取失败,Err:" + err.Error()
  2037. return
  2038. }
  2039. var userIds []string
  2040. for _, v := range list {
  2041. userIds = append(userIds, strconv.Itoa(v.UserId))
  2042. }
  2043. // 查询留言相关的用户
  2044. var userOthers []*models.WxUser
  2045. if len(userIds) > 0 {
  2046. userOthers, err = models.GetWxUserListByUserIds(strings.Join(userIds, ","))
  2047. if err != nil {
  2048. br.Msg = "查询留言用户出错"
  2049. br.ErrMsg = "查询留言用户出错,Err:" + err.Error()
  2050. return
  2051. }
  2052. }
  2053. usersMapName := make(map[int]string)
  2054. for _, v := range userOthers {
  2055. usersMapName[int(v.UserId)] = v.RealName
  2056. }
  2057. for _, v := range list {
  2058. v.RealName = usersMapName[v.UserId]
  2059. }
  2060. respist := new(cygx.ActivityHelpAskListResp)
  2061. respist.List = list
  2062. br.Ret = 200
  2063. br.Success = true
  2064. br.Msg = "获取成功"
  2065. br.Data = respist
  2066. }
  2067. // @Title 带问详情excel表格下载
  2068. // @Description 带问详情excel表格下载接口
  2069. // @Param ActivityId query int true "活动ID"
  2070. // @Success 200 导出成功
  2071. // @router /activitySignup/askListExport [get]
  2072. func (this *ActivitySignupCoAntroller) AskListExport() {
  2073. br := new(models.BaseResponse).Init()
  2074. defer func() {
  2075. this.Data["json"] = br
  2076. this.ServeJSON()
  2077. }()
  2078. AdminUser := this.SysUser
  2079. if AdminUser == nil {
  2080. br.Msg = "请登录"
  2081. br.ErrMsg = "请登录,SysUser Is Empty"
  2082. return
  2083. }
  2084. activityId, _ := this.GetInt("ActivityId")
  2085. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  2086. if activityInfo == nil {
  2087. br.Msg = "活动不存在"
  2088. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  2089. return
  2090. }
  2091. list, err := cygx.GetActivityHelpAskList(activityId)
  2092. if err != nil {
  2093. br.Msg = "获取失败"
  2094. br.ErrMsg = "获取失败,Err:" + err.Error()
  2095. return
  2096. }
  2097. var userIds []string
  2098. for _, v := range list {
  2099. userIds = append(userIds, strconv.Itoa(v.UserId))
  2100. }
  2101. // 查询留言相关的用户
  2102. var userOthers []*models.WxUser
  2103. if len(userIds) > 0 {
  2104. userOthers, err = models.GetWxUserListByUserIds(strings.Join(userIds, ","))
  2105. if err != nil {
  2106. br.Msg = "查询留言用户出错"
  2107. br.ErrMsg = "查询留言用户出错,Err:" + err.Error()
  2108. return
  2109. }
  2110. }
  2111. usersMapName := make(map[int]string)
  2112. for _, v := range userOthers {
  2113. usersMapName[int(v.UserId)] = v.RealName
  2114. }
  2115. for _, v := range list {
  2116. v.RealName = usersMapName[v.UserId]
  2117. }
  2118. //创建excel
  2119. dir, err := os.Executable()
  2120. exPath := filepath.Dir(dir)
  2121. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2122. xlsxFile := xlsx.NewFile()
  2123. if err != nil {
  2124. br.Msg = "生成文件失败"
  2125. br.ErrMsg = "生成文件失败"
  2126. return
  2127. }
  2128. style := xlsx.NewStyle()
  2129. alignment := xlsx.Alignment{
  2130. Horizontal: "center",
  2131. Vertical: "center",
  2132. WrapText: true,
  2133. }
  2134. style.Alignment = alignment
  2135. style.ApplyAlignment = true
  2136. sheet, err := xlsxFile.AddSheet("名单")
  2137. if err != nil {
  2138. br.Msg = "新增Sheet失败"
  2139. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  2140. return
  2141. }
  2142. //标头
  2143. rowTitle := sheet.AddRow()
  2144. cellA := rowTitle.AddCell()
  2145. cellA.Value = "姓名"
  2146. cellB := rowTitle.AddCell()
  2147. cellB.Value = "公司名称"
  2148. cellC := rowTitle.AddCell()
  2149. cellC.Value = "问题"
  2150. cellD := rowTitle.AddCell()
  2151. cellD.Value = "提交时间"
  2152. for _, item := range list {
  2153. row := sheet.AddRow()
  2154. cellA := row.AddCell()
  2155. cellA.Value = item.RealName
  2156. cellB := row.AddCell()
  2157. cellB.Value = item.CompanyName
  2158. cellC := row.AddCell()
  2159. cellC.Value = item.Content
  2160. cellD := row.AddCell()
  2161. cellD.Value = item.CreateTime
  2162. }
  2163. err = xlsxFile.Save(downLoadnFilePath)
  2164. if err != nil {
  2165. br.Msg = "保存文件失败"
  2166. br.ErrMsg = "保存文件失败"
  2167. return
  2168. }
  2169. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  2170. downloadFileName := "问题列表" + randStr + ".xlsx"
  2171. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  2172. defer func() {
  2173. os.Remove(downLoadnFilePath)
  2174. }()
  2175. //添加操作日志记录
  2176. br.IsAddLog = true
  2177. br.Success = true
  2178. br.Ret = 200
  2179. br.Msg = "导出成功"
  2180. }
  2181. // @Title 新增报名人员(可择报名方式)
  2182. // @Description 新增报名人员(可择报名方式)接口
  2183. // @Param request body cygx.AddOutboundPersonnelJsonItm true "type json string"
  2184. // @Success 200 操作成功
  2185. // @router /activitySignup/addSignuUserOptType [post]
  2186. func (this *ActivitySignupCoAntroller) AddSignuUserOptType() {
  2187. br := new(models.BaseResponse).Init()
  2188. defer func() {
  2189. this.Data["json"] = br
  2190. this.ServeJSON()
  2191. }()
  2192. AdminUser := this.SysUser
  2193. if AdminUser == nil {
  2194. br.Msg = "请登录"
  2195. br.ErrMsg = "请登录,SysUser Is Empty"
  2196. return
  2197. }
  2198. var req cygx.AddOutboundPersonnelJsonItm
  2199. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2200. if err != nil {
  2201. br.Msg = "参数解析异常!"
  2202. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2203. return
  2204. }
  2205. adminInfo, err := system.GetSysUserById(AdminUser.AdminId)
  2206. if err != nil {
  2207. br.Msg = "添加失败"
  2208. br.ErrMsg = "获取管理员信息失败,Err:" + err.Error()
  2209. return
  2210. }
  2211. jsonStr := req.JsonStar
  2212. var config cygx.RequestCommonPolicyConfig
  2213. err = json.Unmarshal([]byte(jsonStr), &config.CommonPolicyconfigs)
  2214. if err != nil {
  2215. br.Msg = "参数解析异常!"
  2216. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2217. return
  2218. }
  2219. var uids string
  2220. for _, v := range config.CommonPolicyconfigs {
  2221. uids += strconv.Itoa(v.Uid) + ","
  2222. }
  2223. uids = strings.TrimRight(uids, ",")
  2224. var items []*cygx.CygxActivitySignup
  2225. activityIds := req.ActivityIds
  2226. uidList := strings.Split(uids, ",")
  2227. activityIdList := strings.Split(activityIds, ",")
  2228. for _, v := range config.CommonPolicyconfigs {
  2229. uid := v.Uid
  2230. wxUser, userErr := models.GetWxUserByUserId(uid)
  2231. if userErr != nil {
  2232. br.Msg = "编辑失败!查询用户信息失败"
  2233. br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在"
  2234. return
  2235. }
  2236. for _, vact := range activityIdList {
  2237. activityId, _ := strconv.Atoi(vact)
  2238. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  2239. if err != nil {
  2240. br.Msg = "活动不存在"
  2241. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  2242. return
  2243. }
  2244. if adminInfo.RoleTypeCode != "admin" {
  2245. havePower := cygxService.CheckaddSignuUserPower(wxUser.CompanyId, activityId, activityInfo)
  2246. if !havePower {
  2247. br.Msg = "当前活动对该客户不可见,无法报名"
  2248. br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId))
  2249. return
  2250. }
  2251. }
  2252. limitPeopleNum, _ := strconv.Atoi(activityInfo.LimitPeopleNum)
  2253. //获取这个活动已经报名的用户数量
  2254. totalSignup, errSignup := cygx.GetActivitySignupCountByActivityId(activityId)
  2255. if errSignup != nil {
  2256. br.Msg = "获取失败"
  2257. br.ErrMsg = "获取失败,Err:" + errSignup.Error()
  2258. return
  2259. }
  2260. //获取这个活动中输入的这些用户的报名数量
  2261. totalThisUser, errThisUser := cygx.GetActivitySignupCountByThisUser(activityId, uids)
  2262. if errThisUser != nil {
  2263. br.Msg = "获取失败"
  2264. br.ErrMsg = "获取失败,Err:" + errThisUser.Error()
  2265. return
  2266. }
  2267. if limitPeopleNum < totalSignup+len(uidList)-totalThisUser {
  2268. br.Msg = "当前活动报名人数已满"
  2269. br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ActivityName
  2270. return
  2271. }
  2272. total, errtotal := cygx.GetActivitySignupCount(uid, activityId)
  2273. if errtotal != nil {
  2274. br.Msg = "获取失败"
  2275. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  2276. return
  2277. }
  2278. //判断这个用户是否报名了,如果没有报名则写入报名数据
  2279. if total == 0 {
  2280. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  2281. if err != nil {
  2282. br.Msg = "获取失败"
  2283. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2284. return
  2285. }
  2286. item := new(cygx.CygxActivitySignup)
  2287. item.UserId = infoUser.UserId
  2288. item.RealName = infoUser.RealName
  2289. item.SellerName = infoUser.SellerName
  2290. item.ActivityId = activityId
  2291. item.CreateTime = time.Now()
  2292. item.Mobile = infoUser.Mobile
  2293. item.Email = infoUser.Email
  2294. item.CompanyId = infoUser.CompanyId
  2295. item.CompanyName = infoUser.CompanyName
  2296. //优先绑定用户修改过的外呼手机号
  2297. if infoUser.OutboundMobile != "" {
  2298. item.OutboundMobile = infoUser.OutboundMobile
  2299. if infoUser.OutboundCountryCode == "" {
  2300. item.CountryCode = "86"
  2301. } else {
  2302. item.CountryCode = infoUser.OutboundCountryCode
  2303. }
  2304. } else {
  2305. item.OutboundMobile = infoUser.Mobile
  2306. if infoUser.CountryCode == "" {
  2307. item.CountryCode = "86"
  2308. } else {
  2309. item.CountryCode = infoUser.CountryCode
  2310. }
  2311. }
  2312. signupType, _ := strconv.Atoi(v.Type)
  2313. item.SignupType = signupType
  2314. item.Source = 2
  2315. items = append(items, item)
  2316. }
  2317. }
  2318. }
  2319. err = cygx.AddCygxActivitySignupUser(items)
  2320. if err != nil {
  2321. br.Msg = "操作失败"
  2322. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  2323. return
  2324. }
  2325. //添加操作日志记录
  2326. br.IsAddLog = true
  2327. br.Ret = 200
  2328. br.Success = true
  2329. br.Msg = "操作成功"
  2330. }
  2331. // @Title 活动取消报名
  2332. // @Description 活动取消报名接口
  2333. // @Param request body cygx.CygxSignupId true "type json string"
  2334. // @Success Ret=200
  2335. // @router /activitySignup/cancel [post]
  2336. func (this *ActivitySignupCoAntroller) SignupCancel() {
  2337. br := new(models.BaseResponse).Init()
  2338. defer func() {
  2339. this.Data["json"] = br
  2340. this.ServeJSON()
  2341. }()
  2342. AdminUser := this.SysUser
  2343. if AdminUser == nil {
  2344. br.Msg = "请登录"
  2345. br.ErrMsg = "请登录,SysUser Is Empty"
  2346. return
  2347. }
  2348. var req cygx.CygxSignupId
  2349. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2350. if err != nil {
  2351. br.Msg = "参数解析异常!"
  2352. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2353. return
  2354. }
  2355. adminInfo, err := system.GetSysUserById(AdminUser.AdminId)
  2356. if err != nil {
  2357. br.Msg = "添加失败"
  2358. br.ErrMsg = "获取管理员信息失败,Err:" + err.Error()
  2359. return
  2360. }
  2361. signupId := req.SignupId
  2362. cancelClass := req.CancelClass
  2363. detail, err := cygx.GetActivitySignupInfoById(signupId)
  2364. if err != nil {
  2365. br.Msg = "报名信息不存在"
  2366. br.ErrMsg = "报名信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(signupId)
  2367. return
  2368. }
  2369. activityInfo, err := cygx.GetAddActivityInfoById(detail.ActivityId)
  2370. if err != nil {
  2371. br.Msg = "操作失败"
  2372. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detail.ActivityId)
  2373. return
  2374. }
  2375. if cancelClass == 1 {
  2376. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  2377. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  2378. br.Msg = "活动开始前1小时内无法取消外呼,提示:外呼名单已发送专家组,请联系专家组取消"
  2379. return
  2380. }
  2381. }
  2382. activityTypeId := activityInfo.ActivityTypeId
  2383. if adminInfo.RoleTypeCode != "admin" {
  2384. if activityTypeId == 1 || activityTypeId == 2 {
  2385. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  2386. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  2387. br.Msg = "报名名单已发送至办会平台,请联系相关人员处理。"
  2388. br.ErrMsg = fmt.Sprint("UserId:", detail.UserId, "ActivityId:", detail.ActivityId)
  2389. return
  2390. }
  2391. }
  2392. //取消报名截止时间校验
  2393. //if activityInfo.CancelDeadline != utils.EmptyDateTimeStr {
  2394. // cancelDeadline := utils.StrTimeToTime(activityInfo.CancelDeadline) //时间字符串格式转时间格式
  2395. // if time.Now().After(cancelDeadline) {
  2396. // br.Msg = "当前时间晚于取消报名截止时间,已无法取消报名。"
  2397. // br.ErrMsg = fmt.Sprint("UserId:", detail.UserId, "ActivityId:", detail.ActivityId)
  2398. // return
  2399. // }
  2400. //}
  2401. }
  2402. _, err = cygx.CancelActivitySignup(detail)
  2403. if err != nil {
  2404. br.Msg = "操作失败"
  2405. br.ErrMsg = "操作失败,Err:" + err.Error()
  2406. return
  2407. }
  2408. go cygxService.YanXuanActivityPointsBillSignupCancel(detail.ActivityId, detail.UserId, adminInfo.AdminId)
  2409. if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  2410. go services.SendWxCategoryMsgWithYxActivityCancelSignUpBySell(detail.UserId, activityInfo.ActivityId)
  2411. }
  2412. //添加操作日志记录
  2413. br.IsAddLog = true
  2414. br.Ret = 200
  2415. br.Success = true
  2416. br.Msg = "操作成功"
  2417. }
  2418. // @Title 预约纪要详情
  2419. // @Description 预约纪要详情列表接口
  2420. // @Param ActivityId query int true "活动ID"
  2421. // @Success 200 {object} cygx.GetAppointmentListRep
  2422. // @router /activitySignup/appointment/summaryList [get]
  2423. func (this *ActivitySignupCoAntroller) SummaryList() {
  2424. br := new(models.BaseResponse).Init()
  2425. defer func() {
  2426. this.Data["json"] = br
  2427. this.ServeJSON()
  2428. }()
  2429. sysUser := this.SysUser
  2430. if sysUser == nil {
  2431. br.Msg = "请登录"
  2432. br.ErrMsg = "请登录,SysUser Is Empty"
  2433. return
  2434. }
  2435. activityId, _ := this.GetInt("ActivityId")
  2436. if activityId < 1 {
  2437. br.Msg = "活动不存在"
  2438. return
  2439. }
  2440. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  2441. if activityInfo == nil {
  2442. br.Msg = "活动不存在"
  2443. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  2444. return
  2445. }
  2446. var isShowMobile bool
  2447. if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3 {
  2448. isShowMobile = true
  2449. }
  2450. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  2451. resp := new(cygx.CanDownload)
  2452. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  2453. if errAdmin != nil {
  2454. br.Msg = "获取失败"
  2455. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  2456. return
  2457. }
  2458. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  2459. resp.IsCanDownload = true
  2460. }
  2461. memberType := "Admin"
  2462. sqlStr := ""
  2463. totalStr := sqlStr
  2464. if isShowMobile {
  2465. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) {
  2466. //权益申请销售只能看到自己名下的客户的申请
  2467. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  2468. if err != nil {
  2469. br.Msg = "获取失败"
  2470. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  2471. return
  2472. }
  2473. var companyIdstr []string
  2474. for _, v := range companyIds {
  2475. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  2476. }
  2477. sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) `
  2478. if adminInfo.RoleTypeCode == "rai_group" {
  2479. //组长查看本组所有组员
  2480. memberType = "GroupLeader"
  2481. } else {
  2482. //组员查看自己
  2483. memberType = "Sale"
  2484. }
  2485. }
  2486. }
  2487. list, err := cygx.GetCygxAppointmentSummaryList(activityId, sqlStr)
  2488. if err != nil {
  2489. br.Msg = "获取失败"
  2490. br.ErrMsg = "获取失败,Err:" + err.Error()
  2491. return
  2492. }
  2493. //根据公司ID获取对应销售
  2494. var sellerCompanyIds []int
  2495. for _, v := range list {
  2496. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  2497. }
  2498. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  2499. total, errtotal := cygx.GetCygxAppointmentSummaryCount(activityId, totalStr)
  2500. if errtotal != nil {
  2501. br.Msg = "获取失败"
  2502. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  2503. return
  2504. }
  2505. myTotal, errmyTotal := cygx.GetCygxAppointmentSummaryCount(activityId, sqlStr)
  2506. if errmyTotal != nil {
  2507. br.Msg = "获取失败"
  2508. br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error()
  2509. return
  2510. }
  2511. for k, v := range list {
  2512. list[k].SellerName = sellNameMap[v.CompanyId]
  2513. if !isShowMobile {
  2514. list[k].Mobile = ""
  2515. }
  2516. }
  2517. respList := new(cygx.GetAppointmentListRep)
  2518. respList.List = list
  2519. respList.Total = total
  2520. respList.MyTotal = myTotal
  2521. respList.ActivityId = activityId
  2522. respList.IsLimitPeople = activityInfo.IsLimitPeople
  2523. respList.MemberType = memberType
  2524. activityTypeId := activityInfo.ActivityTypeId
  2525. //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "`
  2526. if activityTypeId == 1 || activityTypeId == 2 {
  2527. respList.ExcelType = "AppointmentCall"
  2528. } else if activityTypeId == 5 || activityTypeId == 6 {
  2529. respList.ExcelType = "ExpertSalon"
  2530. } else if activityTypeId == 3 {
  2531. respList.ExcelType = "Teleconference"
  2532. } else if activityTypeId == 4 {
  2533. respList.ExcelType = "OfflineResearch"
  2534. }
  2535. if isShowMobile {
  2536. respList.ActivityType = 1
  2537. }
  2538. br.Ret = 200
  2539. br.Success = true
  2540. br.Msg = "获取成功"
  2541. br.Data = respList
  2542. }
  2543. // @Title 新增预约纪要人员
  2544. // @Description 新增预约纪要人员接口
  2545. // @Param request body cygx.AddOutboundPersonnelItm true "type json string"
  2546. // @Success 200 操作成功
  2547. // @router /activitySignup/appointment/addSummaryUser [post]
  2548. func (this *ActivitySignupCoAntroller) AddSummaryUser() {
  2549. br := new(models.BaseResponse).Init()
  2550. defer func() {
  2551. this.Data["json"] = br
  2552. this.ServeJSON()
  2553. }()
  2554. AdminUser := this.SysUser
  2555. if AdminUser == nil {
  2556. br.Msg = "请登录"
  2557. br.ErrMsg = "请登录,SysUser Is Empty"
  2558. return
  2559. }
  2560. var req cygx.AddOutboundPersonnelItm
  2561. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2562. if err != nil {
  2563. br.Msg = "参数解析异常!"
  2564. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2565. return
  2566. }
  2567. adminInfo, err := system.GetSysUserById(AdminUser.AdminId)
  2568. if err != nil {
  2569. br.Msg = "添加失败"
  2570. br.ErrMsg = "获取管理员信息失败,Err:" + err.Error()
  2571. return
  2572. }
  2573. var items []*cygx.CygxActivityAppointment
  2574. uids := req.UserIds
  2575. activityIds := req.ActivityIds
  2576. uidList := strings.Split(uids, ",")
  2577. activityIdList := strings.Split(activityIds, ",")
  2578. for _, v := range uidList {
  2579. uid, err := strconv.Atoi(v)
  2580. if err != nil {
  2581. br.Msg = "操作失败"
  2582. br.ErrMsg = "查询用户信息失败,Err:" + err.Error()
  2583. return
  2584. }
  2585. wxUser, userErr := models.GetWxUserByUserId(uid)
  2586. if userErr != nil {
  2587. br.Msg = "编辑失败!查询用户信息失败"
  2588. br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在"
  2589. return
  2590. }
  2591. for _, vact := range activityIdList {
  2592. activityId, _ := strconv.Atoi(vact)
  2593. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  2594. if err != nil {
  2595. br.Msg = "活动不存在"
  2596. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  2597. return
  2598. }
  2599. if adminInfo.RoleTypeCode != "admin" {
  2600. //havePower := cygxService.CheckaddSignuUserPower(wxUser.CompanyId, activityId, activityInfo)
  2601. havePower, err := cygxService.GetActivityDetailUserPower(wxUser, AdminUser, activityInfo)
  2602. if err != nil {
  2603. br.Msg = "用户权限校验失败!"
  2604. br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId)
  2605. return
  2606. }
  2607. if !havePower {
  2608. br.Msg = "当前活动对该客户不可见,无法报名"
  2609. br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ActivityName + "用户ID:" + strconv.Itoa(int(wxUser.UserId))
  2610. return
  2611. }
  2612. }
  2613. //isHideAppointment := cygxService.IsShowAppointmentByadminSet(activityInfo.IsCanAppointmentMinutes)
  2614. if activityInfo.IsCanAppointmentMinutes == 0 {
  2615. br.Msg = "当前活动无法新增预约纪要" + activityInfo.ActivityName
  2616. return
  2617. }
  2618. //if cygxService.CheckActivityAddAppointment(activityInfo) {
  2619. // br.Msg = "当前活动无法新增预约纪要" + activityInfo.ActivityName
  2620. // return
  2621. //}
  2622. total, errtotal := cygx.GetUserCygxActivityAppointmentCount(uid, activityId)
  2623. if errtotal != nil {
  2624. br.Msg = "获取失败"
  2625. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  2626. return
  2627. }
  2628. //判断这个用户是否报名了,如果没有报名则写入报名数据
  2629. if total == 0 {
  2630. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  2631. if err != nil {
  2632. br.Msg = "获取失败"
  2633. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2634. return
  2635. }
  2636. item := new(cygx.CygxActivityAppointment)
  2637. item.UserId = infoUser.UserId
  2638. item.RealName = infoUser.RealName
  2639. item.SellerName = infoUser.SellerName
  2640. item.ActivityId = activityId
  2641. item.CreateTime = time.Now()
  2642. item.Mobile = infoUser.Mobile
  2643. item.Email = infoUser.Email
  2644. item.CompanyId = infoUser.CompanyId
  2645. item.CompanyName = infoUser.CompanyName
  2646. item.Source = 2
  2647. items = append(items, item)
  2648. }
  2649. }
  2650. }
  2651. err = cygx.AddCygxActivityAppointmentUser(items)
  2652. if err != nil {
  2653. br.Msg = "操作失败"
  2654. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  2655. return
  2656. }
  2657. //添加操作日志记录
  2658. br.IsAddLog = true
  2659. br.Ret = 200
  2660. br.Success = true
  2661. br.Msg = "操作成功"
  2662. }
  2663. // @Title 取消纪要纪要预约
  2664. // @Description 取消纪要纪要预约接口
  2665. // @Param request body cygx.CygxSignupId true "type json string"
  2666. // @Success Ret=200
  2667. // @router /activitySignup/appointment/cancel [post]
  2668. func (this *ActivitySignupCoAntroller) SummaryCancel() {
  2669. br := new(models.BaseResponse).Init()
  2670. defer func() {
  2671. this.Data["json"] = br
  2672. this.ServeJSON()
  2673. }()
  2674. AdminUser := this.SysUser
  2675. if AdminUser == nil {
  2676. br.Msg = "请登录"
  2677. br.ErrMsg = "请登录,SysUser Is Empty"
  2678. return
  2679. }
  2680. var req cygx.CygxSignupId
  2681. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2682. if err != nil {
  2683. br.Msg = "参数解析异常!"
  2684. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2685. return
  2686. }
  2687. signupId := req.SignupId
  2688. detail, err := cygx.GetCygxAppointmentSummaryInfoById(signupId)
  2689. if err != nil {
  2690. br.Msg = "预约信息不存在"
  2691. br.ErrMsg = "预约信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(signupId)
  2692. return
  2693. }
  2694. _, err = cygx.CancelcygxActivityAppointment(detail)
  2695. if err != nil {
  2696. br.Msg = "操作失败"
  2697. br.ErrMsg = "操作失败,Err:" + err.Error()
  2698. return
  2699. }
  2700. //添加操作日志记录
  2701. br.IsAddLog = true
  2702. br.Ret = 200
  2703. br.Success = true
  2704. br.Msg = "操作成功"
  2705. }
  2706. // @Title 会议提醒人数详情
  2707. // @Description 会议提醒人数详情列表接口
  2708. // @Param ActivityId query int true "活动ID"
  2709. // @Success 200 {object} cygx.GetAppointmentListRep
  2710. // @router /activitySignup/reminder/list [get]
  2711. func (this *ActivitySignupCoAntroller) ReminderList() {
  2712. br := new(models.BaseResponse).Init()
  2713. defer func() {
  2714. this.Data["json"] = br
  2715. this.ServeJSON()
  2716. }()
  2717. sysUser := this.SysUser
  2718. if sysUser == nil {
  2719. br.Msg = "请登录"
  2720. br.ErrMsg = "请登录,SysUser Is Empty"
  2721. return
  2722. }
  2723. activityId, _ := this.GetInt("ActivityId")
  2724. if activityId < 1 {
  2725. br.Msg = "活动不存在"
  2726. return
  2727. }
  2728. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  2729. if activityInfo == nil {
  2730. br.Msg = "活动不存在"
  2731. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  2732. return
  2733. }
  2734. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  2735. resp := new(cygx.CanDownload)
  2736. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  2737. if errAdmin != nil {
  2738. br.Msg = "获取失败"
  2739. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  2740. return
  2741. }
  2742. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  2743. resp.IsCanDownload = true
  2744. }
  2745. memberType := "Admin"
  2746. sqlStr := ""
  2747. totalStr := sqlStr
  2748. if resp.IsCanDownload == false && (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 3) {
  2749. //权益申请销售只能看到自己名下的客户的申请
  2750. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  2751. if err != nil {
  2752. br.Msg = "获取失败"
  2753. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  2754. return
  2755. }
  2756. var companyIdstr []string
  2757. for _, v := range companyIds {
  2758. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  2759. }
  2760. sqlStr += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) `
  2761. if adminInfo.RoleTypeCode == "rai_group" {
  2762. //组长查看本组所有组员
  2763. memberType = "GroupLeader"
  2764. } else {
  2765. //组员查看自己
  2766. memberType = "Sale"
  2767. }
  2768. }
  2769. list, err := cygx.GetCygxActivityMeetingReminderList(activityId, sqlStr)
  2770. if err != nil {
  2771. br.Msg = "获取失败"
  2772. br.ErrMsg = "获取失败,Err:" + err.Error()
  2773. return
  2774. }
  2775. //根据公司ID获取对应销售
  2776. //var sellerCompanyIds []int
  2777. var userIds []int
  2778. for _, v := range list {
  2779. //sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  2780. userIds = append(userIds, v.UserId)
  2781. }
  2782. listUser, err := models.GetWxUserRaiSllerListByUserIds(userIds)
  2783. if err != nil {
  2784. br.Msg = "获取失败"
  2785. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2786. return
  2787. }
  2788. //拼接用户相关信息
  2789. mapUser := make(map[int]*models.WxUserSller)
  2790. for _, v := range listUser {
  2791. mapUser[v.UserId] = v
  2792. }
  2793. for _, v := range list {
  2794. if mapUser[v.UserId] != nil {
  2795. v.RealName = mapUser[v.UserId].RealName
  2796. v.Mobile = mapUser[v.UserId].Mobile
  2797. v.CompanyName = mapUser[v.UserId].CompanyName
  2798. v.SellerName = mapUser[v.UserId].SellerName
  2799. }
  2800. }
  2801. //sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  2802. total, errtotal := cygx.GetCygxActivityMeetingReminderCount(activityId, totalStr)
  2803. if errtotal != nil {
  2804. br.Msg = "获取失败"
  2805. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  2806. return
  2807. }
  2808. myTotal, errmyTotal := cygx.GetCygxActivityMeetingReminderCount(activityId, sqlStr)
  2809. if errmyTotal != nil {
  2810. br.Msg = "获取失败"
  2811. br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error()
  2812. return
  2813. }
  2814. if len(list) > 0 {
  2815. //for k, v := range list {
  2816. // list[k].SellerName = sellNameMap[v.CompanyId]
  2817. //}
  2818. } else {
  2819. list = make([]*cygx.CygxAppointmentList, 0)
  2820. }
  2821. respList := new(cygx.GetAppointmentListRep)
  2822. respList.List = list
  2823. respList.Total = total
  2824. respList.MyTotal = myTotal
  2825. respList.ActivityId = activityId
  2826. respList.IsLimitPeople = activityInfo.IsLimitPeople
  2827. respList.MemberType = memberType
  2828. activityTypeId := activityInfo.ActivityTypeId
  2829. //ExcelType string `description:"EXcel下载类型 AppointmentCall:预约外呼、ExpertSalon:专家沙龙报名、Teleconference:公司调研电话会、OfflineResearch:公司线下调研 "`
  2830. if activityTypeId == 1 || activityTypeId == 2 {
  2831. respList.ExcelType = "AppointmentCall"
  2832. } else if activityTypeId == 5 || activityTypeId == 6 {
  2833. respList.ExcelType = "ExpertSalon"
  2834. } else if activityTypeId == 3 {
  2835. respList.ExcelType = "Teleconference"
  2836. } else if activityTypeId == 4 {
  2837. respList.ExcelType = "OfflineResearch"
  2838. }
  2839. br.Ret = 200
  2840. br.Success = true
  2841. br.Msg = "获取成功"
  2842. br.Data = respList
  2843. }
  2844. // @Title 取消会议提醒
  2845. // @Description 取消会议提醒接口
  2846. // @Param request body cygx.CygxSignupId true "type json string"
  2847. // @Success Ret=200
  2848. // @router /activitySignup/reminder/cancel [post]
  2849. func (this *ActivitySignupCoAntroller) ReminderCancel() {
  2850. br := new(models.BaseResponse).Init()
  2851. defer func() {
  2852. this.Data["json"] = br
  2853. this.ServeJSON()
  2854. }()
  2855. AdminUser := this.SysUser
  2856. if AdminUser == nil {
  2857. br.Msg = "请登录"
  2858. br.ErrMsg = "请登录,SysUser Is Empty"
  2859. return
  2860. }
  2861. var req cygx.CygxSignupId
  2862. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2863. if err != nil {
  2864. br.Msg = "参数解析异常!"
  2865. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2866. return
  2867. }
  2868. signupId := req.SignupId
  2869. detail, err := cygx.GetCygxActivityMeetingReminderInfoById(signupId)
  2870. if err != nil {
  2871. br.Msg = "预约信息不存在"
  2872. br.ErrMsg = "预约信息ID错误,Err:" + err.Error() + "id:" + strconv.Itoa(signupId)
  2873. return
  2874. }
  2875. _, err = cygx.CancelActivityMeetingReminder(detail)
  2876. if err != nil {
  2877. br.Msg = "操作失败"
  2878. br.ErrMsg = "操作失败,Err:" + err.Error()
  2879. return
  2880. }
  2881. //添加操作日志记录
  2882. br.IsAddLog = true
  2883. br.Ret = 200
  2884. br.Success = true
  2885. br.Msg = "操作成功"
  2886. }
  2887. // @Title 发送模版消息
  2888. // @Description 发送模版消息接口
  2889. // @Param request body cygx.AddOutboundPersonnelItm true "type json string"
  2890. // @Success 200 操作成功
  2891. // @router /activitySignup/tempMsg [post]
  2892. func (this *ActivitySignupCoAntroller) TempMsg() {
  2893. br := new(models.BaseResponse).Init()
  2894. defer func() {
  2895. this.Data["json"] = br
  2896. this.ServeJSON()
  2897. }()
  2898. AdminUser := this.SysUser
  2899. if AdminUser == nil {
  2900. br.Msg = "请登录"
  2901. br.ErrMsg = "请登录,SysUser Is Empty"
  2902. return
  2903. }
  2904. var req cygx.ActivitySignupTempMsgReq
  2905. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2906. if err != nil {
  2907. br.Msg = "参数解析异常!"
  2908. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2909. return
  2910. }
  2911. //adminInfo, err := system.GetSysUserById(AdminUser.AdminId)
  2912. //if err != nil {
  2913. // br.Msg = "添加失败"
  2914. // br.ErrMsg = "获取管理员信息失败,Err:" + err.Error()
  2915. // return
  2916. //}
  2917. idSlice := strings.Split(req.ActivityIds, ",")
  2918. for _, sId := range idSlice {
  2919. id, e := strconv.Atoi(sId)
  2920. if e != nil {
  2921. br.Msg = "活动Id参数异常"
  2922. br.ErrMsg = "参数解析异常, Err:" + e.Error()
  2923. return
  2924. }
  2925. var openIdList []*cygx.OpenIdList
  2926. idMap := make(map[string]string, 0)
  2927. if strings.Contains(req.SendGroup, "1") {
  2928. list, err := cygx.GetCygxUserIndustryFllowOpneidByActivityIds(id)
  2929. if err != nil {
  2930. br.Msg = "查询openId失败"
  2931. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  2932. return
  2933. }
  2934. for _, idList := range list {
  2935. openIdList = append(openIdList, idList)
  2936. idMap[idList.OpenId] = idList.OpenId
  2937. }
  2938. }
  2939. if strings.Contains(req.SendGroup, "2") {
  2940. var condition string
  2941. var pars []interface{}
  2942. condition = " AND p.STATUS IN ('永续') "
  2943. listmobileYongxu, err := models.GetActivitySpecialOpenIdListMobile(condition, pars)
  2944. if err != nil {
  2945. br.Msg = "查询openId失败"
  2946. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  2947. return
  2948. }
  2949. mapMobileYongxu := make(map[string]string)
  2950. for _, v := range listmobileYongxu {
  2951. mapMobileYongxu[v.Mobile] = v.Mobile
  2952. }
  2953. var mobiles []string
  2954. listFllow, err := cygx.GetCygxForeverUserIndustryFllowOpneidByActivityIds(id)
  2955. if err != nil {
  2956. br.Msg = "查询openId失败"
  2957. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  2958. return
  2959. }
  2960. for _, v := range listFllow {
  2961. if mapMobileYongxu[v.Mobile] != "" {
  2962. mobiles = append(mobiles, v.Mobile)
  2963. }
  2964. }
  2965. list, err := cygx.GetUserRecordListByMobileArr(mobiles)
  2966. if err != nil {
  2967. br.Msg = "查询openId失败"
  2968. br.ErrMsg = "查询openId失败,GetUserRecordListByMobileArr Err:" + err.Error()
  2969. return
  2970. }
  2971. for _, idList := range openIdList {
  2972. idMap[idList.OpenId] = idList.OpenId
  2973. }
  2974. for _, idList := range list {
  2975. if _, ok := idMap[idList.OpenId]; !ok {
  2976. openIdList = append(openIdList, idList)
  2977. idMap[idList.OpenId] = idList.OpenId
  2978. }
  2979. }
  2980. }
  2981. if strings.Contains(req.SendGroup, "3") {
  2982. list, err := cygxService.GetCygxBigTypeUserIndustryFllowOpneidByActivityIds(id)
  2983. if err != nil {
  2984. br.Msg = "查询openId失败"
  2985. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  2986. return
  2987. }
  2988. for _, idList := range openIdList {
  2989. idMap[idList.OpenId] = idList.OpenId
  2990. }
  2991. for _, idList := range list {
  2992. if _, ok := idMap[idList.OpenId]; !ok {
  2993. openIdList = append(openIdList, idList)
  2994. idMap[idList.OpenId] = idList.OpenId
  2995. }
  2996. }
  2997. }
  2998. if strings.Contains(req.SendGroup, "4") {
  2999. list, err := cygxService.GetCygxIndustryPackageUserIndustryFllowOpneidByActivityIds(id)
  3000. if err != nil {
  3001. br.Msg = "查询openId失败"
  3002. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  3003. return
  3004. }
  3005. for _, idList := range openIdList {
  3006. idMap[idList.OpenId] = idList.OpenId
  3007. }
  3008. for _, idList := range list {
  3009. if _, ok := idMap[idList.OpenId]; !ok {
  3010. openIdList = append(openIdList, idList)
  3011. idMap[idList.OpenId] = idList.OpenId
  3012. }
  3013. }
  3014. }
  3015. if strings.Contains(req.SendGroup, "5") {
  3016. list, err := cygxService.GetCygxOtherIndustryPackageUserIndustryFllowOpneidByActivityIds(id)
  3017. if err != nil {
  3018. br.Msg = "查询openId失败"
  3019. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  3020. return
  3021. }
  3022. for _, idList := range openIdList {
  3023. idMap[idList.OpenId] = idList.OpenId
  3024. }
  3025. for _, idList := range list {
  3026. if _, ok := idMap[idList.OpenId]; !ok {
  3027. openIdList = append(openIdList, idList)
  3028. idMap[idList.OpenId] = idList.OpenId
  3029. }
  3030. }
  3031. }
  3032. if strings.Contains(req.SendGroup, "6") {
  3033. //list, err := models.GetCygxTryOutUserIndustryFllowOpneidByActivityIds(id)
  3034. //if err != nil {
  3035. // br.Msg = "查询openId失败"
  3036. // br.ErrMsg = "查询openId失败,Err:" + err.Error()
  3037. // return
  3038. //}
  3039. var condition string
  3040. var pars []interface{}
  3041. condition = " AND p.STATUS IN ('试用') "
  3042. listmobileShiyong, err := models.GetActivitySpecialOpenIdListMobile(condition, pars)
  3043. if err != nil {
  3044. br.Msg = "查询openId失败"
  3045. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  3046. return
  3047. }
  3048. mapMobileShiyong := make(map[string]string)
  3049. for _, v := range listmobileShiyong {
  3050. mapMobileShiyong[v.Mobile] = v.Mobile
  3051. }
  3052. var mobiles []string
  3053. listFllow, err := cygx.GetCygxForeverUserIndustryFllowOpneidByActivityIds(id)
  3054. if err != nil {
  3055. br.Msg = "查询openId失败"
  3056. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  3057. return
  3058. }
  3059. for _, v := range listFllow {
  3060. if mapMobileShiyong[v.Mobile] != "" {
  3061. mobiles = append(mobiles, v.Mobile)
  3062. }
  3063. }
  3064. list, err := cygx.GetUserRecordListByMobileArr(mobiles)
  3065. if err != nil {
  3066. br.Msg = "查询openId失败"
  3067. br.ErrMsg = "查询openId失败,GetUserRecordListByMobileArr Err:" + err.Error()
  3068. return
  3069. }
  3070. for _, idList := range openIdList {
  3071. idMap[idList.OpenId] = idList.OpenId
  3072. }
  3073. for _, idList := range list {
  3074. if _, ok := idMap[idList.OpenId]; !ok {
  3075. openIdList = append(openIdList, idList)
  3076. idMap[idList.OpenId] = idList.OpenId
  3077. }
  3078. }
  3079. }
  3080. if strings.Contains(req.SendGroup, "7") {
  3081. list, err := cygxService.GetCygxInteractiveUserOpneidByActivityIds(id)
  3082. if err != nil {
  3083. br.Msg = "查询openId失败"
  3084. br.ErrMsg = "查询openId失败,Err:" + err.Error()
  3085. return
  3086. }
  3087. for _, idList := range openIdList {
  3088. idMap[idList.OpenId] = idList.OpenId
  3089. }
  3090. for _, idList := range list {
  3091. if _, ok := idMap[idList.OpenId]; !ok {
  3092. openIdList = append(openIdList, idList)
  3093. idMap[idList.OpenId] = idList.OpenId
  3094. }
  3095. }
  3096. }
  3097. if len(openIdList) > 0 {
  3098. openIdArr := make([]string, len(openIdList))
  3099. for i, v := range openIdList {
  3100. openIdArr[i] = v.OpenId
  3101. }
  3102. sendInfo := new(services.SendWxTemplate)
  3103. //sendInfo.First = req.FirstText
  3104. sendInfo.Keyword1 = req.ActivityName
  3105. sendInfo.Keyword2 = req.Content
  3106. //sendInfo.Keyword3 = meetingTime
  3107. sendInfo.Remark = "点击查看活动详情"
  3108. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  3109. sendInfo.RedirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(id)
  3110. sendInfo.RedirectTarget = 3
  3111. sendInfo.Resource = strconv.Itoa(id)
  3112. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_CUSTOMIZE
  3113. sendInfo.OpenIdArr = openIdArr
  3114. e = services.SendTemplateMsg(sendInfo)
  3115. if e != nil {
  3116. br.Msg = "推送模板消息失败!"
  3117. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  3118. return
  3119. }
  3120. }
  3121. }
  3122. br.Ret = 200
  3123. br.Success = true
  3124. br.Msg = "发送成功"
  3125. }
  3126. // @Title 模版消息发送客户类型列表
  3127. // @Description 模版消息发送客户类型列表接口
  3128. // @Success Ret=200
  3129. // @router /activitySignup/tempMsg/sendGroupList [get]
  3130. func (this *ActivitySignupCoAntroller) SendGroupList() {
  3131. br := new(models.BaseResponse).Init()
  3132. defer func() {
  3133. this.Data["json"] = br
  3134. this.ServeJSON()
  3135. }()
  3136. AdminUser := this.SysUser
  3137. if AdminUser == nil {
  3138. br.Msg = "请登录"
  3139. br.ErrMsg = "请登录,SysUser Is Empty"
  3140. return
  3141. }
  3142. list := make([]cygx.SendGroup, 0)
  3143. list = append(list, cygx.SendGroup{
  3144. Id: 1,
  3145. Name: "全部客户",
  3146. })
  3147. list = append(list, cygx.SendGroup{
  3148. Id: 2,
  3149. Name: "永续客户",
  3150. })
  3151. list = append(list, cygx.SendGroup{
  3152. Id: 3,
  3153. Name: "大套餐客户",
  3154. })
  3155. list = append(list, cygx.SendGroup{
  3156. Id: 4,
  3157. Name: "行业套餐客户",
  3158. })
  3159. list = append(list, cygx.SendGroup{
  3160. Id: 5,
  3161. Name: "其他行业正式客户",
  3162. })
  3163. list = append(list, cygx.SendGroup{
  3164. Id: 6,
  3165. Name: "试用客户",
  3166. })
  3167. list = append(list, cygx.SendGroup{
  3168. Id: 7,
  3169. Name: "已参与互动的客户",
  3170. })
  3171. br.Ret = 200
  3172. br.Success = true
  3173. br.Data = list
  3174. }