activity_meet.go 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677
  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.TimeRemoveHms(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.TimeRemoveHms(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 yidongTitle string
  1690. titleSlice := strings.Split(v.Title, "】")
  1691. for _, vt := range titleSlice {
  1692. yidongTitle = vt
  1693. }
  1694. //如果活动时间一致,而且标题还还包含关键词就建立匹配关系
  1695. if strings.Contains(detail.ActivityNameTask, yidongTitle) && detail.ActivityTime == v.Start {
  1696. err = cygx.UpdateCygxActivityyidongActivityId(v.ID, activityId)
  1697. if err != nil {
  1698. br.Msg = "手动归类失败"
  1699. br.ErrMsg = "建立易董活动匹配关系失败,UpdateCygxActivityyidongActivityId Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1700. return
  1701. }
  1702. ismatch = true
  1703. go cygxService.GetYiDongActivityMeeting(v.ID, activityId)
  1704. break
  1705. }
  1706. }
  1707. }
  1708. if !ismatch {
  1709. condition += ` AND roadshow_begin_time >= ` + "'" + dateTime + " 00:00:00'"
  1710. condition += ` AND roadshow_begin_time <= ` + "'" + dateTime + " 23:59:59'"
  1711. if len(slice) > 0 {
  1712. keyWord = slice[0]
  1713. }
  1714. if keyWord != "" {
  1715. list, err := cygx.GetRoadshowDataList(keyWord, condition)
  1716. if err != nil {
  1717. br.Msg = "手动归类失败"
  1718. br.ErrMsg = "获取进门财经数据失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1719. return
  1720. }
  1721. var roadshowId string
  1722. for _, v := range list {
  1723. if v.RoadshowId != "" {
  1724. roadshowId = v.RoadshowId
  1725. break
  1726. }
  1727. }
  1728. needAddAttendanc := make([]*cygx.CygxActivityAttendanceDetail, 0)
  1729. if len(list) > 0 {
  1730. err = cygx.UpdateActivityRoadshowTitle(activityId, keyWord, roadshowId)
  1731. if err != nil {
  1732. br.Msg = "手动归类失败"
  1733. br.ErrMsg = "关联匹配类型失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1734. return
  1735. }
  1736. for _, v := range list {
  1737. if v.UserPhone != "" {
  1738. item := new(cygx.CygxActivityAttendanceDetail)
  1739. item.ActivityId = activityId
  1740. item.RealName = v.UserName
  1741. item.Mobile = v.UserPhone
  1742. item.CompanyName = v.Company
  1743. //item.SellerName = sellerName
  1744. item.FirstMeetingTime = v.FirstWatchTime
  1745. item.LastMeetingTime = v.LastWatchTime
  1746. item.Duration = utils.GetAttendanceDetailSeconds(v.JoinTime)
  1747. if v.JoinType == 1 {
  1748. item.MeetingTypeStr = "网络"
  1749. } else {
  1750. item.MeetingTypeStr = "电话"
  1751. }
  1752. item.MeetingAuthentication = v.AuthInfo
  1753. if v.DataType == 1 {
  1754. item.MeetingStatusStr = "直播"
  1755. } else {
  1756. item.MeetingStatusStr = "回放"
  1757. }
  1758. item.Position = v.Occupation
  1759. item.UseridEntity = v.UseridEntity
  1760. item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
  1761. item.CreateTime = time.Now()
  1762. mobileStr += "'" + v.UserPhone + "'" + ","
  1763. needAddAttendanc = append(needAddAttendanc, item)
  1764. }
  1765. }
  1766. mobileStr = strings.TrimRight(mobileStr, ",")
  1767. if mobileStr == "" {
  1768. mobileStr = "1"
  1769. }
  1770. listUser, err := cygx.GetWxUserOutboundMobile(mobileStr)
  1771. if err != nil {
  1772. br.Msg = "手动归类失败!"
  1773. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  1774. return
  1775. }
  1776. for _, v := range listUser {
  1777. userIdArr = append(userIdArr, v.UserId)
  1778. }
  1779. for k, v := range needAddAttendanc {
  1780. for _, v2 := range listUser {
  1781. if v2.OutboundMobile == v.Mobile {
  1782. needAddAttendanc[k].CompanyId = v2.CompanyId
  1783. needAddAttendanc[k].SellerName = v2.SellerName
  1784. needAddAttendanc[k].CompanyName = v2.CompanyName
  1785. needAddAttendanc[k].IsMeetingStr = 1
  1786. }
  1787. }
  1788. }
  1789. err = cygx.AddAttendancDetail(needAddAttendanc, activityId, mobileStr)
  1790. if err != nil {
  1791. br.Msg = "手动归类失败"
  1792. br.ErrMsg = "手动归类失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  1793. return
  1794. }
  1795. go cygxService.AddCygxActivityRestrictSignupByAdmin(activityId)
  1796. go cygx.AddCygxActivityMeetDetailLogOnline(needAddAttendanc, activityId)
  1797. go cygxService.ActivityUserLabelLogAdd(activityId, userIdArr) //添加用户活动到会标签到Redis
  1798. go cygxService.AddctivitySignupDetailListByHand(needAddAttendanc, activityId) //手动匹配进门财经信息
  1799. } else {
  1800. br.Msg = "手动归类失败"
  1801. br.ErrMsg = "暂未找到匹配数据!"
  1802. return
  1803. }
  1804. }
  1805. }
  1806. //添加操作日志记录
  1807. br.Ret = 200
  1808. br.Success = true
  1809. br.Msg = "操作成功"
  1810. br.IsAddLog = true
  1811. }
  1812. // @Title 下载客户参会记录
  1813. // @Description 下载客户参会记录接口
  1814. // @Param CompanyId query int true "公司ID"
  1815. // @Param MeetType query int true "参会方式 1线上,2线下 默认为线上"
  1816. // @Success Ret=200
  1817. // @router /activityMeet/companyHistory [get]
  1818. func (this *ActivityMeetCoAntroller) CompanyHisory() {
  1819. br := new(models.BaseResponse).Init()
  1820. var err error
  1821. defer func() {
  1822. this.Data["json"] = br
  1823. this.ServeJSON()
  1824. if err != nil {
  1825. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+"下载客户参会记录失败"+err.Error(), 3)
  1826. }
  1827. }()
  1828. sysUser := this.SysUser
  1829. if sysUser == nil {
  1830. br.Msg = "请登录"
  1831. br.ErrMsg = "请登录,SysUser Is Empty"
  1832. return
  1833. }
  1834. companyId, _ := this.GetInt("CompanyId")
  1835. meetType, _ := this.GetInt("MeetType")
  1836. if companyId < 1 {
  1837. br.Msg = "请输入公司ID"
  1838. return
  1839. }
  1840. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  1841. var isCanDownload bool
  1842. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  1843. if err != nil {
  1844. br.Msg = "获取失败"
  1845. br.ErrMsg = "获取失败,Err:" + err.Error()
  1846. return
  1847. }
  1848. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  1849. isCanDownload = true
  1850. }
  1851. if !isCanDownload {
  1852. br.Msg = "暂无下载权限"
  1853. return
  1854. }
  1855. //获取企业客户信息
  1856. companyInfo, err := company.GetCompanyById(companyId)
  1857. if err != nil {
  1858. br.Msg = "获取失败"
  1859. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  1860. return
  1861. }
  1862. var list []*cygx.CompanyMeetRep
  1863. mobiles, err := models.GetCompanyUserMobilesByCompanyId(companyId)
  1864. if err != nil && err.Error() != utils.ErrNoRow() {
  1865. br.Msg = "获取信息失败"
  1866. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1867. return
  1868. }
  1869. var meetTypeName string
  1870. if mobiles != "" {
  1871. mobiles = strings.Replace(mobiles, ",", "','", -1)
  1872. mobiles = "'" + mobiles + "'"
  1873. if meetType != 2 {
  1874. list, err = cygx.GetCygxActivityAttendanceDetailByCompanyId(mobiles)
  1875. meetTypeName = "线上"
  1876. } else {
  1877. list, err = cygx.GetCygxActivityOfflineMeetingDetailByCompanyId(mobiles)
  1878. meetTypeName = "线下"
  1879. }
  1880. }
  1881. if err != nil && err.Error() != utils.ErrNoRow() {
  1882. br.Msg = "获取信息失败"
  1883. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1884. return
  1885. }
  1886. //创建excel
  1887. dir, err := os.Executable()
  1888. exPath := filepath.Dir(dir)
  1889. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1890. xlsxFile := xlsx.NewFile()
  1891. if err != nil {
  1892. br.Msg = "生成文件失败"
  1893. br.ErrMsg = "生成文件失败"
  1894. return
  1895. }
  1896. style := xlsx.NewStyle()
  1897. alignment := xlsx.Alignment{
  1898. Horizontal: "center",
  1899. Vertical: "center",
  1900. WrapText: true,
  1901. }
  1902. style.Alignment = alignment
  1903. style.ApplyAlignment = true
  1904. sheet, err := xlsxFile.AddSheet(meetTypeName + "参会记录统计")
  1905. if err != nil {
  1906. br.Msg = "新增Sheet失败"
  1907. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1908. return
  1909. }
  1910. //标头
  1911. rowTitle := sheet.AddRow()
  1912. cellA := rowTitle.AddCell()
  1913. cellA.Value = "姓名"
  1914. cellB := rowTitle.AddCell()
  1915. cellB.Value = "手机号/邮箱"
  1916. cellC := rowTitle.AddCell()
  1917. cellC.Value = "活动名称"
  1918. cellD := rowTitle.AddCell()
  1919. cellD.Value = "所属行业"
  1920. cellE := rowTitle.AddCell()
  1921. cellE.Value = "活动类型"
  1922. cellF := rowTitle.AddCell()
  1923. cellF.Value = "活动主题"
  1924. cellG := rowTitle.AddCell()
  1925. cellG.Value = "活动时间"
  1926. if meetType != 2 {
  1927. cellH := rowTitle.AddCell()
  1928. cellH.Value = "首次入会时间"
  1929. cellI := rowTitle.AddCell()
  1930. cellI.Value = "最后退出时间"
  1931. cellJ := rowTitle.AddCell()
  1932. cellJ.Value = "参与总时长"
  1933. cellK := rowTitle.AddCell()
  1934. cellK.Value = "参会方式"
  1935. cellL := rowTitle.AddCell()
  1936. cellL.Value = "参会鉴权"
  1937. cellM := rowTitle.AddCell()
  1938. cellM.Value = "参会状态"
  1939. }
  1940. for _, item := range list {
  1941. row := sheet.AddRow()
  1942. cellA := row.AddCell()
  1943. cellA.Value = item.RealName
  1944. cellB := row.AddCell()
  1945. cellB.Value = item.Mobile
  1946. if item.Mobile == "" {
  1947. cellB.Value = item.Email
  1948. }
  1949. cellC := row.AddCell()
  1950. cellC.Value = item.ActivityName
  1951. cellD := row.AddCell()
  1952. cellD.Value = item.ChartPermissionName
  1953. cellE := row.AddCell()
  1954. cellE.Value = item.ActivityTypeName
  1955. cellF := row.AddCell()
  1956. cellF.Value = item.Label
  1957. cellG := row.AddCell()
  1958. cellG.Value = item.ActivityTime
  1959. cellH := row.AddCell()
  1960. if meetType != 2 {
  1961. cellH.Value = item.FirstMeetingTime
  1962. cellI := row.AddCell()
  1963. cellI.Value = item.LastMeetingTime
  1964. cellJ := row.AddCell()
  1965. cellJ.Value = item.Duration
  1966. cellK := row.AddCell()
  1967. cellK.Value = item.MeetingTypeStr
  1968. cellL := row.AddCell()
  1969. cellL.Value = item.MeetingAuthentication
  1970. cellM := row.AddCell()
  1971. cellM.Value = item.MeetingStatusStr
  1972. }
  1973. }
  1974. err = xlsxFile.Save(downLoadnFilePath)
  1975. if err != nil {
  1976. br.Msg = "保存文件失败"
  1977. br.ErrMsg = "保存文件失败"
  1978. return
  1979. }
  1980. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1981. downloadFileName := companyInfo.CompanyName + meetTypeName + "参会记录" + randStr + ".xlsx"
  1982. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1983. defer func() {
  1984. os.Remove(downLoadnFilePath)
  1985. }()
  1986. //添加操作日志记录
  1987. br.Ret = 200
  1988. br.Success = true
  1989. br.Msg = "导出成功"
  1990. br.IsAddLog = true
  1991. }
  1992. // @Title 下载客户参会月度统计记录
  1993. // @Description 下载客户参会月度统计记录接口
  1994. // @Param CompanyId query int true "公司ID"
  1995. // @Param MeetType query int true "参会方式 1线上,2线下 默认为线上"
  1996. // @Success Ret=200
  1997. // @router /activityMeet/companyCoount [get]
  1998. func (this *ActivityMeetCoAntroller) CompanyCoount() {
  1999. br := new(models.BaseResponse).Init()
  2000. defer func() {
  2001. this.Data["json"] = br
  2002. this.ServeJSON()
  2003. }()
  2004. sysUser := this.SysUser
  2005. if sysUser == nil {
  2006. br.Msg = "请登录"
  2007. br.ErrMsg = "请登录,SysUser Is Empty"
  2008. return
  2009. }
  2010. companyId, _ := this.GetInt("CompanyId")
  2011. meetType, _ := this.GetInt("MeetType")
  2012. if companyId < 1 {
  2013. br.Msg = "请输入公司ID"
  2014. return
  2015. }
  2016. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  2017. var isCanDownload bool
  2018. adminInfo, err := system.GetSysUserById(sysUser.AdminId)
  2019. if err != nil {
  2020. br.Msg = "获取失败"
  2021. br.ErrMsg = "获取失败,Err:" + err.Error()
  2022. return
  2023. }
  2024. if adminInfo.Role == "admin" || strings.Index(adminInfo.RoleTypeCode, "rai") > -1 {
  2025. isCanDownload = true
  2026. }
  2027. if !isCanDownload {
  2028. br.Msg = "暂无下载权限"
  2029. return
  2030. }
  2031. //获取企业客户信息
  2032. companyInfo, err := company.GetCompanyById(companyId)
  2033. if err != nil {
  2034. br.Msg = "获取失败"
  2035. br.ErrMsg = "获取企业客户信息失败,Err:" + err.Error()
  2036. return
  2037. }
  2038. var list []*cygx.CompanyMeetRep
  2039. listDate, err := cygx.GetCompanyAciviytyGroupDate()
  2040. if err != nil {
  2041. br.Msg = "获取失败"
  2042. br.ErrMsg = "获取失败,Err:" + err.Error()
  2043. return
  2044. }
  2045. dateMap := make(map[string]int)
  2046. permissionNameMap := make(map[string]int)
  2047. var meetTypeName string
  2048. if meetType != 2 {
  2049. list, err = cygx.GetCompanyActivityCount(companyId)
  2050. meetTypeName = "线上"
  2051. } else {
  2052. list, err = cygx.GetCygxActivityOfflineMeetingCoount(companyId)
  2053. meetTypeName = "线下"
  2054. }
  2055. if err != nil {
  2056. br.Msg = "获取失败"
  2057. br.ErrMsg = "获取失败,Err:" + err.Error()
  2058. return
  2059. }
  2060. for _, v := range list {
  2061. if dateMap[v.ActivityTime] == 0 {
  2062. dateMap[v.ActivityTime] = 1
  2063. } else {
  2064. dateMap[v.ActivityTime] += 1
  2065. }
  2066. if permissionNameMap[v.ActivityTime+v.ChartPermissionName] == 0 {
  2067. permissionNameMap[v.ActivityTime+v.ChartPermissionName] = 1
  2068. } else {
  2069. permissionNameMap[v.ActivityTime+v.ChartPermissionName] += 1
  2070. }
  2071. }
  2072. //创建excel
  2073. dir, err := os.Executable()
  2074. exPath := filepath.Dir(dir)
  2075. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2076. xlsxFile := xlsx.NewFile()
  2077. if err != nil {
  2078. br.Msg = "生成文件失败"
  2079. br.ErrMsg = "生成文件失败"
  2080. return
  2081. }
  2082. style := xlsx.NewStyle()
  2083. alignment := xlsx.Alignment{
  2084. Horizontal: "center",
  2085. Vertical: "center",
  2086. WrapText: true,
  2087. }
  2088. style.Alignment = alignment
  2089. style.ApplyAlignment = true
  2090. sheet, err := xlsxFile.AddSheet("客户活动参与量月度统计")
  2091. if err != nil {
  2092. br.Msg = "新增Sheet失败"
  2093. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  2094. return
  2095. }
  2096. //标头
  2097. rowTitle := sheet.AddRow()
  2098. cellA := rowTitle.AddCell()
  2099. cellA.Value = "月份"
  2100. cellB := rowTitle.AddCell()
  2101. cellB.Value = "总参与量"
  2102. cellC := rowTitle.AddCell()
  2103. cellC.Value = "医药"
  2104. cellD := rowTitle.AddCell()
  2105. cellD.Value = "消费"
  2106. cellE := rowTitle.AddCell()
  2107. cellE.Value = "科技"
  2108. cellF := rowTitle.AddCell()
  2109. cellF.Value = "智造"
  2110. cellG := rowTitle.AddCell()
  2111. cellG.Value = "策略"
  2112. cellH := rowTitle.AddCell()
  2113. cellH.Value = "研选"
  2114. for _, item := range listDate {
  2115. row := sheet.AddRow()
  2116. cellA := row.AddCell()
  2117. cellA.Value = item.CreateTimes
  2118. cellB := row.AddCell()
  2119. cellB.Value = strconv.Itoa(dateMap[item.CreateTimes])
  2120. cellC := row.AddCell()
  2121. cellC.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"医药"])
  2122. cellD := row.AddCell()
  2123. cellD.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"消费"])
  2124. cellE := row.AddCell()
  2125. cellE.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"科技"])
  2126. cellF := row.AddCell()
  2127. cellF.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"智造"])
  2128. cellG := row.AddCell()
  2129. cellG.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"策略"])
  2130. cellH := row.AddCell()
  2131. cellH.Value = strconv.Itoa(permissionNameMap[item.CreateTimes+"研选"])
  2132. }
  2133. err = xlsxFile.Save(downLoadnFilePath)
  2134. if err != nil {
  2135. br.Msg = "保存文件失败"
  2136. br.ErrMsg = "保存文件失败"
  2137. return
  2138. }
  2139. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  2140. downloadFileName := companyInfo.CompanyName + "活动参与量月度统计(" + meetTypeName + ")" + randStr + ".xlsx"
  2141. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  2142. defer func() {
  2143. os.Remove(downLoadnFilePath)
  2144. }()
  2145. br.Ret = 200
  2146. br.Success = true
  2147. br.Msg = "导出成功"
  2148. br.IsAddLog = true
  2149. }
  2150. // @Title 新增备注接口
  2151. // @Description 新增备注
  2152. // @Param request body cygx.ActivityUserRemarksAddReq true "type json string"
  2153. // @Success 200 新增成功
  2154. // @router /activityMeet/addRemarks [post]
  2155. func (this *ActivityMeetCoAntroller) Add() {
  2156. br := new(models.BaseResponse).Init()
  2157. defer func() {
  2158. this.Data["json"] = br
  2159. this.ServeJSON()
  2160. }()
  2161. sysUser := this.SysUser
  2162. if sysUser == nil {
  2163. br.Msg = "请登录"
  2164. br.ErrMsg = "请登录,SysUser Is Empty"
  2165. br.Ret = 408
  2166. return
  2167. }
  2168. var req cygx.ActivityUserRemarksAddReq
  2169. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2170. if err != nil {
  2171. br.Msg = "参数解析异常!"
  2172. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2173. return
  2174. }
  2175. if req.Content == "" {
  2176. br.Msg = "请填写内容"
  2177. return
  2178. }
  2179. if req.ActivityId < 1 {
  2180. br.Msg = "请选择活动ID"
  2181. return
  2182. }
  2183. if req.Mobile == "" {
  2184. br.Msg = "手机号不能为空"
  2185. return
  2186. }
  2187. item := new(cygx.CygxActivityUserRemarks)
  2188. item.ActivityId = req.ActivityId
  2189. item.Mobile = req.Mobile
  2190. item.AdminId = sysUser.AdminId
  2191. item.RealName = sysUser.RealName
  2192. item.Content = req.Content
  2193. item.CreateTime = time.Now()
  2194. err = cygx.AddCygxActivityUserRemarks(item)
  2195. if err != nil {
  2196. br.Msg = "新增失败."
  2197. br.ErrMsg = "新增失败,Err:" + err.Error()
  2198. return
  2199. }
  2200. br.Ret = 200
  2201. br.Success = true
  2202. br.Msg = "新增成功"
  2203. }
  2204. // @Title 备注列表
  2205. // @Description 备注列表接口
  2206. // @Param Mobile query string true "手机号"
  2207. // @Success 200 {object} cygx.CygxActivityUserRemarksListResp
  2208. // @router /activityMeet/remark/list [get]
  2209. func (this *ActivityMeetCoAntroller) RemarkList() {
  2210. br := new(models.BaseResponse).Init()
  2211. defer func() {
  2212. this.Data["json"] = br
  2213. this.ServeJSON()
  2214. }()
  2215. sysUser := this.SysUser
  2216. if sysUser == nil {
  2217. br.Msg = "请登录"
  2218. br.ErrMsg = "请登录,SysUser Is Empty"
  2219. br.Ret = 408
  2220. return
  2221. }
  2222. mobile := this.GetString("Mobile")
  2223. if mobile == "" {
  2224. br.Msg = "请输入手机号"
  2225. return
  2226. }
  2227. list, err := cygx.GetCygxActivityUserRemarksLlist(mobile)
  2228. if err != nil && err.Error() != utils.ErrNoRow() {
  2229. br.Msg = "获取信息失败"
  2230. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  2231. return
  2232. }
  2233. if len(list) == 0 {
  2234. list = make([]*cygx.CygxActivityUserRemarksResp, 0)
  2235. }
  2236. resp := new(cygx.CygxActivityUserRemarksListResp)
  2237. resp.List = list
  2238. br.Ret = 200
  2239. br.Success = true
  2240. br.Msg = "获取成功"
  2241. br.Data = resp
  2242. }
  2243. // @Title 上传停留时间
  2244. // @Description 上传停留时间
  2245. // @Param request body cygx.CygxActivityMeetingHistoryAddReq true "type json string"
  2246. // @Success 200 新增成功
  2247. // @router /activityMeet/addStopTime [post]
  2248. func (this *ActivityMeetCoAntroller) AddStopTime() {
  2249. br := new(models.BaseResponse).Init()
  2250. defer func() {
  2251. this.Data["json"] = br
  2252. this.ServeJSON()
  2253. }()
  2254. sysUser := this.SysUser
  2255. if sysUser == nil {
  2256. br.Msg = "请登录"
  2257. br.ErrMsg = "请登录,SysUser Is Empty"
  2258. br.Ret = 408
  2259. return
  2260. }
  2261. var req cygx.CygxActivityMeetingHistoryAddReq
  2262. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2263. if err != nil {
  2264. br.Msg = "参数解析异常!"
  2265. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2266. return
  2267. }
  2268. stopTime := req.StopTime
  2269. activityId := req.ActivityId
  2270. if stopTime > 0 {
  2271. detail, err := cygx.GetCygxActivityMeetingHistoryNew(activityId, sysUser.AdminId)
  2272. if err != nil && err.Error() != utils.ErrNoRow() {
  2273. br.Msg = "获取信息失败"
  2274. br.ErrMsg = "获取最新消息失败,Err:" + err.Error()
  2275. return
  2276. }
  2277. if detail != nil {
  2278. err = cygx.UpdateActivityMeetingHistoryTime(stopTime, detail.Id)
  2279. }
  2280. }
  2281. br.Ret = 200
  2282. br.Success = true
  2283. br.Msg = "新增成功"
  2284. }
  2285. // @Title 阅读记录列表
  2286. // @Description 阅读记录列表接口
  2287. // @Param ActivityId query int true "活动ID"
  2288. // @Success 200 {object} cygx.CygxActivityMeetingHistoryListResp
  2289. // @router /activityMeet/history/list [get]
  2290. func (this *ActivityMeetCoAntroller) HistoryList() {
  2291. br := new(models.BaseResponse).Init()
  2292. defer func() {
  2293. this.Data["json"] = br
  2294. this.ServeJSON()
  2295. }()
  2296. sysUser := this.SysUser
  2297. if sysUser == nil {
  2298. br.Msg = "请登录"
  2299. br.ErrMsg = "请登录,SysUser Is Empty"
  2300. br.Ret = 408
  2301. return
  2302. }
  2303. activityId, _ := this.GetInt("ActivityId")
  2304. if activityId < 1 {
  2305. br.Msg = "活动不存在"
  2306. return
  2307. }
  2308. list, err := cygx.GetCygxActivityMeetingHistoryLlist(activityId)
  2309. if err != nil && err.Error() != utils.ErrNoRow() {
  2310. br.Msg = "获取信息失败"
  2311. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  2312. return
  2313. }
  2314. if len(list) == 0 {
  2315. list = make([]*cygx.CygxActivityMeetingHistoryResp, 0)
  2316. }
  2317. resp := new(cygx.CygxActivityMeetingHistoryListResp)
  2318. resp.List = list
  2319. br.Ret = 200
  2320. br.Success = true
  2321. br.Msg = "获取成功"
  2322. br.Data = resp
  2323. }
  2324. // @Title 上传参会表格(易董举办的活动)
  2325. // @Description 上传参会表格数据(易董举办的活动)
  2326. // @Param File query file true "文件"
  2327. // @Param ActivityId query int true "活动ID"
  2328. // @Success 200 Ret=200 导入成功
  2329. // @router /activityMeet/importYidong [post]
  2330. func (this *ActivityMeetCoAntroller) ImportYidongConduct() {
  2331. br := new(models.BaseResponse).Init()
  2332. defer func() {
  2333. this.Data["json"] = br
  2334. this.ServeJSON()
  2335. }()
  2336. AdminUser := this.SysUser
  2337. if AdminUser == nil {
  2338. br.Msg = "请重新登录"
  2339. return
  2340. }
  2341. file, h, err := this.GetFile("File")
  2342. if err != nil {
  2343. br.Msg = "获取文件失败"
  2344. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  2345. return
  2346. }
  2347. activityId, _ := this.GetInt("ActivityId")
  2348. if activityId <= 0 {
  2349. br.Msg = "参数错误"
  2350. br.ErrMsg = "活动id为0"
  2351. return
  2352. }
  2353. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  2354. if err != nil {
  2355. br.Msg = "活动不存在"
  2356. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  2357. return
  2358. }
  2359. //校验活动后台管理员、销售是否有修改权限
  2360. havePower, popupMsg, err := cygxService.CheckActivityUpdatePower(AdminUser.AdminId, activityInfo)
  2361. if err != nil {
  2362. br.Msg = "获取管理员身份信息失败"
  2363. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  2364. return
  2365. }
  2366. if !havePower {
  2367. br.Msg = popupMsg
  2368. return
  2369. }
  2370. if activityInfo.ActiveState != 3 && activityInfo.ActiveState != 2 {
  2371. br.Msg = "任务未开始,请稍后上传"
  2372. return
  2373. }
  2374. if activityInfo.IsYidongConduct == 0 {
  2375. br.Msg = "不属于易董的活动无法上传参会信息!"
  2376. return
  2377. }
  2378. uploadDir := "static/xls"
  2379. err = os.MkdirAll(uploadDir, 766)
  2380. if err != nil {
  2381. br.Msg = "存储目录创建失败"
  2382. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  2383. return
  2384. }
  2385. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  2386. defer file.Close()
  2387. err = this.SaveToFile("File", path)
  2388. if err != nil {
  2389. br.Msg = "文件保存失败"
  2390. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  2391. return
  2392. }
  2393. xlFile, err := xlsx.OpenFile(path)
  2394. if err != nil {
  2395. br.Msg = "文件导入失败"
  2396. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  2397. return
  2398. }
  2399. defer func() {
  2400. os.Remove(path)
  2401. }()
  2402. //允许添加的联系人
  2403. needAddAttendanc := make([]*cygx.CygxActivityAttendanceDetail, 0)
  2404. var mobileStr string
  2405. // 遍历sheet页读取
  2406. realNameKey, mobileKey, companyNameKey, positionKey, firstMeetingTimeKey, lastMeetingTimeKey, durationKey, meetingTypeStrKey, meetingAuthenticationKey, meetingStatusStrKey, meetNumKey := -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  2407. for _, sheet := range xlFile.Sheets {
  2408. //遍历行读取
  2409. maxRow := sheet.MaxRow
  2410. for i := 0; i < maxRow; i++ {
  2411. if i == 0 {
  2412. row := sheet.Row(i)
  2413. cells := row.Cells
  2414. for k, cell := range cells {
  2415. text := cell.String()
  2416. if text == "姓名" {
  2417. realNameKey = k
  2418. }
  2419. if text == "公司" {
  2420. companyNameKey = k
  2421. }
  2422. if text == "职位" {
  2423. positionKey = k
  2424. }
  2425. if text == "手机" {
  2426. mobileKey = k
  2427. }
  2428. if text == "参会方式" {
  2429. meetingTypeStrKey = k
  2430. }
  2431. if text == "参会时长" {
  2432. durationKey = k
  2433. }
  2434. if text == "入会时间" {
  2435. firstMeetingTimeKey = k
  2436. }
  2437. if text == "离会时间" {
  2438. lastMeetingTimeKey = k
  2439. }
  2440. if text == "来源" {
  2441. meetingAuthenticationKey = k
  2442. }
  2443. if text == "参会状态" {
  2444. meetingStatusStrKey = k
  2445. }
  2446. if text == "入会次数" {
  2447. meetNumKey = k
  2448. }
  2449. }
  2450. }
  2451. if i == 0 {
  2452. if mobileKey == -1 {
  2453. br.Msg = "模板格式错误,缺少:电话"
  2454. br.ErrMsg = "模板格式错误"
  2455. return
  2456. }
  2457. if firstMeetingTimeKey == -1 {
  2458. br.Msg = "模板格式错误,缺少:首次入会时间"
  2459. br.ErrMsg = "模板格式错误!"
  2460. return
  2461. }
  2462. if lastMeetingTimeKey == -1 {
  2463. br.Msg = "模板格式错误,缺少:最后退出时间"
  2464. br.ErrMsg = "模板格式错误!"
  2465. return
  2466. }
  2467. if durationKey == -1 {
  2468. br.Msg = "模板格式错误,缺少:参与总时长"
  2469. br.ErrMsg = "模板格式错误!"
  2470. return
  2471. }
  2472. }
  2473. if i >= 1 {
  2474. row := sheet.Row(i)
  2475. cells := row.Cells
  2476. var realName, mobile, companyName, position, sellerName, firstMeetingTime, lastMeetingTime, duration, meetingTypeStr, meetingAuthentication, meetingStatusStr, meetNum string
  2477. for k, cell := range cells {
  2478. if k == realNameKey {
  2479. realName = cell.String()
  2480. }
  2481. if k == mobileKey {
  2482. mobile = cell.String()
  2483. }
  2484. if k == companyNameKey {
  2485. companyName = cell.String()
  2486. }
  2487. if k == positionKey {
  2488. position = cell.String()
  2489. }
  2490. if k == firstMeetingTimeKey {
  2491. firstMeetingTime = cell.String()
  2492. }
  2493. if k == lastMeetingTimeKey {
  2494. lastMeetingTime = cell.String()
  2495. }
  2496. if k == durationKey {
  2497. duration = cell.String()
  2498. }
  2499. if k == meetingTypeStrKey {
  2500. meetingTypeStr = cell.String()
  2501. }
  2502. if k == meetingAuthenticationKey {
  2503. meetingAuthentication = cell.String()
  2504. }
  2505. if k == meetingStatusStrKey {
  2506. meetingStatusStr = cell.String()
  2507. }
  2508. if k == meetNumKey {
  2509. meetNum = cell.String()
  2510. }
  2511. }
  2512. //这些字段都没有的话,系统认为excel到底了
  2513. if duration == "" && mobile == "" && firstMeetingTime == "" {
  2514. break
  2515. }
  2516. item := new(cygx.CygxActivityAttendanceDetail)
  2517. item.ActivityId = activityId
  2518. item.RealName = realName
  2519. item.Mobile = mobile
  2520. item.CompanyName = companyName
  2521. item.SellerName = sellerName
  2522. if meetNum == "1" {
  2523. item.FirstMeetingTime = firstMeetingTime
  2524. item.LastMeetingTime = lastMeetingTime
  2525. }
  2526. item.Duration = duration
  2527. item.MeetingTypeStr = meetingTypeStr
  2528. item.MeetingAuthentication = meetingAuthentication
  2529. item.MeetingStatusStr = meetingStatusStr
  2530. item.Position = position
  2531. item.CreateTime = time.Now()
  2532. if mobile != "" {
  2533. mobileStr += "'" + mobile + "'" + ","
  2534. needAddAttendanc = append(needAddAttendanc, item)
  2535. }
  2536. }
  2537. }
  2538. }
  2539. mobileStr = strings.TrimRight(mobileStr, ",")
  2540. if mobileStr == "" {
  2541. mobileStr = "1"
  2542. }
  2543. //外呼号
  2544. listUser, err := cygx.GetWxUserOutboundMobile(mobileStr)
  2545. if err != nil {
  2546. br.Msg = "手动归类失败!"
  2547. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  2548. return
  2549. }
  2550. //手机号
  2551. listUserMobile, err := cygx.GetWxUserMobile(mobileStr)
  2552. if err != nil {
  2553. br.Msg = "手动归类失败!"
  2554. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  2555. return
  2556. }
  2557. mapneedAddAttendanc := make(map[string]*cygx.WxUserOutboundMobile)
  2558. for _, v := range listUser {
  2559. mapneedAddAttendanc[v.OutboundMobile] = v
  2560. }
  2561. for _, v := range listUserMobile {
  2562. if mapneedAddAttendanc[v.Mobile] == nil {
  2563. mapneedAddAttendanc[v.Mobile] = v
  2564. }
  2565. }
  2566. for k, v := range needAddAttendanc {
  2567. if mapneedAddAttendanc[v.Mobile] != nil {
  2568. needAddAttendanc[k].CompanyId = mapneedAddAttendanc[v.Mobile].CompanyId
  2569. needAddAttendanc[k].SellerName = mapneedAddAttendanc[v.Mobile].SellerName
  2570. needAddAttendanc[k].CompanyName = mapneedAddAttendanc[v.Mobile].CompanyName
  2571. needAddAttendanc[k].IsMeetingStr = 1
  2572. }
  2573. }
  2574. err = cygx.AddAttendancDetail(needAddAttendanc, activityId, mobileStr)
  2575. if err != nil {
  2576. br.Msg = "手动归类失败"
  2577. br.ErrMsg = "手动归类失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  2578. return
  2579. }
  2580. go cygxService.AddCygxActivityRestrictSignupByAdmin(activityId)
  2581. go cygx.AddCygxActivityMeetDetailLogOnline(needAddAttendanc, activityId)
  2582. br.Msg = "导入成功"
  2583. br.Ret = 200
  2584. br.Success = true
  2585. br.IsAddLog = true
  2586. }