activity_meet.go 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681
  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/company"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/models/system"
  12. "hongze/hz_crm_api/services"
  13. "hongze/hz_crm_api/services/alarm_msg"
  14. cygxService "hongze/hz_crm_api/services/cygx"
  15. "hongze/hz_crm_api/utils"
  16. "os"
  17. "path/filepath"
  18. "strconv"
  19. "strings"
  20. "time"
  21. )
  22. // 到会管理
  23. type ActivityMeetCoAntroller struct {
  24. controllers.BaseAuthController
  25. }
  26. // @Title 到会管理列表
  27. // @Description 获取到会管理列表接口
  28. // @Param PageSize query int true "每页数据条数"
  29. // @Param CurrentIndex query int true "当前页页码,从1开始"
  30. // @Param ChartPermissionId query string false "行业id"
  31. // @Param ActivityTypeId query string false "活动类型id "
  32. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  33. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  34. // @Param KeyWord query string false "搜索关键词"
  35. // @Param MeetType query int true "会议类型 1线上、2线下"
  36. // @Param IsResearch query bool true "是否为研选"
  37. // @Success 200 {object} cygx.GetCygxMeetListRep
  38. // @router /activityMeet/list [get]
  39. func (this *ActivityMeetCoAntroller) MeetList() {
  40. br := new(models.BaseResponse).Init()
  41. defer func() {
  42. this.Data["json"] = br
  43. this.ServeJSON()
  44. }()
  45. sysUser := this.SysUser
  46. if sysUser == nil {
  47. br.Msg = "请登录"
  48. br.ErrMsg = "请登录,SysUser Is Empty"
  49. return
  50. }
  51. pageSize, _ := this.GetInt("PageSize")
  52. currentIndex, _ := this.GetInt("CurrentIndex")
  53. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  54. ActivityTypeId := this.GetString("ActivityTypeId")
  55. startDate := this.GetString("StartDate")
  56. endDate := this.GetString("EndDate")
  57. keyWord := this.GetString("KeyWord")
  58. meetType, _ := this.GetInt("MeetType")
  59. isResearch, _ := this.GetBool("IsResearch", false) // 是否为研选 查研观向11.0 (研选活动独立显示)
  60. var startSize int
  61. if pageSize <= 0 {
  62. pageSize = utils.PageSize20
  63. }
  64. if currentIndex <= 0 {
  65. currentIndex = 1
  66. }
  67. startSize = utils.StartIndex(currentIndex, pageSize)
  68. activityIdArr := make([]int, 0)
  69. activityIdArrUpdateTime := make([]int, 0)
  70. var condition string
  71. var pars []interface{}
  72. condition += `AND a.active_state IN (2,3) AND a.publish_status = 1 `
  73. if keyWord != "" {
  74. condition += ` AND (a.activity_name LIKE '%` + keyWord + `%' ) `
  75. }
  76. if meetType == 1 {
  77. condition += ` AND a.activity_type_id IN (1,2,3,7) `
  78. } else {
  79. condition += ` AND a.activity_type_id IN (4,5,6,8) ` //默认
  80. }
  81. if ActivityTypeId != "" {
  82. condition += ` AND a.activity_type_id IN (` + ActivityTypeId + `) `
  83. }
  84. if isResearch {
  85. chartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  86. } else {
  87. condition += ` AND a.chart_permission_id != '` + strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) + `'`
  88. }
  89. //行业名称
  90. if chartPermissionId > 0 {
  91. condition += ` AND a.chart_permission_id = '` + strconv.Itoa(chartPermissionId) + `'`
  92. }
  93. if startDate != "" {
  94. condition += ` AND a.activity_time >= ` + "'" + startDate + " 00:00:00'"
  95. }
  96. if endDate != "" {
  97. condition += ` AND a.activity_time <= ` + "'" + endDate + " 23:59:59'"
  98. }
  99. total, err := cygx.GetCygxMeetCount(condition, pars)
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取失败,Err:" + err.Error()
  103. return
  104. }
  105. condition += ` GROUP BY a.activity_id ORDER BY a.activity_time DESC `
  106. list, errList := cygx.GetCygxMeetListAll(condition, pars, startSize, pageSize)
  107. if errList != nil {
  108. br.Msg = "获取失败"
  109. br.ErrMsg = "获取失败,Err:" + errList.Error()
  110. return
  111. }
  112. page := paging.GetPaging(currentIndex, pageSize, total)
  113. resp := new(cygx.GetCygxMeetListRep)
  114. for k, v := range list {
  115. if v.IsSubmitMeeting == 1 {
  116. list[k].OperationStyle = 2
  117. } else {
  118. list[k].OperationStyle = 1
  119. }
  120. if meetType == 2 {
  121. list[k].MeetPeopleNum = v.OmeetPeopleNum
  122. }
  123. if v.ActivityTypeId == 7 {
  124. list[k].IsCClassMeeting = true
  125. }
  126. activityIdArrUpdateTime = append(activityIdArrUpdateTime, v.ActivityId)
  127. //到会列表按钮展示操作
  128. if v.IsSubmitMeeting == 1 {
  129. //list[k].IsShowAttendanceDetails = true
  130. if meetType == 1 && v.ActivityTypeId == 7 {
  131. //如果C类电话会是手动提交的报名信息,就展示 修改到会情况 按钮
  132. if v.SubmitMeetingType == 1 {
  133. list[k].IsShowUpdateMeeting = true
  134. }
  135. //C类强制展示
  136. list[k].IsShowAttendanceDetails = true
  137. }
  138. //已经提交到会的线下会议都展示 修改到会情况 按钮
  139. if meetType == 2 {
  140. list[k].IsShowUpdateMeeting = true
  141. }
  142. } else {
  143. if list[k].YidongActivityId != "" {
  144. //list[k].ActivityTypeName += utils.YI_DONG_NAME
  145. } else {
  146. //如果是线上
  147. if meetType == 1 {
  148. list[k].IsShowHandMovement = true
  149. //如果 是C类电话会则做下面的处理
  150. if v.ActivityTypeId == 7 {
  151. list[k].IsShowSubmitMeeting = true
  152. }
  153. } else {
  154. list[k].IsShowSubmitMeeting = true
  155. }
  156. }
  157. if v.IsYidongConduct == 1 {
  158. //v.ActivityTypeName += utils.YI_DONG_NAME_TWO
  159. list[k].IsShowSubmitMeeting = true
  160. list[k].IsShowHandMovement = false
  161. }
  162. }
  163. if v.YidongActivityId != "" {
  164. ydUpdateDetil, err := cygx.GetCygxActivityYiDongUpdateTime(v.YidongActivityId)
  165. if err != nil && err.Error() != utils.ErrNoRow() {
  166. br.Msg = "获取失败"
  167. br.ErrMsg = "获取失败,GetCygxActivityYiDongUpdateTime Err:" + err.Error()
  168. return
  169. }
  170. if ydUpdateDetil != nil {
  171. list[k].UpdateTime = ydUpdateDetil.CreateTime
  172. }
  173. activityIdArr = append(activityIdArr, v.ActivityId)
  174. //易懂的到会改为true
  175. if v.IsSubmitMeeting == 1 {
  176. list[k].IsShowAttendanceDetails = true
  177. }
  178. if v.ChartPermissionNameDeputy != "" && v.ChartPermissionNameDeputy != v.ChartPermissionName {
  179. v.ChartPermissionName = v.ChartPermissionNameDeputy // 易董同步过来的活动展示副权限 v11.0
  180. }
  181. }
  182. //判断是否是易董在易董举办的会议
  183. if v.IsYidongConduct == 1 {
  184. list[k].IsShowHandMovement = false
  185. list[k].IsShowSubmitMeeting = false
  186. list[k].IsShowUpdateMeeting = false
  187. }
  188. //是否展示签到码
  189. if (v.ActivityTypeId == 5 || v.ActivityTypeId == 6 || v.ActivityTypeId == 8) && v.SigninImg != "" {
  190. list[k].IsShowSigninButton = true
  191. }
  192. list[k].MeetPeopleNum += v.PotentialPeopleNum //加上潜在客户人数
  193. }
  194. mapUpdateTime, _ := cygxService.GetActivityMeetUpdateTime(activityIdArrUpdateTime) //获取线上活动到会更新时间
  195. //处理易董的活动到会数量
  196. mapYidongMeetNum := make(map[int]int)
  197. if len(activityIdArr) > 0 {
  198. yidongList, err := cygx.GetCygxActivityYiDongMeetNum(activityIdArr)
  199. if err != nil && err.Error() != utils.ErrNoRow() {
  200. br.Msg = "获取失败"
  201. br.ErrMsg = "获取失败,GetCygxActivityYiDongUpdateTime Err:" + err.Error()
  202. return
  203. }
  204. for _, v := range yidongList {
  205. mapYidongMeetNum[v.ActivityId] = v.Num
  206. }
  207. }
  208. for k, v := range list {
  209. if v.ChartPermissionNames != "" {
  210. list[k].ChartPermissionName = v.ChartPermissionNames
  211. }
  212. if v.YidongActivityId != "" {
  213. list[k].MeetPeopleNum = mapYidongMeetNum[v.ActivityId]
  214. list[k].ActivityTypeName += utils.YI_DONG_NAME
  215. }
  216. if v.IsYidongConduct == 1 {
  217. v.ActivityTypeName += utils.YI_DONG_NAME_TWO
  218. }
  219. v.UpdateTime = mapUpdateTime[v.ActivityId]
  220. }
  221. resp.List = list
  222. resp.Paging = page
  223. br.Ret = 200
  224. br.Success = true
  225. br.Msg = "获取成功"
  226. br.Data = resp
  227. }
  228. // @Title 线下报名详情列表
  229. // @Description 获取线下报名详情列表接口
  230. // @Param ActivityId query int true "活动ID"
  231. // @Success 200 {object} cygx.CygxActivitySignupListRep
  232. // @router /activityMeet/offlineListDetail [get]
  233. func (this *ActivityMeetCoAntroller) OfflineListDetail() {
  234. br := new(models.BaseResponse).Init()
  235. defer func() {
  236. this.Data["json"] = br
  237. this.ServeJSON()
  238. }()
  239. sysUser := this.SysUser
  240. if sysUser == nil {
  241. br.Msg = "请登录"
  242. br.ErrMsg = "请登录,SysUser Is Empty"
  243. return
  244. }
  245. activityId, _ := this.GetInt("ActivityId")
  246. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  247. if activityInfo == nil {
  248. br.Msg = "活动不存在"
  249. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  250. return
  251. }
  252. var condition string
  253. condition += ` AND s.is_cancel = 0 AND s.do_fail_type =0 AND s.activity_id = ` + strconv.Itoa(activityId)
  254. list, err := cygx.GetCygxActivitySignup(condition)
  255. if err != nil {
  256. br.Msg = "获取失败"
  257. br.ErrMsg = "获取失败,Err:" + err.Error()
  258. return
  259. }
  260. resp := new(cygx.CygxActivitySignupListRep)
  261. for k, v := range list {
  262. if v.IsMeeting == 1 {
  263. list[k].Operation = true
  264. }
  265. }
  266. resp.List = list
  267. resp.ActivityId = activityId
  268. br.Ret = 200
  269. br.Success = true
  270. br.Msg = "获取成功"
  271. br.Data = resp
  272. }
  273. // @Title 提交线下到会情况
  274. // @Description 提交线下到会情况接口
  275. // @Param request body cygx.MeetingDoRep true "type json string"
  276. // @Success 200 操作成功
  277. // @router /activityMeet/meetingDo [post]
  278. func (this *ActivityMeetCoAntroller) MeetingDo() {
  279. br := new(models.BaseResponse).Init()
  280. defer func() {
  281. this.Data["json"] = br
  282. this.ServeJSON()
  283. }()
  284. AdminUser := this.SysUser
  285. if AdminUser == nil {
  286. br.Msg = "请登录"
  287. br.ErrMsg = "请登录,用户信息为空"
  288. br.Ret = 408
  289. return
  290. }
  291. var req cygx.MeetingDoRep
  292. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  293. if err != nil {
  294. br.Msg = "参数解析异常!"
  295. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  296. return
  297. }
  298. mapMeetingUid := make(map[int]bool)
  299. var userIdArr []int
  300. meetingUids := req.Ids
  301. if len(meetingUids) == 0 {
  302. meetingUids = "0"
  303. } else {
  304. //过滤字段
  305. slice := strings.Split(meetingUids, ",")
  306. meetingUids = ""
  307. for _, v := range slice {
  308. if v != "" {
  309. meetingUids += v + ","
  310. userId, _ := strconv.Atoi(v)
  311. if userId > 0 {
  312. userIdArr = append(userIdArr, userId)
  313. }
  314. mapMeetingUid[userId] = true
  315. }
  316. }
  317. meetingUids = strings.TrimRight(meetingUids, ",")
  318. }
  319. activityId := req.ActivityId
  320. //加入缓存机制,避免同时提交到会信息
  321. redisKey := fmt.Sprint("cygx:activity_meet:batch:activityId:", req.ActivityId)
  322. isExist := utils.Rc.IsExist(redisKey)
  323. if isExist {
  324. br.Msg = "到会详情正在处理,请勿重复提交"
  325. return
  326. } else {
  327. //设置1分钟缓存
  328. utils.Rc.SetNX(redisKey, 1, time.Second*60)
  329. defer func() {
  330. utils.Rc.Delete(redisKey)
  331. }()
  332. }
  333. //加入缓存机制,避免创建同一个名称的指标 end
  334. activityInfo, errInfo := cygx.GetAddActivityInfoById(activityId)
  335. if activityInfo == nil {
  336. br.Msg = "操作失败"
  337. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  338. return
  339. }
  340. if errInfo != nil {
  341. br.Msg = "操作失败"
  342. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  343. return
  344. }
  345. ////校验活动后台管理员、销售是否有修改权限
  346. //havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  347. //if err != nil {
  348. // br.Msg = "获取管理员身份信息失败"
  349. // br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  350. // return
  351. //}
  352. //if !havePower {
  353. // br.Msg = popupMsg
  354. // return
  355. //}
  356. noMeetingUids, err := cygx.GetSignupUserIds(activityId, meetingUids) //未到会的用户ID
  357. if err != nil {
  358. br.Msg = "获取信息失败"
  359. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  360. return
  361. }
  362. var allUids string
  363. if len(noMeetingUids) > 0 {
  364. allUids = noMeetingUids + "," + meetingUids
  365. } else {
  366. allUids = meetingUids
  367. }
  368. listUser, err := cygx.GetUserAndCompanyNameListByUids(allUids)
  369. if err != nil {
  370. br.Msg = "获取失败"
  371. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  372. return
  373. }
  374. var pars []interface{}
  375. var condition string
  376. condition = ` AND activity_id = ? ORDER BY create_time DESC `
  377. pars = append(pars, activityId)
  378. listSigin, err := cygx.GetCygxActivitySigninList(condition, pars)
  379. if err != nil && err.Error() != utils.ErrNoRow() {
  380. br.Msg = "获取失败"
  381. br.ErrMsg = "获取失败,Err:" + err.Error()
  382. return
  383. }
  384. siginMap := make(map[int]string)
  385. for _, v := range listSigin {
  386. siginMap[v.UserId] = v.CreateTime
  387. }
  388. var items []*cygx.CygxActivityOfflineMeetingDetail
  389. var itemDs []*cygx.CygxActivitySignupDetail
  390. for _, v := range listUser {
  391. var item = new(cygx.CygxActivityOfflineMeetingDetail)
  392. item.UserId = v.UserId
  393. item.ActivityId = activityId
  394. item.CreateTime = time.Now()
  395. item.Mobile = v.Mobile
  396. item.Email = v.Email
  397. item.CompanyId = v.CompanyId
  398. item.CompanyName = v.CompanyName
  399. if mapMeetingUid[v.UserId] {
  400. item.IsMeeting = 1
  401. }
  402. //保留扫码通过扫码签到人员的签到时间
  403. if siginMap[v.UserId] != "" {
  404. item.SigninTime = siginMap[v.UserId]
  405. } else {
  406. item.SigninTime = time.Now().Format(utils.FormatDateTime)
  407. }
  408. items = append(items, item)
  409. var itemD = new(cygx.CygxActivitySignupDetail)
  410. itemD.UserId = v.UserId
  411. itemD.RealName = v.RealName
  412. itemD.ActivityId = activityId
  413. itemD.CreateTime = time.Now()
  414. itemD.Mobile = v.Mobile
  415. itemD.CompanyId = v.CompanyId
  416. itemD.CompanyName = v.CompanyName
  417. if mapMeetingUid[v.UserId] {
  418. itemD.IsMeeting = 1
  419. }
  420. itemDs = append(itemDs, itemD)
  421. }
  422. err = cygx.MeetingDo(meetingUids, noMeetingUids, activityId, items)
  423. if err != nil {
  424. br.Msg = "操作失败"
  425. br.ErrMsg = "操作失败,Err:" + err.Error()
  426. return
  427. }
  428. go cygxService.AddCygxActivityRestrictSignupByAdmin(activityId) // 处理爽约记录黑名单限制
  429. go cygxService.AddCygxActivityMeetDetailLogOffline(meetingUids, activityId) // 处理个人以及机构到会数量
  430. go cygxService.AddctivitySignupDetailList(itemDs, activityId) // 处理个人以及机构到会数量
  431. go cygxService.ActivityUserLabelLogAdd(activityId, userIdArr) // 处理用户标签
  432. go cygxService.YanXuanActivityPointsBillSubmitMeeting(activityId, AdminUser.AdminId) // 处理用户到会研选扣点
  433. //添加操作日志记录
  434. br.Ret = 200
  435. br.Success = true
  436. br.Msg = "操作成功"
  437. br.IsAddLog = true
  438. }
  439. // @Title 线下报名到会详情列表
  440. // @Description 获取线下报名到会详情列表接口
  441. // @Param ActivityId query int true "活动ID"
  442. // @Success 200 {object} cygx.CygxActivitySignupListRep
  443. // @router /activityMeet/offlineMeetingList [get]
  444. func (this *ActivityMeetCoAntroller) OfflineMeetingList() {
  445. br := new(models.BaseResponse).Init()
  446. defer func() {
  447. this.Data["json"] = br
  448. this.ServeJSON()
  449. }()
  450. sysUser := this.SysUser
  451. if sysUser == nil {
  452. br.Msg = "请登录"
  453. br.ErrMsg = "请登录,SysUser Is Empty"
  454. return
  455. }
  456. activityId, _ := this.GetInt("ActivityId")
  457. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  458. if activityInfo == nil {
  459. br.Msg = "活动不存在"
  460. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  461. return
  462. }
  463. var condition string
  464. var err error
  465. var list []*cygx.CygxActivitySignupList
  466. condition += ` AND s.activity_id = ` + strconv.Itoa(activityId)
  467. if activityInfo.YidongActivityId != "" {
  468. listMeeting, errMeeting := cygx.GetOfflineMeetingListByYidong(condition)
  469. list = listMeeting
  470. err = errMeeting
  471. } else {
  472. if activityInfo.IsSubmitMeeting == 1 {
  473. condition += " ORDER BY is_meeting DESC ,signin_time DESC , id DESC "
  474. listMeeting, errMeeting := cygx.GetOfflineMeetingList(condition)
  475. list = listMeeting
  476. err = errMeeting
  477. } else {
  478. condition += ` AND s.do_fail_type = 0 `
  479. listNoMeeting, errNoMeeting := cygx.GetCygxActivitySignup(condition)
  480. if errNoMeeting != nil {
  481. br.Msg = "获取失败"
  482. br.ErrMsg = "获取失败,Err:" + errNoMeeting.Error()
  483. return
  484. }
  485. for k := range listNoMeeting {
  486. listNoMeeting[k].Channel = 1
  487. }
  488. list = listNoMeeting
  489. err = errNoMeeting
  490. }
  491. }
  492. if err != nil {
  493. br.Msg = "获取失败"
  494. br.ErrMsg = "获取失败,Err:" + err.Error()
  495. return
  496. }
  497. var mobileArr []string
  498. resp := new(cygx.CygxActivitySignupListRep)
  499. if len(list) == 0 {
  500. list = make([]*cygx.CygxActivitySignupList, 0)
  501. } else {
  502. for k, v := range list {
  503. if v.IsMeeting == 1 {
  504. list[k].Operation = true
  505. }
  506. if activityInfo.YidongActivityId != "" {
  507. list[k].Channel = 1
  508. }
  509. if list[k].Channel == 0 && list[k].IsMeeting == 1 {
  510. list[k].IsAirborne = 1
  511. }
  512. mobileArr = append(mobileArr, v.Mobile)
  513. }
  514. }
  515. mapMobileUser := make(map[string]string)
  516. if len(mobileArr) > 0 {
  517. listUser, err := models.GetWxUserListByUserMobileHaveCompany(mobileArr)
  518. if err != nil {
  519. br.Msg = "获取失败"
  520. br.ErrMsg = "获取失败,GetWxUserListByUserMobileHaveCompany Err:" + err.Error()
  521. return
  522. }
  523. for _, v := range listUser {
  524. mapMobileUser[v.Mobile] = v.RealName
  525. }
  526. for _, v := range list {
  527. v.RealName = mapMobileUser[v.Mobile]
  528. }
  529. }
  530. var pars []interface{}
  531. condition = ` AND activity_id = ? ORDER BY create_time DESC `
  532. pars = append(pars, activityId)
  533. listSigin, err := cygx.GetCygxActivitySigninList(condition, pars)
  534. if err != nil && err.Error() != utils.ErrNoRow() {
  535. br.Msg = "获取失败"
  536. br.ErrMsg = "获取失败,Err:" + err.Error()
  537. return
  538. }
  539. if len(listSigin) == 0 {
  540. resp.ListSignin = make([]*cygx.CygxActivitySignin, 0)
  541. } else {
  542. for _, v := range listSigin {
  543. if v.CompanyId <= 1 {
  544. if v.Mobile == "" {
  545. v.Mobile = v.Email
  546. }
  547. resp.ListSignin = append(resp.ListSignin, v)
  548. }
  549. }
  550. for _, v := range list {
  551. if v.IsMeeting == 0 {
  552. v.SigninTime = ""
  553. }
  554. }
  555. if len(resp.ListSignin) == 0 {
  556. resp.ListSignin = make([]*cygx.CygxActivitySignin, 0)
  557. }
  558. }
  559. resp.List = list
  560. resp.ActivityId = activityId
  561. br.Ret = 200
  562. br.Success = true
  563. br.Msg = "获取成功"
  564. br.Data = resp
  565. }
  566. // @Title 爽约记录
  567. // @Description 获取爽约记录接口
  568. // @Param PageSize query int true "每页数据条数"
  569. // @Param CurrentIndex query int true "当前页页码,从1开始"
  570. // @Param KeyWord query string false "搜索关键词"
  571. // @Param SellerName query string false "销售姓名"
  572. // @Success 200 {object} cygx.GetCygxBreakAppointmentListRep
  573. // @router /activityMeet/breakAppointment [get]
  574. func (this *ActivityMeetCoAntroller) BreakAppointment() {
  575. br := new(models.BaseResponse).Init()
  576. defer func() {
  577. this.Data["json"] = br
  578. this.ServeJSON()
  579. }()
  580. sysUser := this.SysUser
  581. if sysUser == nil {
  582. br.Msg = "请登录"
  583. br.ErrMsg = "请登录,SysUser Is Empty"
  584. return
  585. }
  586. var condition string
  587. pageSize, _ := this.GetInt("PageSize")
  588. currentIndex, _ := this.GetInt("CurrentIndex")
  589. keyWord := this.GetString("KeyWord")
  590. sellerName := this.GetString("SellerName")
  591. var startSize int
  592. if pageSize <= 0 {
  593. pageSize = utils.PageSize20
  594. }
  595. if currentIndex <= 0 {
  596. currentIndex = 1
  597. }
  598. startSize = utils.StartIndex(currentIndex, pageSize)
  599. var pars []interface{}
  600. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  601. respDownload := new(cygx.CanDownload)
  602. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  603. if errAdmin != nil {
  604. br.Msg = "获取失败"
  605. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  606. return
  607. }
  608. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  609. respDownload.IsCanDownload = true
  610. }
  611. var list []*cygx.CygxBreakAppointmentList
  612. var err error
  613. if respDownload.IsCanDownload == false {
  614. //if adminInfo.RoleTypeCode == "rai_group" {
  615. // //组长查看本组所有组员
  616. // condition = ` AND s.user_id IN (SELECT user_id FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(sysUser.AdminId) + ` ) )) `
  617. //} else {
  618. // //组员查看自己
  619. // condition = ` AND s.user_id IN (SELECT user_id FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(sysUser.AdminId) + `) `
  620. //}
  621. //权益申请销售只能看到自己名下的客户的申请
  622. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  623. if err != nil {
  624. br.Msg = "获取失败"
  625. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  626. return
  627. }
  628. var companyIdstr []string
  629. for _, v := range companyIds {
  630. companyIdstr = append(companyIdstr, strconv.Itoa(v))
  631. }
  632. condition += ` AND s.company_id IN (` + strings.Join(companyIdstr, ",") + `) `
  633. }
  634. if keyWord != "" {
  635. condition += ` AND (s.company_name LIKE '%` + keyWord + `%' OR s.mobile LIKE '%` + keyWord + `%') `
  636. }
  637. if sellerName != "" {
  638. condition += ` AND s.seller_name = '` + sellerName + `' `
  639. }
  640. condition += ` AND a.is_limit_people > 0 `
  641. total, err := cygx.GetCygxBreakAppointmentCount(condition, pars)
  642. if err != nil {
  643. br.Msg = "获取失败"
  644. br.ErrMsg = "获取失败,Err:" + err.Error()
  645. return
  646. }
  647. list, err = cygx.GetCygxBreakAppointmentList(condition, pars, startSize, pageSize)
  648. if err != nil {
  649. br.Msg = "获取失败"
  650. br.ErrMsg = "获取失败,Err:" + err.Error()
  651. return
  652. }
  653. for k, v := range list {
  654. if v.IsRestrict > 0 {
  655. list[k].Operation = true
  656. }
  657. sellerName, err := cygx.GetCompanySellerName(v.CompanyId)
  658. if err != nil {
  659. br.Msg = "获取信息失败"
  660. br.ErrMsg = "获取客户信息失败,Err:" + err.Error() + "CompanyId:" + strconv.Itoa(v.CompanyId)
  661. return
  662. }
  663. list[k].SellerName = sellerName
  664. }
  665. page := paging.GetPaging(currentIndex, pageSize, total)
  666. resp := new(cygx.GetCygxBreakAppointmentListRep)
  667. resp.List = list
  668. resp.Paging = page
  669. br.Ret = 200
  670. br.Success = true
  671. br.Msg = "获取成功"
  672. br.Data = resp
  673. }
  674. // @Title 销售姓名列表
  675. // @Description 获取销售姓名列表接口
  676. // @Success 200 {object} cygx.GetCygxSellerNameListRep
  677. // @router /activityMeet/sellerNameList [get]
  678. func (this *ActivityMeetCoAntroller) SellerName() {
  679. br := new(models.BaseResponse).Init()
  680. defer func() {
  681. this.Data["json"] = br
  682. this.ServeJSON()
  683. }()
  684. sysUser := this.SysUser
  685. if sysUser == nil {
  686. br.Msg = "请登录"
  687. br.ErrMsg = "请登录,SysUser Is Empty"
  688. return
  689. }
  690. list, err := cygx.GetCygxSellerNameList()
  691. if err != nil {
  692. br.Msg = "获取失败"
  693. br.ErrMsg = "获取失败,Err:" + err.Error()
  694. return
  695. }
  696. resp := new(cygx.GetCygxSellerNameListRep)
  697. resp.List = list
  698. br.Ret = 200
  699. br.Success = true
  700. br.Msg = "获取成功"
  701. br.Data = resp
  702. }
  703. // @Title 爽约详情
  704. // @Description 获取爽约详情列表接口
  705. // @Param UserId int string true "用户ID"
  706. // @Success 200 {object} cygx.GetCygxActivityBreakAppointmentRep
  707. // @router /activityMeet/breakAppointmentDetail [get]
  708. func (this *ActivityMeetCoAntroller) BreakAppointmentDetail() {
  709. br := new(models.BaseResponse).Init()
  710. defer func() {
  711. this.Data["json"] = br
  712. this.ServeJSON()
  713. }()
  714. sysUser := this.SysUser
  715. if sysUser == nil {
  716. br.Msg = "请登录"
  717. br.ErrMsg = "请登录,SysUser Is Empty"
  718. return
  719. }
  720. userId, _ := this.GetInt("UserId")
  721. detail, err := models.GetWxUserByUserId(userId)
  722. if err != nil {
  723. br.Msg = "操作失败"
  724. br.ErrMsg = "操作失败,Err:" + err.Error()
  725. return
  726. }
  727. list, err := cygx.GetCygxActivityBreakAppointmentList(detail.Mobile)
  728. if err != nil {
  729. br.Msg = "获取失败"
  730. br.ErrMsg = "获取失败,Err:" + err.Error()
  731. return
  732. }
  733. resp := new(cygx.GetCygxActivityBreakAppointmentRep)
  734. resp.List = list
  735. br.Ret = 200
  736. br.Success = true
  737. br.Msg = "获取成功"
  738. br.Data = resp
  739. }
  740. // @Title 报名限制操作
  741. // @Description 报名限制操作接口
  742. // @Param request body cygx.SignUpRestrictUid true "type json string"
  743. // @Success 200 操作成功
  744. // @router /activityMeet/signUpRestrictUid [post]
  745. func (this *ActivityMeetCoAntroller) SignUpRestrict() {
  746. br := new(models.BaseResponse).Init()
  747. defer func() {
  748. this.Data["json"] = br
  749. this.ServeJSON()
  750. }()
  751. AdminUser := this.SysUser
  752. if AdminUser == nil {
  753. br.Msg = "请登录"
  754. br.ErrMsg = "请登录,SysUser Is Empty"
  755. return
  756. }
  757. var req cygx.SignUpRestrictUid
  758. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  759. if err != nil {
  760. br.Msg = "参数解析异常!"
  761. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  762. return
  763. }
  764. uid := req.UserId
  765. total, errTotal := cygx.GetUserBreakAppointmentCount(uid)
  766. if errTotal != nil {
  767. br.Msg = "获取失败"
  768. br.ErrMsg = "获取失败,Err:" + errTotal.Error()
  769. return
  770. }
  771. if total == 0 {
  772. br.Msg = "该用户暂无爽约记录!"
  773. br.ErrMsg = "该用户暂无爽约记录,UserID:" + strconv.Itoa(uid)
  774. return
  775. }
  776. totalRestrictByUid, errRestrictByUid := cygx.GetCygxActivityRestrictSignupCount(uid)
  777. if errRestrictByUid != nil {
  778. br.Msg = "获取失败"
  779. br.ErrMsg = "获取失败,Err:" + errRestrictByUid.Error()
  780. return
  781. }
  782. if totalRestrictByUid == 0 {
  783. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  784. if err != nil {
  785. br.Msg = "获取失败"
  786. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  787. return
  788. }
  789. item := new(cygx.CygxActivityRestrictSignup)
  790. item.UserId = infoUser.UserId
  791. item.CreateTime = time.Now()
  792. item.Mobile = infoUser.Mobile
  793. item.Email = infoUser.Email
  794. item.CompanyId = infoUser.CompanyId
  795. item.CompanyName = infoUser.CompanyName
  796. item.IsRestrict = 1
  797. err = cygx.AddCygxActivityRestrictSignup(item)
  798. if err != nil {
  799. br.Msg = "操作失败"
  800. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  801. return
  802. }
  803. } else {
  804. var newIsRestrict int
  805. detail, err := cygx.GetCygxActivityRestrictSignupInfo(uid)
  806. if err != nil {
  807. br.Msg = "操作失败"
  808. br.ErrMsg = "操作失败,Err:" + err.Error()
  809. return
  810. }
  811. if detail == nil {
  812. br.Msg = "操作失败"
  813. br.ErrMsg = "UserID错误,不存在UserID:"
  814. return
  815. }
  816. if detail.IsRestrict == 0 {
  817. newIsRestrict = 1
  818. } else {
  819. newIsRestrict = 0
  820. }
  821. err = cygx.UpdateCygxActivityRestrictSignup(newIsRestrict, uid)
  822. if err != nil {
  823. br.Msg = "操作失败"
  824. br.ErrMsg = "操作失败,Err:" + err.Error()
  825. return
  826. }
  827. }
  828. //添加操作日志记录
  829. br.Ret = 200
  830. br.Success = true
  831. br.Msg = "操作成功"
  832. br.IsAddLog = true
  833. }
  834. // @Title 线上到会管理详情
  835. // @Description 获取线上到会管理详情接口
  836. // @Param ActivityId query int true "活动ID"
  837. // @Success 200 {object} cygx.GetAppointmentListRep
  838. // @router /activityMeet/appointmentList [get]
  839. func (this *ActivityMeetCoAntroller) AppointmentList() {
  840. br := new(models.BaseResponse).Init()
  841. defer func() {
  842. this.Data["json"] = br
  843. this.ServeJSON()
  844. }()
  845. sysUser := this.SysUser
  846. if sysUser == nil {
  847. br.Msg = "请登录"
  848. br.ErrMsg = "请登录,SysUser Is Empty"
  849. return
  850. }
  851. activityId, _ := this.GetInt("ActivityId")
  852. if activityId < 1 {
  853. br.Msg = "活动不存在"
  854. return
  855. }
  856. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  857. if activityInfo == nil {
  858. br.Msg = "活动不存在"
  859. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  860. return
  861. }
  862. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  863. resp := new(cygx.CanDownload)
  864. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  865. if errAdmin != nil {
  866. br.Msg = "获取失败"
  867. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  868. return
  869. }
  870. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  871. resp.IsCanDownload = true
  872. }
  873. sqlStr := ` AND s.do_fail_type = 0`
  874. memberType := "Admin"
  875. list, err := cygx.GetCygxAppointmentList(activityId, sqlStr)
  876. if err != nil {
  877. br.Msg = "获取失败"
  878. br.ErrMsg = "获取失败,Err:" + err.Error()
  879. return
  880. }
  881. total, errtotal := cygx.GetCygxAppointmentCount(activityId, sqlStr)
  882. if errtotal != nil {
  883. br.Msg = "获取失败"
  884. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  885. return
  886. }
  887. myTotalsqlStr := `AND s.do_fail_type = 0 AND s.user_id IN (SELECT user_id FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(sysUser.AdminId) + `) `
  888. myTotal, errmyTotal := cygx.GetCygxAppointmentCount(activityId, myTotalsqlStr)
  889. if errmyTotal != nil {
  890. br.Msg = "获取失败"
  891. br.ErrMsg = "我的客户总数获取失败,Err:" + errmyTotal.Error()
  892. return
  893. }
  894. for k, v := range list {
  895. list[k].SellerName = v.PsellerName
  896. }
  897. respList := new(cygx.GetAppointmentListRep)
  898. //销售查看自己客户,销售组长查看组员
  899. if resp.IsCanDownload == false {
  900. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  901. if err != nil {
  902. br.Msg = "获取失败"
  903. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  904. return
  905. }
  906. for _, v := range list {
  907. if _, ok := mapMobile[v.Mobile]; ok {
  908. respList.List = append(respList.List, v)
  909. }
  910. }
  911. if adminInfo.RoleTypeCode == "rai_group" {
  912. //组长查看本组所有组员
  913. memberType = "GroupLeader"
  914. } else {
  915. //组员查看自己
  916. memberType = "Sale"
  917. }
  918. } else {
  919. respList.List = list
  920. }
  921. if len(respList.List) == 0 {
  922. respList.List = make([]*cygx.CygxAppointmentList, 0)
  923. }
  924. respList.List = list
  925. respList.Total = total
  926. respList.MyTotal = myTotal
  927. respList.ActivityId = activityId
  928. respList.MemberType = memberType
  929. respList.IsLimitPeople = activityInfo.IsLimitPeople
  930. activityTypeId := activityInfo.ActivityTypeId
  931. if activityTypeId == 1 || activityTypeId == 2 {
  932. respList.ExcelType = "AppointmentCall"
  933. } else if activityTypeId == 5 || activityTypeId == 6 {
  934. respList.ExcelType = "ExpertSalon"
  935. } else if activityTypeId == 3 {
  936. respList.ExcelType = "Teleconference"
  937. } else if activityTypeId == 4 {
  938. respList.ExcelType = "OfflineResearch"
  939. } else if activityTypeId == 7 {
  940. respList.ExcelType = "CClass"
  941. }
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "获取成功"
  945. br.Data = respList
  946. }
  947. // @Title 客户参会记录下载
  948. // @Description 客户参会记录下载
  949. // @Success 200 导出成功
  950. // @router /activityMeet/meetingExport [get]
  951. func (this *ActivityMeetCoAntroller) SignupFailExport() {
  952. br := new(models.BaseResponse).Init()
  953. defer func() {
  954. this.Data["json"] = br
  955. this.ServeJSON()
  956. }()
  957. AdminUser := this.SysUser
  958. if AdminUser == nil {
  959. br.Msg = "请登录"
  960. br.ErrMsg = "请登录,SysUser Is Empty"
  961. return
  962. }
  963. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  964. resp := new(cygx.CanDownload)
  965. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  966. if errAdmin != nil {
  967. br.Msg = "获取失败"
  968. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  969. return
  970. }
  971. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  972. resp.IsCanDownload = true
  973. }
  974. var err error
  975. var condition string
  976. var items []*cygx.MeetingExportRep
  977. list, err := cygx.GetMeetingExportAll(condition)
  978. if err != nil {
  979. br.Msg = "获取失败"
  980. br.ErrMsg = "获取失败,Err:" + err.Error()
  981. return
  982. }
  983. //销售查看自己客户,销售组长查看组员
  984. if resp.IsCanDownload == false {
  985. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  986. if err != nil {
  987. br.Msg = "获取失败"
  988. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  989. return
  990. }
  991. for _, v := range list {
  992. if _, ok := mapMobile[v.Mobile]; ok {
  993. items = append(items, v)
  994. }
  995. }
  996. } else {
  997. items = list
  998. }
  999. //创建excel
  1000. dir, err := os.Executable()
  1001. exPath := filepath.Dir(dir)
  1002. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1003. xlsxFile := xlsx.NewFile()
  1004. if err != nil {
  1005. br.Msg = "生成文件失败"
  1006. br.ErrMsg = "生成文件失败"
  1007. return
  1008. }
  1009. style := xlsx.NewStyle()
  1010. alignment := xlsx.Alignment{
  1011. Horizontal: "center",
  1012. Vertical: "center",
  1013. WrapText: true,
  1014. }
  1015. style.Alignment = alignment
  1016. style.ApplyAlignment = true
  1017. sheet, err := xlsxFile.AddSheet("到会管理名单")
  1018. if err != nil {
  1019. br.Msg = "新增Sheet失败"
  1020. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1021. return
  1022. }
  1023. //标头
  1024. rowTitle := sheet.AddRow()
  1025. cellA := rowTitle.AddCell()
  1026. cellA.Value = "公司名"
  1027. cellB := rowTitle.AddCell()
  1028. cellB.Value = "状态"
  1029. cellC := rowTitle.AddCell()
  1030. cellC.Value = "姓名"
  1031. cellD := rowTitle.AddCell()
  1032. cellD.Value = "手机号"
  1033. cellE := rowTitle.AddCell()
  1034. cellE.Value = "所属销售"
  1035. cellF := rowTitle.AddCell()
  1036. cellF.Value = "活动名称"
  1037. cellG := rowTitle.AddCell()
  1038. cellG.Value = "行业"
  1039. cellH := rowTitle.AddCell()
  1040. cellH.Value = "活动类型"
  1041. cellI := rowTitle.AddCell()
  1042. cellI.Value = "活动时间"
  1043. cellJ := rowTitle.AddCell()
  1044. cellJ.Value = "开通权限"
  1045. for _, item := range items {
  1046. row := sheet.AddRow()
  1047. cellA := row.AddCell()
  1048. cellA.Value = item.CompanyName
  1049. cellB := row.AddCell()
  1050. cellB.Value = item.Status
  1051. cellC := row.AddCell()
  1052. cellC.Value = item.RealName
  1053. cellD := row.AddCell()
  1054. cellD.Value = item.Mobile
  1055. cellE := row.AddCell()
  1056. cellE.Value = item.PsellerName
  1057. cellF := row.AddCell()
  1058. cellF.Value = item.ActivityName
  1059. cellG := row.AddCell()
  1060. cellG.Value = item.ChartPermissionName
  1061. cellH := row.AddCell()
  1062. cellH.Value = item.ActivityTypeName
  1063. cellI := row.AddCell()
  1064. cellI.Value = item.ActivityTimeText
  1065. cellJ := row.AddCell()
  1066. cellJ.Value = item.Permission
  1067. }
  1068. err = xlsxFile.Save(downLoadnFilePath)
  1069. if err != nil {
  1070. br.Msg = "保存文件失败"
  1071. br.ErrMsg = "保存文件失败"
  1072. return
  1073. }
  1074. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1075. downloadFileName := "客户参会记录" + randStr + ".xlsx"
  1076. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1077. defer func() {
  1078. os.Remove(downLoadnFilePath)
  1079. }()
  1080. //添加操作日志记录
  1081. br.Success = true
  1082. br.Ret = 200
  1083. br.Msg = "导出成功"
  1084. br.IsAddLog = true
  1085. }
  1086. // @Title 上传参会表格
  1087. // @Description 上传参会表格数据
  1088. // @Param File query file true "文件"
  1089. // @Param ActivityId query int true "活动ID"
  1090. // @Success 200 Ret=200 导入成功
  1091. // @router /activityMeet/import [post]
  1092. func (this *ActivityMeetCoAntroller) Import() {
  1093. br := new(models.BaseResponse).Init()
  1094. defer func() {
  1095. this.Data["json"] = br
  1096. this.ServeJSON()
  1097. }()
  1098. AdminUser := this.SysUser
  1099. if AdminUser == nil {
  1100. br.Msg = "请重新登录"
  1101. return
  1102. }
  1103. file, h, err := this.GetFile("File")
  1104. if err != nil {
  1105. br.Msg = "获取文件失败"
  1106. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  1107. return
  1108. }
  1109. activityId, _ := this.GetInt("ActivityId")
  1110. if activityId <= 0 {
  1111. br.Msg = "参数错误"
  1112. br.ErrMsg = "活动id为0"
  1113. return
  1114. }
  1115. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  1116. if err != nil {
  1117. br.Msg = "活动不存在"
  1118. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1119. return
  1120. }
  1121. //校验活动后台管理员、销售是否有修改权限
  1122. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  1123. if err != nil {
  1124. br.Msg = "获取管理员身份信息失败"
  1125. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  1126. return
  1127. }
  1128. if !havePower {
  1129. br.Msg = popupMsg
  1130. return
  1131. }
  1132. if activityInfo.ActiveState != 3 && activityInfo.ActiveState != 2 {
  1133. br.Msg = "任务未开始,请稍后上传"
  1134. return
  1135. }
  1136. uploadDir := "static/xls"
  1137. err = os.MkdirAll(uploadDir, 766)
  1138. if err != nil {
  1139. br.Msg = "存储目录创建失败"
  1140. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1141. return
  1142. }
  1143. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  1144. defer file.Close()
  1145. err = this.SaveToFile("File", path)
  1146. if err != nil {
  1147. br.Msg = "文件保存失败"
  1148. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  1149. return
  1150. }
  1151. xlFile, err := xlsx.OpenFile(path)
  1152. if err != nil {
  1153. br.Msg = "文件导入失败"
  1154. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. defer func() {
  1158. os.Remove(path)
  1159. }()
  1160. //允许添加的联系人
  1161. needAddAttendanc := make([]*cygx.CygxActivityAttendanceDetail, 0)
  1162. var mobileStr string
  1163. // 遍历sheet页读取
  1164. realNameKey, mobileKey, companyNameKey, positionKey, firstMeetingTimeKey, lastMeetingTimeKey, durationKey, meetingTypeStrKey, meetingAuthenticationKey, meetingStatusStrKey := -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  1165. for _, sheet := range xlFile.Sheets {
  1166. //遍历行读取
  1167. maxRow := sheet.MaxRow
  1168. for i := 0; i < maxRow; i++ {
  1169. if i == 0 {
  1170. row := sheet.Row(i)
  1171. cells := row.Cells
  1172. for k, cell := range cells {
  1173. text := cell.String()
  1174. if text == "姓名" {
  1175. realNameKey = k
  1176. }
  1177. if text == "电话" {
  1178. mobileKey = k
  1179. }
  1180. if text == "公司" {
  1181. companyNameKey = k
  1182. }
  1183. if text == "职位" {
  1184. positionKey = k
  1185. }
  1186. if text == "首次入会时间" {
  1187. firstMeetingTimeKey = k
  1188. }
  1189. if text == "最后退出时间" {
  1190. lastMeetingTimeKey = k
  1191. }
  1192. if text == "参与总时长(分)" {
  1193. durationKey = k
  1194. }
  1195. if text == "参会方式" {
  1196. meetingTypeStrKey = k
  1197. }
  1198. if text == "参会鉴权" {
  1199. meetingAuthenticationKey = k
  1200. }
  1201. if text == "参会状态" {
  1202. meetingStatusStrKey = k
  1203. }
  1204. }
  1205. }
  1206. if i == 0 {
  1207. if mobileKey == -1 {
  1208. br.Msg = "模板格式错误,缺少:电话"
  1209. br.ErrMsg = "模板格式错误"
  1210. return
  1211. }
  1212. if firstMeetingTimeKey == -1 {
  1213. br.Msg = "模板格式错误,缺少:首次入会时间"
  1214. br.ErrMsg = "模板格式错误!"
  1215. return
  1216. }
  1217. if lastMeetingTimeKey == -1 {
  1218. br.Msg = "模板格式错误,缺少:最后退出时间"
  1219. br.ErrMsg = "模板格式错误!"
  1220. return
  1221. }
  1222. if durationKey == -1 {
  1223. br.Msg = "模板格式错误,缺少:参与总时长"
  1224. br.ErrMsg = "模板格式错误!"
  1225. return
  1226. }
  1227. }
  1228. if i >= 1 {
  1229. row := sheet.Row(i)
  1230. cells := row.Cells
  1231. var realName, mobile, companyName, position, sellerName, firstMeetingTime, lastMeetingTime, duration, meetingTypeStr, meetingAuthentication, meetingStatusStr string
  1232. for k, cell := range cells {
  1233. if k == realNameKey {
  1234. realName = cell.String()
  1235. }
  1236. if k == mobileKey {
  1237. mobile = cell.String()
  1238. //if mobile != "" {
  1239. // fmt.Println(mobile)
  1240. // _, err := strconv.ParseFloat(mobile, 64)
  1241. // if err != nil {
  1242. // br.Msg = "手机号存在非数字类字符!"
  1243. // br.ErrMsg = "手机号存在非数字类字符!err:" + err.Error() + mobile
  1244. // return
  1245. // }
  1246. //}
  1247. }
  1248. if k == companyNameKey {
  1249. companyName = cell.String()
  1250. }
  1251. if k == positionKey {
  1252. position = cell.String()
  1253. }
  1254. if k == firstMeetingTimeKey {
  1255. firstMeetingTime = cell.String()
  1256. }
  1257. if k == lastMeetingTimeKey {
  1258. lastMeetingTime = cell.String()
  1259. }
  1260. if k == durationKey {
  1261. duration = cell.String()
  1262. }
  1263. if k == meetingTypeStrKey {
  1264. meetingTypeStr = cell.String()
  1265. }
  1266. if k == meetingAuthenticationKey {
  1267. meetingAuthentication = cell.String()
  1268. }
  1269. if k == meetingStatusStrKey {
  1270. meetingStatusStr = cell.String()
  1271. }
  1272. }
  1273. //这些字段都没有的话,系统认为excel到底了
  1274. if duration == "" && mobile == "" && firstMeetingTime == "" {
  1275. break
  1276. }
  1277. item := new(cygx.CygxActivityAttendanceDetail)
  1278. item.ActivityId = activityId
  1279. item.RealName = realName
  1280. item.Mobile = mobile
  1281. item.CompanyName = companyName
  1282. item.SellerName = sellerName
  1283. item.FirstMeetingTime = firstMeetingTime
  1284. item.LastMeetingTime = lastMeetingTime
  1285. item.Duration = duration
  1286. item.MeetingTypeStr = meetingTypeStr
  1287. item.MeetingAuthentication = meetingAuthentication
  1288. item.MeetingStatusStr = meetingStatusStr
  1289. item.Position = position
  1290. item.CreateTime = time.Now()
  1291. if mobile != "" {
  1292. mobileStr += "'" + mobile + "'" + ","
  1293. needAddAttendanc = append(needAddAttendanc, item)
  1294. }
  1295. }
  1296. }
  1297. }
  1298. mobileStr = strings.TrimRight(mobileStr, ",")
  1299. if mobileStr == "" {
  1300. mobileStr = "1"
  1301. }
  1302. list, err := cygx.GetWxUserOutboundMobile(mobileStr)
  1303. if err != nil {
  1304. br.Msg = "上传失败"
  1305. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1306. return
  1307. }
  1308. for k, v := range needAddAttendanc {
  1309. for _, v2 := range list {
  1310. if v2.OutboundMobile == v.Mobile {
  1311. needAddAttendanc[k].CompanyId = v2.CompanyId
  1312. }
  1313. }
  1314. }
  1315. err = cygx.AddAttendancDetail(needAddAttendanc, activityId, mobileStr)
  1316. if err != nil {
  1317. br.Msg = "上传失败"
  1318. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  1319. return
  1320. }
  1321. go cygxService.AddCygxActivityRestrictSignupByAdmin(activityId)
  1322. go cygx.AddCygxActivityMeetDetailLogOnline(needAddAttendanc, activityId)
  1323. //添加操作日志记录
  1324. br.Msg = "导入成功"
  1325. br.Ret = 200
  1326. br.Success = true
  1327. br.IsAddLog = true
  1328. }
  1329. // @Title 线上到会详情
  1330. // @Description 获取线上到会详情接口
  1331. // @Param ActivityId query int true "活动ID"
  1332. // @Success 200 {object} cygx.AttendanceDetailList
  1333. // @router /activityMeet/attendanceDetail [get]
  1334. func (this *ActivityMeetCoAntroller) AttendanceDetail() {
  1335. br := new(models.BaseResponse).Init()
  1336. defer func() {
  1337. this.Data["json"] = br
  1338. this.ServeJSON()
  1339. }()
  1340. sysUser := this.SysUser
  1341. if sysUser == nil {
  1342. br.Msg = "请登录"
  1343. br.ErrMsg = "请登录,SysUser Is Empty"
  1344. return
  1345. }
  1346. activityId, _ := this.GetInt("ActivityId")
  1347. if activityId < 1 {
  1348. br.Msg = "活动不存在"
  1349. return
  1350. }
  1351. activityInfo, _ := cygx.GetAddActivityInfoById(activityId)
  1352. if activityInfo == nil {
  1353. br.Msg = "活动不存在"
  1354. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  1355. return
  1356. }
  1357. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1358. resp := new(cygx.CanDownload)
  1359. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  1360. if errAdmin != nil {
  1361. br.Msg = "获取失败"
  1362. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  1363. return
  1364. }
  1365. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  1366. resp.IsCanDownload = true
  1367. }
  1368. var condition string
  1369. var condition2 string
  1370. //同一用户上传多次参会记录时,到会与未到会分开查询
  1371. list1, err := cygx.GetAttendanceDetailListGroup(activityId, condition+` AND s.is_meeting = 1 AND d.userid_entity != 3 GROUP BY s.user_id `)
  1372. if err != nil {
  1373. br.Msg = "获取失败"
  1374. br.ErrMsg = "获取失败,Err:" + err.Error()
  1375. return
  1376. }
  1377. listGroup, err := cygx.GetAttendanceDetailListGroup(activityId, condition+` AND s.is_meeting = 0 GROUP BY s.user_id `)
  1378. if err != nil {
  1379. br.Msg = "获取失败"
  1380. br.ErrMsg = "获取失败,Err:" + err.Error()
  1381. return
  1382. }
  1383. var sellerCompanyIds []int
  1384. if len(listGroup) > 0 {
  1385. for _, v := range listGroup {
  1386. list1 = append(list1, v)
  1387. }
  1388. }
  1389. mobileStr := ""
  1390. for _, v := range list1 {
  1391. if v.OutboundMobile != "" {
  1392. mobileStr += v.OutboundMobile + ","
  1393. }
  1394. if v.Mobile != "" {
  1395. mobileStr += v.Mobile + ","
  1396. }
  1397. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1398. }
  1399. mobileStr = strings.TrimRight(mobileStr, ",")
  1400. if mobileStr == "" {
  1401. mobileStr = "1"
  1402. }
  1403. condition2 += ` AND d.mobile NOT IN ( ` + mobileStr + ` ) `
  1404. list2, err := cygx.GetAttendanceDetailList2(activityId, condition2+` AND d.company_id > 1 `)
  1405. if err != nil {
  1406. br.Msg = "获取失败"
  1407. br.ErrMsg = "获取失败,Err:" + err.Error()
  1408. return
  1409. }
  1410. listNoAppointment, err := cygx.GetAttendanceDetailList2(activityId, ` AND d.mobile NOT IN ( `+mobileStr+` ) `+` AND d.company_id > 1 `) //未预约 所有
  1411. if err != nil {
  1412. br.Msg = "获取失败"
  1413. br.ErrMsg = "获取失败,Err:" + err.Error()
  1414. return
  1415. }
  1416. for _, v := range listNoAppointment {
  1417. if v.Mobile != "" {
  1418. mobileStr += "," + v.Mobile
  1419. }
  1420. }
  1421. //不在公司客户体系里面的也算潜在客户,通过手机号来排除 潜在客户不做权限判断
  1422. mobileStr = strings.TrimLeft(mobileStr, ",")
  1423. condition2 = ` AND d.real_name NOT LIKE '%专家%' AND d.mobile NOT IN ( ` + mobileStr + ` ) `
  1424. var isBloneSell bool //是否属于销售添加
  1425. var isProhibit bool // 是否禁止展示
  1426. if activityInfo.AdminId > 0 {
  1427. adminInfoActivity, errAdmin := system.GetSysUserById(activityInfo.AdminId)
  1428. if errAdmin != nil && errAdmin.Error() != utils.ErrNoRow() {
  1429. br.Msg = "获取失败"
  1430. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  1431. return
  1432. }
  1433. if adminInfoActivity != nil {
  1434. roleTypeCode := adminInfoActivity.RoleTypeCode
  1435. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1436. isBloneSell = true
  1437. }
  1438. //如果这个活动属于销售创建,而且不是这个销售自己查看的,并且查看的角色不属于管理员或者权益管理员,那么就做限制处理
  1439. if isBloneSell && sysUser.AdminId != adminInfoActivity.AdminId && (sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  1440. isProhibit = true //限制又取消了。2023-06-14 ,2024.09.04又开启了
  1441. }
  1442. }
  1443. }
  1444. list3, err := cygx.GetAttendanceDetailList3(activityId, condition2)
  1445. if err != nil {
  1446. br.Msg = "获取失败"
  1447. br.ErrMsg = "获取失败,Err:" + err.Error()
  1448. return
  1449. }
  1450. for k, v := range list1 {
  1451. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  1452. list1[k].FirstMeetingTime = ""
  1453. list1[k].LastMeetingTime = ""
  1454. }
  1455. }
  1456. for k, v := range list2 {
  1457. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  1458. list2[k].FirstMeetingTime = ""
  1459. list2[k].LastMeetingTime = ""
  1460. }
  1461. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  1462. }
  1463. //获取公司ID所对应的销售名称
  1464. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  1465. for k, v := range list1 {
  1466. list1[k].SellerName = sellNameMap[v.CompanyId]
  1467. }
  1468. for k, v := range list2 {
  1469. list2[k].SellerName = sellNameMap[v.CompanyId]
  1470. }
  1471. mobileStr = ""
  1472. for k, v := range list3 {
  1473. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  1474. list3[k].FirstMeetingTime = ""
  1475. list3[k].LastMeetingTime = ""
  1476. }
  1477. if v.Mobile != "" {
  1478. mobileStr += v.Mobile + ","
  1479. }
  1480. }
  1481. mapRemark := make(map[string]string)
  1482. if isProhibit {
  1483. list3 = make([]*cygx.AttendanceDetail, 0)
  1484. } else {
  1485. mobileStr = strings.TrimRight(mobileStr, ",")
  1486. if mobileStr != "" {
  1487. listRemark, err := cygx.GetCygxActivityUserRemarksLlistByActivityId(mobileStr, activityId)
  1488. if err != nil && err.Error() != utils.ErrNoRow() {
  1489. br.Msg = "获取信息失败"
  1490. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. for _, v := range listRemark {
  1494. if mapRemark[v.Mobile] == "" {
  1495. mapRemark[v.Mobile] = v.Content
  1496. }
  1497. }
  1498. for k, v := range list3 {
  1499. if mapRemark[v.Mobile] != "" {
  1500. list3[k].Content = mapRemark[v.Mobile]
  1501. }
  1502. }
  1503. }
  1504. }
  1505. //添加浏览记录
  1506. item := new(cygx.CygxActivityMeetingHistory)
  1507. item.ActivityId = activityId
  1508. item.AdminId = sysUser.AdminId
  1509. item.RealName = sysUser.RealName
  1510. item.RoleTypeCode = sysUser.RoleTypeCode
  1511. item.CreateTime = time.Now()
  1512. err = cygx.AddCygxActivityMeetingHistory(item)
  1513. resplist := new(cygx.AttendanceDetailList)
  1514. if resp.IsCanDownload == false {
  1515. //var conditionMobile string
  1516. //if adminInfo.RoleTypeCode == "rai_group" {
  1517. // //组长查看本组所有组员
  1518. // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(sysUser.AdminId) + ` )) `
  1519. //} else {
  1520. // //组员查看自己
  1521. // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(sysUser.AdminId)
  1522. //}
  1523. //mobileList, err := cygx.GetSellerUserMobile(conditionMobile)
  1524. //if err != nil {
  1525. // br.Msg = "获取失败"
  1526. // br.ErrMsg = "获取失败,GetSellerUserMobile Err:" + err.Error()
  1527. // return
  1528. //}
  1529. mapUserMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  1530. if err != nil {
  1531. br.Msg = "获取失败"
  1532. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  1533. return
  1534. }
  1535. //mapUserMobile := make(map[string]string)
  1536. //for _, v := range mobileList {
  1537. // mapUserMobile[v.Mobile] = v.Mobile
  1538. //}
  1539. for _, v := range list1 {
  1540. if _, ok := mapUserMobile[v.Mobile]; ok {
  1541. resplist.List1 = append(resplist.List1, v)
  1542. }
  1543. }
  1544. for _, v := range list2 {
  1545. if _, ok := mapUserMobile[v.Mobile]; ok {
  1546. resplist.List2 = append(resplist.List2, v)
  1547. }
  1548. }
  1549. } else {
  1550. resplist.List1 = list1
  1551. resplist.List2 = list2
  1552. }
  1553. resplist.List3 = list3
  1554. br.Ret = 200
  1555. br.Success = true
  1556. br.Msg = "获取成功"
  1557. br.Data = resplist
  1558. }
  1559. // @Title 线上活动进门财经关联匹配列表
  1560. // @Description 获取线上活动进门财经关联匹配列表接口
  1561. // @Param KeyWord query string false "搜索关键词"
  1562. // @Param ActivityId query int false "搜索关键词"
  1563. // @Success 200 {object} cygx.RoadshowDataTitleList
  1564. // @router /activityMeet/matchingList [get]
  1565. func (this *ActivityMeetCoAntroller) MatchingList() {
  1566. br := new(models.BaseResponse).Init()
  1567. defer func() {
  1568. this.Data["json"] = br
  1569. this.ServeJSON()
  1570. }()
  1571. sysUser := this.SysUser
  1572. if sysUser == nil {
  1573. br.Msg = "请登录"
  1574. br.ErrMsg = "请登录,SysUser Is Empty"
  1575. return
  1576. }
  1577. keyWord := this.GetString("KeyWord")
  1578. if keyWord == "" {
  1579. br.Msg = "请输入搜索内容"
  1580. return
  1581. }
  1582. activityId, _ := this.GetInt("ActivityId")
  1583. detail, err := cygx.GetAddActivityInfoById(activityId)
  1584. if err != nil {
  1585. br.Msg = "活动不存在"
  1586. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1587. return
  1588. }
  1589. dateTime := detail.ActivityTime
  1590. dateTime = utils.TimeRemoveHms2(dateTime)
  1591. startTime := dateTime + " 00:00:00'"
  1592. endTime := dateTime + " 23:59:59'"
  1593. list, err := cygx.GetRoadshowDataTitleList(startTime, endTime, keyWord)
  1594. if err != nil && err.Error() != utils.ErrNoRow() {
  1595. br.Msg = "获取信息失败"
  1596. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1597. return
  1598. }
  1599. resplist := new(cygx.RoadshowDataTitleList)
  1600. for k, v := range list {
  1601. list[k].ActivityTime = utils.StrTimeToTime(v.ActivityTime).Format(utils.FormatDate)
  1602. nameSlice := strings.Split(v.RoadshowTitle, "|")
  1603. var activityName string
  1604. if len(nameSlice) > 1 {
  1605. activityName = nameSlice[len(nameSlice)-1]
  1606. //activityName = strings.Replace(activityName, " ", "", -1)
  1607. }
  1608. if activityName != "" {
  1609. list[k].RoadshowTitle = activityName
  1610. }
  1611. }
  1612. param := new(cygxService.GetYiDongActivityByApiReq)
  1613. param.MeetingStatus = "2"
  1614. param.ConveneStartStr = dateTime
  1615. param.ConveneEndStr = dateTime
  1616. actList := cygxService.GetYiDongActivityListByApi(param)
  1617. for _, v := range actList {
  1618. if strings.Contains(v.Title, keyWord) {
  1619. item := new(cygx.RoadshowDataTitle)
  1620. item.RoadshowTitle = v.Title
  1621. item.ActivityTime = dateTime
  1622. list = append(list, item)
  1623. }
  1624. }
  1625. resplist.List = list
  1626. br.Ret = 200
  1627. br.Success = true
  1628. br.Msg = "获取成功"
  1629. br.Data = resplist
  1630. }
  1631. // @Title 手动匹配线上客户参会记录
  1632. // @Description 手动匹配线上客户参会记录接口
  1633. // @Param request body cygx.RoadshowDataTitleResp true "type json string"
  1634. // @Success 200 操作成功
  1635. // @router /activityMeet/matchingByHand [post]
  1636. func (this *ActivityMeetCoAntroller) MatchingByHand() {
  1637. br := new(models.BaseResponse).Init()
  1638. defer func() {
  1639. this.Data["json"] = br
  1640. this.ServeJSON()
  1641. }()
  1642. AdminUser := this.SysUser
  1643. if AdminUser == nil {
  1644. br.Msg = "请登录"
  1645. br.ErrMsg = "请登录,SysUser Is Empty"
  1646. return
  1647. }
  1648. var req cygx.RoadshowDataTitleResp
  1649. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1650. if err != nil {
  1651. br.Msg = "参数解析异常!"
  1652. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1653. return
  1654. }
  1655. var mobileStr string
  1656. var userIdArr []int
  1657. activityId := req.ActivityId
  1658. keyWord := req.KeyWord
  1659. slice := strings.Split(keyWord, "{|}")
  1660. detail, err := cygx.GetAddActivityInfoById(activityId)
  1661. if err != nil {
  1662. br.Msg = "活动不存在"
  1663. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1664. return
  1665. }
  1666. //校验活动后台管理员、销售是否有修改权限
  1667. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, detail)
  1668. if err != nil {
  1669. br.Msg = "获取管理员身份信息失败"
  1670. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  1671. return
  1672. }
  1673. if !havePower {
  1674. br.Msg = popupMsg
  1675. return
  1676. }
  1677. var condition string
  1678. dateTime := detail.ActivityTime
  1679. dateTime = utils.TimeRemoveHms2(dateTime)
  1680. param := new(cygxService.GetYiDongActivityByApiReq)
  1681. param.MeetingStatus = "2"
  1682. param.ConveneStartStr = dateTime
  1683. param.ConveneEndStr = dateTime
  1684. actList := cygxService.GetYiDongActivityListByApi(param)
  1685. var ismatch bool // 是否匹配
  1686. //优先匹配易董的活动
  1687. if len(actList) > 0 {
  1688. for _, v := range actList {
  1689. var newActivityName string
  1690. titleSlice := strings.Split(v.Title, "】")
  1691. for _, vt := range titleSlice {
  1692. newActivityName = strings.Replace(vt, "-", "", -1)
  1693. newActivityName = strings.Replace(newActivityName, "-", "", -1)
  1694. newActivityName = strings.Replace(newActivityName, "—", "", -1)
  1695. newActivityName = strings.Replace(newActivityName, " ", "", -1)
  1696. newActivityName = strings.Replace(newActivityName, ":", "", -1)
  1697. }
  1698. //如果活动时间一致,而且标题还还包含关键词就建立匹配关系
  1699. if strings.Contains(detail.ActivityNameTask, newActivityName) && detail.ActivityTime == v.Start {
  1700. err = cygx.UpdateCygxActivityyidongActivityId(v.ID, activityId)
  1701. if err != nil {
  1702. br.Msg = "手动归类失败"
  1703. br.ErrMsg = "建立易董活动匹配关系失败,UpdateCygxActivityyidongActivityId Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1704. return
  1705. }
  1706. ismatch = true
  1707. go cygxService.GetYiDongActivityMeeting(v.ID, activityId)
  1708. break
  1709. }
  1710. }
  1711. }
  1712. if !ismatch {
  1713. condition += ` AND roadshow_begin_time >= ` + "'" + dateTime + " 00:00:00'"
  1714. condition += ` AND roadshow_begin_time <= ` + "'" + dateTime + " 23:59:59'"
  1715. if len(slice) > 0 {
  1716. keyWord = slice[0]
  1717. }
  1718. if keyWord != "" {
  1719. list, err := cygx.GetRoadshowDataList(keyWord, condition)
  1720. if err != nil {
  1721. br.Msg = "手动归类失败"
  1722. br.ErrMsg = "获取进门财经数据失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1723. return
  1724. }
  1725. var roadshowId string
  1726. for _, v := range list {
  1727. if v.RoadshowId != "" {
  1728. roadshowId = v.RoadshowId
  1729. break
  1730. }
  1731. }
  1732. needAddAttendanc := make([]*cygx.CygxActivityAttendanceDetail, 0)
  1733. if len(list) > 0 {
  1734. err = cygx.UpdateActivityRoadshowTitle(activityId, keyWord, roadshowId)
  1735. if err != nil {
  1736. br.Msg = "手动归类失败"
  1737. br.ErrMsg = "关联匹配类型失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1738. return
  1739. }
  1740. for _, v := range list {
  1741. if v.UserPhone != "" {
  1742. item := new(cygx.CygxActivityAttendanceDetail)
  1743. item.ActivityId = activityId
  1744. item.RealName = v.UserName
  1745. item.Mobile = v.UserPhone
  1746. item.CompanyName = v.Company
  1747. //item.SellerName = sellerName
  1748. item.FirstMeetingTime = v.FirstWatchTime
  1749. item.LastMeetingTime = v.LastWatchTime
  1750. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  1751. if v.JoinType == 1 {
  1752. item.MeetingTypeStr = "网络"
  1753. } else {
  1754. item.MeetingTypeStr = "电话"
  1755. }
  1756. item.MeetingAuthentication = v.AuthInfo
  1757. if v.DataType == 1 {
  1758. item.MeetingStatusStr = "直播"
  1759. } else {
  1760. item.MeetingStatusStr = "回放"
  1761. }
  1762. item.Position = v.Occupation
  1763. item.UseridEntity = v.UseridEntity
  1764. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  1765. item.CreateTime = time.Now()
  1766. mobileStr += "'" + v.UserPhone + "'" + ","
  1767. needAddAttendanc = append(needAddAttendanc, item)
  1768. }
  1769. }
  1770. mobileStr = strings.TrimRight(mobileStr, ",")
  1771. if mobileStr == "" {
  1772. mobileStr = "1"
  1773. }
  1774. listUser, err := cygx.GetWxUserOutboundMobile(mobileStr)
  1775. if err != nil {
  1776. br.Msg = "手动归类失败!"
  1777. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  1778. return
  1779. }
  1780. for _, v := range listUser {
  1781. userIdArr = append(userIdArr, v.UserId)
  1782. }
  1783. for k, v := range needAddAttendanc {
  1784. for _, v2 := range listUser {
  1785. if v2.OutboundMobile == v.Mobile {
  1786. needAddAttendanc[k].CompanyId = v2.CompanyId
  1787. needAddAttendanc[k].SellerName = v2.SellerName
  1788. needAddAttendanc[k].CompanyName = v2.CompanyName
  1789. needAddAttendanc[k].IsMeetingStr = 1
  1790. }
  1791. }
  1792. }
  1793. err = cygx.AddAttendancDetail(needAddAttendanc, activityId, mobileStr)
  1794. if err != nil {
  1795. br.Msg = "手动归类失败"
  1796. br.ErrMsg = "手动归类失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1797. return
  1798. }
  1799. go cygxService.AddCygxActivityRestrictSignupByAdmin(activityId)
  1800. go cygx.AddCygxActivityMeetDetailLogOnline(needAddAttendanc, activityId)
  1801. go cygxService.ActivityUserLabelLogAdd(activityId, userIdArr) //添加用户活动到会标签到Redis
  1802. go cygxService.AddctivitySignupDetailListByHand(needAddAttendanc, activityId) //手动匹配进门财经信息
  1803. } else {
  1804. br.Msg = "手动归类失败"
  1805. br.ErrMsg = "暂未找到匹配数据!"
  1806. return
  1807. }
  1808. }
  1809. }
  1810. //添加操作日志记录
  1811. br.Ret = 200
  1812. br.Success = true
  1813. br.Msg = "操作成功"
  1814. br.IsAddLog = true
  1815. }
  1816. // @Title 下载客户参会记录
  1817. // @Description 下载客户参会记录接口
  1818. // @Param CompanyId query int true "公司ID"
  1819. // @Param MeetType query int true "参会方式 1线上,2线下 默认为线上"
  1820. // @Success Ret=200
  1821. // @router /activityMeet/companyHistory [get]
  1822. func (this *ActivityMeetCoAntroller) CompanyHisory() {
  1823. br := new(models.BaseResponse).Init()
  1824. var err error
  1825. defer func() {
  1826. this.Data["json"] = br
  1827. this.ServeJSON()
  1828. if err != nil {
  1829. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+"下载客户参会记录失败"+err.Error(), 3)
  1830. }
  1831. }()
  1832. sysUser := this.SysUser
  1833. if sysUser == nil {
  1834. br.Msg = "请登录"
  1835. br.ErrMsg = "请登录,SysUser Is Empty"
  1836. return
  1837. }
  1838. companyId, _ := this.GetInt("CompanyId")
  1839. meetType, _ := this.GetInt("MeetType")
  1840. if companyId < 1 {
  1841. br.Msg = "请输入公司ID"
  1842. return
  1843. }
  1844. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1845. var isCanDownload bool
  1846. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  1847. if err != nil {
  1848. br.Msg = "获取失败"
  1849. br.ErrMsg = "获取失败,Err:" + err.Error()
  1850. return
  1851. }
  1852. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  1853. isCanDownload = true
  1854. }
  1855. if !isCanDownload {
  1856. br.Msg = "暂无下载权限"
  1857. return
  1858. }
  1859. //获取企业客户信息
  1860. companyInfo, err := company.GetCompanyById(companyId)
  1861. if err != nil {
  1862. br.Msg = "获取失败"
  1863. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1864. return
  1865. }
  1866. var list []*cygx.CompanyMeetRep
  1867. mobiles, err := models.GetCompanyUserMobilesByCompanyId(companyId)
  1868. if err != nil && err.Error() != utils.ErrNoRow() {
  1869. br.Msg = "获取信息失败"
  1870. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1871. return
  1872. }
  1873. var meetTypeName string
  1874. if mobiles != "" {
  1875. mobiles = strings.Replace(mobiles, ",", "','", -1)
  1876. mobiles = "'" + mobiles + "'"
  1877. if meetType != 2 {
  1878. list, err = cygx.GetCygxActivityAttendanceDetailByCompanyId(mobiles)
  1879. meetTypeName = "线上"
  1880. } else {
  1881. list, err = cygx.GetCygxActivityOfflineMeetingDetailByCompanyId(mobiles)
  1882. meetTypeName = "线下"
  1883. }
  1884. }
  1885. if err != nil && err.Error() != utils.ErrNoRow() {
  1886. br.Msg = "获取信息失败"
  1887. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1888. return
  1889. }
  1890. //创建excel
  1891. dir, err := os.Executable()
  1892. exPath := filepath.Dir(dir)
  1893. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1894. xlsxFile := xlsx.NewFile()
  1895. if err != nil {
  1896. br.Msg = "生成文件失败"
  1897. br.ErrMsg = "生成文件失败"
  1898. return
  1899. }
  1900. style := xlsx.NewStyle()
  1901. alignment := xlsx.Alignment{
  1902. Horizontal: "center",
  1903. Vertical: "center",
  1904. WrapText: true,
  1905. }
  1906. style.Alignment = alignment
  1907. style.ApplyAlignment = true
  1908. sheet, err := xlsxFile.AddSheet(meetTypeName + "参会记录统计")
  1909. if err != nil {
  1910. br.Msg = "新增Sheet失败"
  1911. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1912. return
  1913. }
  1914. //标头
  1915. rowTitle := sheet.AddRow()
  1916. cellA := rowTitle.AddCell()
  1917. cellA.Value = "姓名"
  1918. cellB := rowTitle.AddCell()
  1919. cellB.Value = "手机号/邮箱"
  1920. cellC := rowTitle.AddCell()
  1921. cellC.Value = "活动名称"
  1922. cellD := rowTitle.AddCell()
  1923. cellD.Value = "所属行业"
  1924. cellE := rowTitle.AddCell()
  1925. cellE.Value = "活动类型"
  1926. cellF := rowTitle.AddCell()
  1927. cellF.Value = "活动主题"
  1928. cellG := rowTitle.AddCell()
  1929. cellG.Value = "活动时间"
  1930. if meetType != 2 {
  1931. cellH := rowTitle.AddCell()
  1932. cellH.Value = "首次入会时间"
  1933. cellI := rowTitle.AddCell()
  1934. cellI.Value = "最后退出时间"
  1935. cellJ := rowTitle.AddCell()
  1936. cellJ.Value = "参与总时长"
  1937. cellK := rowTitle.AddCell()
  1938. cellK.Value = "参会方式"
  1939. cellL := rowTitle.AddCell()
  1940. cellL.Value = "参会鉴权"
  1941. cellM := rowTitle.AddCell()
  1942. cellM.Value = "参会状态"
  1943. }
  1944. for _, item := range list {
  1945. row := sheet.AddRow()
  1946. cellA := row.AddCell()
  1947. cellA.Value = item.RealName
  1948. cellB := row.AddCell()
  1949. cellB.Value = item.Mobile
  1950. if item.Mobile == "" {
  1951. cellB.Value = item.Email
  1952. }
  1953. cellC := row.AddCell()
  1954. cellC.Value = item.ActivityName
  1955. cellD := row.AddCell()
  1956. cellD.Value = item.ChartPermissionName
  1957. cellE := row.AddCell()
  1958. cellE.Value = item.ActivityTypeName
  1959. cellF := row.AddCell()
  1960. cellF.Value = item.Label
  1961. cellG := row.AddCell()
  1962. cellG.Value = item.ActivityTime
  1963. cellH := row.AddCell()
  1964. if meetType != 2 {
  1965. cellH.Value = item.FirstMeetingTime
  1966. cellI := row.AddCell()
  1967. cellI.Value = item.LastMeetingTime
  1968. cellJ := row.AddCell()
  1969. cellJ.Value = item.Duration
  1970. cellK := row.AddCell()
  1971. cellK.Value = item.MeetingTypeStr
  1972. cellL := row.AddCell()
  1973. cellL.Value = item.MeetingAuthentication
  1974. cellM := row.AddCell()
  1975. cellM.Value = item.MeetingStatusStr
  1976. }
  1977. }
  1978. err = xlsxFile.Save(downLoadnFilePath)
  1979. if err != nil {
  1980. br.Msg = "保存文件失败"
  1981. br.ErrMsg = "保存文件失败"
  1982. return
  1983. }
  1984. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1985. downloadFileName := companyInfo.CompanyName + meetTypeName + "参会记录" + randStr + ".xlsx"
  1986. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1987. defer func() {
  1988. os.Remove(downLoadnFilePath)
  1989. }()
  1990. //添加操作日志记录
  1991. br.Ret = 200
  1992. br.Success = true
  1993. br.Msg = "导出成功"
  1994. br.IsAddLog = true
  1995. }
  1996. // @Title 下载客户参会月度统计记录
  1997. // @Description 下载客户参会月度统计记录接口
  1998. // @Param CompanyId query int true "公司ID"
  1999. // @Param MeetType query int true "参会方式 1线上,2线下 默认为线上"
  2000. // @Success Ret=200
  2001. // @router /activityMeet/companyCoount [get]
  2002. func (this *ActivityMeetCoAntroller) CompanyCoount() {
  2003. br := new(models.BaseResponse).Init()
  2004. defer func() {
  2005. this.Data["json"] = br
  2006. this.ServeJSON()
  2007. }()
  2008. sysUser := this.SysUser
  2009. if sysUser == nil {
  2010. br.Msg = "请登录"
  2011. br.ErrMsg = "请登录,SysUser Is Empty"
  2012. return
  2013. }
  2014. companyId, _ := this.GetInt("CompanyId")
  2015. meetType, _ := this.GetInt("MeetType")
  2016. if companyId < 1 {
  2017. br.Msg = "请输入公司ID"
  2018. return
  2019. }
  2020. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  2021. var isCanDownload bool
  2022. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  2023. if err != nil {
  2024. br.Msg = "获取失败"
  2025. br.ErrMsg = "获取失败,Err:" + err.Error()
  2026. return
  2027. }
  2028. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  2029. isCanDownload = true
  2030. }
  2031. if !isCanDownload {
  2032. br.Msg = "暂无下载权限"
  2033. return
  2034. }
  2035. //获取企业客户信息
  2036. companyInfo, err := company.GetCompanyById(companyId)
  2037. if err != nil {
  2038. br.Msg = "获取失败"
  2039. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  2040. return
  2041. }
  2042. var list []*cygx.CompanyMeetRep
  2043. listDate, err := cygx.GetCompanyAciviytyGroupDate()
  2044. if err != nil {
  2045. br.Msg = "获取失败"
  2046. br.ErrMsg = "获取失败,Err:" + err.Error()
  2047. return
  2048. }
  2049. dateMap := make(map[string]int)
  2050. permissionNameMap := make(map[string]int)
  2051. var meetTypeName string
  2052. if meetType != 2 {
  2053. list, err = cygx.GetCompanyActivityCount(companyId)
  2054. meetTypeName = "线上"
  2055. } else {
  2056. list, err = cygx.GetCygxActivityOfflineMeetingCoount(companyId)
  2057. meetTypeName = "线下"
  2058. }
  2059. if err != nil {
  2060. br.Msg = "获取失败"
  2061. br.ErrMsg = "获取失败,Err:" + err.Error()
  2062. return
  2063. }
  2064. for _, v := range list {
  2065. if dateMap[v.ActivityTime] == 0 {
  2066. dateMap[v.ActivityTime] = 1
  2067. } else {
  2068. dateMap[v.ActivityTime] += 1
  2069. }
  2070. if permissionNameMap[v.ActivityTime+v.ChartPermissionName] == 0 {
  2071. permissionNameMap[v.ActivityTime+v.ChartPermissionName] = 1
  2072. } else {
  2073. permissionNameMap[v.ActivityTime+v.ChartPermissionName] += 1
  2074. }
  2075. }
  2076. //创建excel
  2077. dir, err := os.Executable()
  2078. exPath := filepath.Dir(dir)
  2079. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2080. xlsxFile := xlsx.NewFile()
  2081. if err != nil {
  2082. br.Msg = "生成文件失败"
  2083. br.ErrMsg = "生成文件失败"
  2084. return
  2085. }
  2086. style := xlsx.NewStyle()
  2087. alignment := xlsx.Alignment{
  2088. Horizontal: "center",
  2089. Vertical: "center",
  2090. WrapText: true,
  2091. }
  2092. style.Alignment = alignment
  2093. style.ApplyAlignment = true
  2094. sheet, err := xlsxFile.AddSheet("客户活动参与量月度统计")
  2095. if err != nil {
  2096. br.Msg = "新增Sheet失败"
  2097. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  2098. return
  2099. }
  2100. //标头
  2101. rowTitle := sheet.AddRow()
  2102. cellA := rowTitle.AddCell()
  2103. cellA.Value = "月份"
  2104. cellB := rowTitle.AddCell()
  2105. cellB.Value = "总参与量"
  2106. cellC := rowTitle.AddCell()
  2107. cellC.Value = "医药"
  2108. cellD := rowTitle.AddCell()
  2109. cellD.Value = "消费"
  2110. cellE := rowTitle.AddCell()
  2111. cellE.Value = "科技"
  2112. cellF := rowTitle.AddCell()
  2113. cellF.Value = "智造"
  2114. cellG := rowTitle.AddCell()
  2115. cellG.Value = "策略"
  2116. cellH := rowTitle.AddCell()
  2117. cellH.Value = "研选"
  2118. for _, item := range listDate {
  2119. row := sheet.AddRow()
  2120. cellA := row.AddCell()
  2121. cellA.Value = item.CreateTimes
  2122. cellB := row.AddCell()
  2123. cellB.Value = strconv.Itoa(dateMap[item.CreateTimes])
  2124. cellC := row.AddCell()
  2125. cellC.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"医药"])
  2126. cellD := row.AddCell()
  2127. cellD.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"消费"])
  2128. cellE := row.AddCell()
  2129. cellE.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"科技"])
  2130. cellF := row.AddCell()
  2131. cellF.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"智造"])
  2132. cellG := row.AddCell()
  2133. cellG.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"策略"])
  2134. cellH := row.AddCell()
  2135. cellH.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"研选"])
  2136. }
  2137. err = xlsxFile.Save(downLoadnFilePath)
  2138. if err != nil {
  2139. br.Msg = "保存文件失败"
  2140. br.ErrMsg = "保存文件失败"
  2141. return
  2142. }
  2143. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  2144. downloadFileName := companyInfo.CompanyName + "活动参与量月度统计(" + meetTypeName + ")" + randStr + ".xlsx"
  2145. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  2146. defer func() {
  2147. os.Remove(downLoadnFilePath)
  2148. }()
  2149. br.Ret = 200
  2150. br.Success = true
  2151. br.Msg = "导出成功"
  2152. br.IsAddLog = true
  2153. }
  2154. // @Title 新增备注接口
  2155. // @Description 新增备注
  2156. // @Param request body cygx.ActivityUserRemarksAddReq true "type json string"
  2157. // @Success 200 新增成功
  2158. // @router /activityMeet/addRemarks [post]
  2159. func (this *ActivityMeetCoAntroller) Add() {
  2160. br := new(models.BaseResponse).Init()
  2161. defer func() {
  2162. this.Data["json"] = br
  2163. this.ServeJSON()
  2164. }()
  2165. sysUser := this.SysUser
  2166. if sysUser == nil {
  2167. br.Msg = "请登录"
  2168. br.ErrMsg = "请登录,SysUser Is Empty"
  2169. br.Ret = 408
  2170. return
  2171. }
  2172. var req cygx.ActivityUserRemarksAddReq
  2173. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2174. if err != nil {
  2175. br.Msg = "参数解析异常!"
  2176. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2177. return
  2178. }
  2179. if req.Content == "" {
  2180. br.Msg = "请填写内容"
  2181. return
  2182. }
  2183. if req.ActivityId < 1 {
  2184. br.Msg = "请选择活动ID"
  2185. return
  2186. }
  2187. if req.Mobile == "" {
  2188. br.Msg = "手机号不能为空"
  2189. return
  2190. }
  2191. item := new(cygx.CygxActivityUserRemarks)
  2192. item.ActivityId = req.ActivityId
  2193. item.Mobile = req.Mobile
  2194. item.AdminId = sysUser.AdminId
  2195. item.RealName = sysUser.RealName
  2196. item.Content = req.Content
  2197. item.CreateTime = time.Now()
  2198. err = cygx.AddCygxActivityUserRemarks(item)
  2199. if err != nil {
  2200. br.Msg = "新增失败."
  2201. br.ErrMsg = "新增失败,Err:" + err.Error()
  2202. return
  2203. }
  2204. br.Ret = 200
  2205. br.Success = true
  2206. br.Msg = "新增成功"
  2207. }
  2208. // @Title 备注列表
  2209. // @Description 备注列表接口
  2210. // @Param Mobile query string true "手机号"
  2211. // @Success 200 {object} cygx.CygxActivityUserRemarksListResp
  2212. // @router /activityMeet/remark/list [get]
  2213. func (this *ActivityMeetCoAntroller) RemarkList() {
  2214. br := new(models.BaseResponse).Init()
  2215. defer func() {
  2216. this.Data["json"] = br
  2217. this.ServeJSON()
  2218. }()
  2219. sysUser := this.SysUser
  2220. if sysUser == nil {
  2221. br.Msg = "请登录"
  2222. br.ErrMsg = "请登录,SysUser Is Empty"
  2223. br.Ret = 408
  2224. return
  2225. }
  2226. mobile := this.GetString("Mobile")
  2227. if mobile == "" {
  2228. br.Msg = "请输入手机号"
  2229. return
  2230. }
  2231. list, err := cygx.GetCygxActivityUserRemarksLlist(mobile)
  2232. if err != nil && err.Error() != utils.ErrNoRow() {
  2233. br.Msg = "获取信息失败"
  2234. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  2235. return
  2236. }
  2237. if len(list) == 0 {
  2238. list = make([]*cygx.CygxActivityUserRemarksResp, 0)
  2239. }
  2240. resp := new(cygx.CygxActivityUserRemarksListResp)
  2241. resp.List = list
  2242. br.Ret = 200
  2243. br.Success = true
  2244. br.Msg = "获取成功"
  2245. br.Data = resp
  2246. }
  2247. // @Title 上传停留时间
  2248. // @Description 上传停留时间
  2249. // @Param request body cygx.CygxActivityMeetingHistoryAddReq true "type json string"
  2250. // @Success 200 新增成功
  2251. // @router /activityMeet/addStopTime [post]
  2252. func (this *ActivityMeetCoAntroller) AddStopTime() {
  2253. br := new(models.BaseResponse).Init()
  2254. defer func() {
  2255. this.Data["json"] = br
  2256. this.ServeJSON()
  2257. }()
  2258. sysUser := this.SysUser
  2259. if sysUser == nil {
  2260. br.Msg = "请登录"
  2261. br.ErrMsg = "请登录,SysUser Is Empty"
  2262. br.Ret = 408
  2263. return
  2264. }
  2265. var req cygx.CygxActivityMeetingHistoryAddReq
  2266. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2267. if err != nil {
  2268. br.Msg = "参数解析异常!"
  2269. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2270. return
  2271. }
  2272. stopTime := req.StopTime
  2273. activityId := req.ActivityId
  2274. if stopTime > 0 {
  2275. detail, err := cygx.GetCygxActivityMeetingHistoryNew(activityId, sysUser.AdminId)
  2276. if err != nil && err.Error() != utils.ErrNoRow() {
  2277. br.Msg = "获取信息失败"
  2278. br.ErrMsg = "获取最新消息失败,Err:" + err.Error()
  2279. return
  2280. }
  2281. if detail != nil {
  2282. err = cygx.UpdateActivityMeetingHistoryTime(stopTime, detail.Id)
  2283. }
  2284. }
  2285. br.Ret = 200
  2286. br.Success = true
  2287. br.Msg = "新增成功"
  2288. }
  2289. // @Title 阅读记录列表
  2290. // @Description 阅读记录列表接口
  2291. // @Param ActivityId query int true "活动ID"
  2292. // @Success 200 {object} cygx.CygxActivityMeetingHistoryListResp
  2293. // @router /activityMeet/history/list [get]
  2294. func (this *ActivityMeetCoAntroller) HistoryList() {
  2295. br := new(models.BaseResponse).Init()
  2296. defer func() {
  2297. this.Data["json"] = br
  2298. this.ServeJSON()
  2299. }()
  2300. sysUser := this.SysUser
  2301. if sysUser == nil {
  2302. br.Msg = "请登录"
  2303. br.ErrMsg = "请登录,SysUser Is Empty"
  2304. br.Ret = 408
  2305. return
  2306. }
  2307. activityId, _ := this.GetInt("ActivityId")
  2308. if activityId < 1 {
  2309. br.Msg = "活动不存在"
  2310. return
  2311. }
  2312. list, err := cygx.GetCygxActivityMeetingHistoryLlist(activityId)
  2313. if err != nil && err.Error() != utils.ErrNoRow() {
  2314. br.Msg = "获取信息失败"
  2315. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  2316. return
  2317. }
  2318. if len(list) == 0 {
  2319. list = make([]*cygx.CygxActivityMeetingHistoryResp, 0)
  2320. }
  2321. resp := new(cygx.CygxActivityMeetingHistoryListResp)
  2322. resp.List = list
  2323. br.Ret = 200
  2324. br.Success = true
  2325. br.Msg = "获取成功"
  2326. br.Data = resp
  2327. }
  2328. // @Title 上传参会表格(易董举办的活动)
  2329. // @Description 上传参会表格数据(易董举办的活动)
  2330. // @Param File query file true "文件"
  2331. // @Param ActivityId query int true "活动ID"
  2332. // @Success 200 Ret=200 导入成功
  2333. // @router /activityMeet/importYidong [post]
  2334. func (this *ActivityMeetCoAntroller) ImportYidongConduct() {
  2335. br := new(models.BaseResponse).Init()
  2336. defer func() {
  2337. this.Data["json"] = br
  2338. this.ServeJSON()
  2339. }()
  2340. AdminUser := this.SysUser
  2341. if AdminUser == nil {
  2342. br.Msg = "请重新登录"
  2343. return
  2344. }
  2345. file, h, err := this.GetFile("File")
  2346. if err != nil {
  2347. br.Msg = "获取文件失败"
  2348. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  2349. return
  2350. }
  2351. activityId, _ := this.GetInt("ActivityId")
  2352. if activityId <= 0 {
  2353. br.Msg = "参数错误"
  2354. br.ErrMsg = "活动id为0"
  2355. return
  2356. }
  2357. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  2358. if err != nil {
  2359. br.Msg = "活动不存在"
  2360. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  2361. return
  2362. }
  2363. //校验活动后台管理员、销售是否有修改权限
  2364. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  2365. if err != nil {
  2366. br.Msg = "获取管理员身份信息失败"
  2367. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  2368. return
  2369. }
  2370. if !havePower {
  2371. br.Msg = popupMsg
  2372. return
  2373. }
  2374. if activityInfo.ActiveState != 3 && activityInfo.ActiveState != 2 {
  2375. br.Msg = "任务未开始,请稍后上传"
  2376. return
  2377. }
  2378. if activityInfo.IsYidongConduct == 0 {
  2379. br.Msg = "不属于易董的活动无法上传参会信息!"
  2380. return
  2381. }
  2382. uploadDir := "static/xls"
  2383. err = os.MkdirAll(uploadDir, 766)
  2384. if err != nil {
  2385. br.Msg = "存储目录创建失败"
  2386. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  2387. return
  2388. }
  2389. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  2390. defer file.Close()
  2391. err = this.SaveToFile("File", path)
  2392. if err != nil {
  2393. br.Msg = "文件保存失败"
  2394. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  2395. return
  2396. }
  2397. xlFile, err := xlsx.OpenFile(path)
  2398. if err != nil {
  2399. br.Msg = "文件导入失败"
  2400. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  2401. return
  2402. }
  2403. defer func() {
  2404. os.Remove(path)
  2405. }()
  2406. //允许添加的联系人
  2407. needAddAttendanc := make([]*cygx.CygxActivityAttendanceDetail, 0)
  2408. var mobileStr string
  2409. // 遍历sheet页读取
  2410. realNameKey, mobileKey, companyNameKey, positionKey, firstMeetingTimeKey, lastMeetingTimeKey, durationKey, meetingTypeStrKey, meetingAuthenticationKey, meetingStatusStrKey, meetNumKey := -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  2411. for _, sheet := range xlFile.Sheets {
  2412. //遍历行读取
  2413. maxRow := sheet.MaxRow
  2414. for i := 0; i < maxRow; i++ {
  2415. if i == 0 {
  2416. row := sheet.Row(i)
  2417. cells := row.Cells
  2418. for k, cell := range cells {
  2419. text := cell.String()
  2420. if text == "姓名" {
  2421. realNameKey = k
  2422. }
  2423. if text == "公司" {
  2424. companyNameKey = k
  2425. }
  2426. if text == "职位" {
  2427. positionKey = k
  2428. }
  2429. if text == "手机" {
  2430. mobileKey = k
  2431. }
  2432. if text == "参会方式" {
  2433. meetingTypeStrKey = k
  2434. }
  2435. if text == "参会时长" {
  2436. durationKey = k
  2437. }
  2438. if text == "入会时间" {
  2439. firstMeetingTimeKey = k
  2440. }
  2441. if text == "离会时间" {
  2442. lastMeetingTimeKey = k
  2443. }
  2444. if text == "来源" {
  2445. meetingAuthenticationKey = k
  2446. }
  2447. if text == "参会状态" {
  2448. meetingStatusStrKey = k
  2449. }
  2450. if text == "入会次数" {
  2451. meetNumKey = k
  2452. }
  2453. }
  2454. }
  2455. if i == 0 {
  2456. if mobileKey == -1 {
  2457. br.Msg = "模板格式错误,缺少:电话"
  2458. br.ErrMsg = "模板格式错误"
  2459. return
  2460. }
  2461. if firstMeetingTimeKey == -1 {
  2462. br.Msg = "模板格式错误,缺少:首次入会时间"
  2463. br.ErrMsg = "模板格式错误!"
  2464. return
  2465. }
  2466. if lastMeetingTimeKey == -1 {
  2467. br.Msg = "模板格式错误,缺少:最后退出时间"
  2468. br.ErrMsg = "模板格式错误!"
  2469. return
  2470. }
  2471. if durationKey == -1 {
  2472. br.Msg = "模板格式错误,缺少:参与总时长"
  2473. br.ErrMsg = "模板格式错误!"
  2474. return
  2475. }
  2476. }
  2477. if i >= 1 {
  2478. row := sheet.Row(i)
  2479. cells := row.Cells
  2480. var realName, mobile, companyName, position, sellerName, firstMeetingTime, lastMeetingTime, duration, meetingTypeStr, meetingAuthentication, meetingStatusStr, meetNum string
  2481. for k, cell := range cells {
  2482. if k == realNameKey {
  2483. realName = cell.String()
  2484. }
  2485. if k == mobileKey {
  2486. mobile = cell.String()
  2487. }
  2488. if k == companyNameKey {
  2489. companyName = cell.String()
  2490. }
  2491. if k == positionKey {
  2492. position = cell.String()
  2493. }
  2494. if k == firstMeetingTimeKey {
  2495. firstMeetingTime = cell.String()
  2496. }
  2497. if k == lastMeetingTimeKey {
  2498. lastMeetingTime = cell.String()
  2499. }
  2500. if k == durationKey {
  2501. duration = cell.String()
  2502. }
  2503. if k == meetingTypeStrKey {
  2504. meetingTypeStr = cell.String()
  2505. }
  2506. if k == meetingAuthenticationKey {
  2507. meetingAuthentication = cell.String()
  2508. }
  2509. if k == meetingStatusStrKey {
  2510. meetingStatusStr = cell.String()
  2511. }
  2512. if k == meetNumKey {
  2513. meetNum = cell.String()
  2514. }
  2515. }
  2516. //这些字段都没有的话,系统认为excel到底了
  2517. if duration == "" && mobile == "" && firstMeetingTime == "" {
  2518. break
  2519. }
  2520. item := new(cygx.CygxActivityAttendanceDetail)
  2521. item.ActivityId = activityId
  2522. item.RealName = realName
  2523. item.Mobile = mobile
  2524. item.CompanyName = companyName
  2525. item.SellerName = sellerName
  2526. if meetNum == "1" {
  2527. item.FirstMeetingTime = firstMeetingTime
  2528. item.LastMeetingTime = lastMeetingTime
  2529. }
  2530. item.Duration = duration
  2531. item.MeetingTypeStr = meetingTypeStr
  2532. item.MeetingAuthentication = meetingAuthentication
  2533. item.MeetingStatusStr = meetingStatusStr
  2534. item.Position = position
  2535. item.CreateTime = time.Now()
  2536. if mobile != "" {
  2537. mobileStr += "'" + mobile + "'" + ","
  2538. needAddAttendanc = append(needAddAttendanc, item)
  2539. }
  2540. }
  2541. }
  2542. }
  2543. mobileStr = strings.TrimRight(mobileStr, ",")
  2544. if mobileStr == "" {
  2545. mobileStr = "1"
  2546. }
  2547. //外呼号
  2548. listUser, err := cygx.GetWxUserOutboundMobile(mobileStr)
  2549. if err != nil {
  2550. br.Msg = "手动归类失败!"
  2551. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  2552. return
  2553. }
  2554. //手机号
  2555. listUserMobile, err := cygx.GetWxUserMobile(mobileStr)
  2556. if err != nil {
  2557. br.Msg = "手动归类失败!"
  2558. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  2559. return
  2560. }
  2561. mapneedAddAttendanc := make(map[string]*cygx.WxUserOutboundMobile)
  2562. for _, v := range listUser {
  2563. mapneedAddAttendanc[v.OutboundMobile] = v
  2564. }
  2565. for _, v := range listUserMobile {
  2566. if mapneedAddAttendanc[v.Mobile] == nil {
  2567. mapneedAddAttendanc[v.Mobile] = v
  2568. }
  2569. }
  2570. for k, v := range needAddAttendanc {
  2571. if mapneedAddAttendanc[v.Mobile] != nil {
  2572. needAddAttendanc[k].CompanyId = mapneedAddAttendanc[v.Mobile].CompanyId
  2573. needAddAttendanc[k].SellerName = mapneedAddAttendanc[v.Mobile].SellerName
  2574. needAddAttendanc[k].CompanyName = mapneedAddAttendanc[v.Mobile].CompanyName
  2575. needAddAttendanc[k].IsMeetingStr = 1
  2576. }
  2577. }
  2578. err = cygx.AddAttendancDetail(needAddAttendanc, activityId, mobileStr)
  2579. if err != nil {
  2580. br.Msg = "手动归类失败"
  2581. br.ErrMsg = "手动归类失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  2582. return
  2583. }
  2584. go cygxService.AddCygxActivityRestrictSignupByAdmin(activityId)
  2585. go cygx.AddCygxActivityMeetDetailLogOnline(needAddAttendanc, activityId)
  2586. br.Msg = "导入成功"
  2587. br.Ret = 200
  2588. br.Success = true
  2589. br.IsAddLog = true
  2590. }