activity_meet.go 76 KB

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