activity_special_trip.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/models/system"
  10. cygxService "hongze/hz_crm_api/services/cygx"
  11. "hongze/hz_crm_api/utils"
  12. "os"
  13. "path/filepath"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 专项调研行程
  19. type ActivitySpecialTripCoAntroller struct {
  20. controllers.BaseAuthController
  21. }
  22. // @Title 新增报名
  23. // @Description 新增报名接口
  24. // @Param request body cygx.AddMeetingReminderReq true "type json string"
  25. // @Success 200 操作成功
  26. // @router /special/trip/addUser [post]
  27. func (this *ActivitySpecialTripCoAntroller) AddUser() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. AdminUser := this.SysUser
  34. if AdminUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. return
  38. }
  39. var req cygx.AddMeetingReminderReq
  40. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  41. if err != nil {
  42. br.Msg = "参数解析异常!"
  43. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  44. return
  45. }
  46. var items []*cygx.CygxActivitySpecialTrip
  47. var itemsBill []*cygx.CygxActivitySpecialTripBill
  48. activityIds := req.ActivityIds
  49. uidList := req.List
  50. if activityIds == "" {
  51. br.Msg = "请选择活动"
  52. br.ErrMsg = "活动ID不能为空"
  53. return
  54. }
  55. activityIdList := strings.Split(activityIds, ",")
  56. var uids string
  57. for _, v := range uidList {
  58. uids += strconv.Itoa(v.UserId) + ","
  59. }
  60. uids = strings.TrimRight(uids, ",")
  61. for _, v := range uidList {
  62. uid := v.UserId
  63. wxUser, userErr := models.GetWxUserByUserId(uid)
  64. if userErr != nil {
  65. br.Msg = "编辑失败!查询用户信息失败"
  66. br.ErrMsg = "查询用户信息失败,Err:" + userErr.Error() + "用户UID:" + strconv.Itoa(uid) + "不存在"
  67. return
  68. }
  69. for _, vact := range activityIdList {
  70. activityId, _ := strconv.Atoi(vact)
  71. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  72. if err != nil {
  73. br.Msg = "活动不存在"
  74. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  75. return
  76. }
  77. limitPeopleNum := activityInfo.LimitPeopleNum
  78. if limitPeopleNum > 0 {
  79. if AdminUser.RoleTypeCode != "admin" {
  80. havePower, err := cygxService.GetSpecialDetailUserPower(wxUser, activityInfo)
  81. if err != nil {
  82. br.Msg = "用户权限校验失败!"
  83. br.ErrMsg = "GetActivityDetailUserPower,Err:" + err.Error() + fmt.Sprint("UserId", wxUser.UserId, "ActivityId:", activityInfo.ActivityId)
  84. return
  85. }
  86. if !havePower {
  87. br.Msg = "当前活动对该客户不可见,无法报名"
  88. br.ErrMsg = "活动ID:" + strconv.Itoa(activityId) + "活动名称:" + activityInfo.ResearchTheme + "用户ID:" + strconv.Itoa(int(wxUser.UserId))
  89. return
  90. }
  91. }
  92. //获取这个活动已经报名的用户数量
  93. totalSignup, errSignup := cygx.GetActivitySpecialTripCountByActivityId(activityId)
  94. if errSignup != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = "获取失败,Err:" + errSignup.Error()
  97. return
  98. }
  99. //获取这个活动中输入的这些用户的报名数量
  100. totalThisUser, errThisUser := cygx.GetActivitySpecialTripCountByThisUser(activityId, uids)
  101. if errThisUser != nil {
  102. br.Msg = "获取失败"
  103. br.ErrMsg = "获取失败,Err:" + errThisUser.Error()
  104. return
  105. }
  106. //如果是限制人数的就做报名人数限制判断
  107. if limitPeopleNum < totalSignup+len(uidList)-totalThisUser {
  108. br.Msg = "新增失败,活动人数超限"
  109. br.ErrMsg = "当前活动报名人数已满,活动:" + activityInfo.ResearchTheme
  110. return
  111. }
  112. }
  113. total, errtotal := cygx.GetActivitySpecialTripCount(uid, activityId)
  114. if errtotal != nil {
  115. br.Msg = "获取失败"
  116. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  117. return
  118. }
  119. if total == 0 {
  120. infoUser, err := cygx.GetUserAndCompanyNameList(uid)
  121. if err != nil {
  122. br.Msg = "获取失败"
  123. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  124. return
  125. }
  126. //流水记录表
  127. itemBill := new(cygx.CygxActivitySpecialTripBill)
  128. itemBill.UserId = infoUser.UserId
  129. itemBill.ActivityId = activityInfo.ActivityId
  130. itemBill.CreateTime = time.Now()
  131. itemBill.Mobile = infoUser.Mobile
  132. itemBill.Email = infoUser.Email
  133. itemBill.CompanyId = infoUser.CompanyId
  134. itemBill.CompanyName = infoUser.CompanyName
  135. itemBill.RealName = infoUser.RealName
  136. itemBill.Source = 2
  137. itemBill.DoType = 1
  138. itemBill.BillDetailed = -1 // 流水减一
  139. itemBill.RegisterPlatform = 1
  140. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  141. itemBill.AdminId = AdminUser.AdminId
  142. item := new(cygx.CygxActivitySpecialTrip)
  143. item.UserId = infoUser.UserId
  144. item.RealName = infoUser.RealName
  145. item.SellerName = infoUser.SellerName
  146. item.ActivityId = activityId
  147. item.CreateTime = time.Now()
  148. item.Mobile = infoUser.Mobile
  149. item.Email = infoUser.Email
  150. item.Email = infoUser.Email
  151. item.CompanyId = infoUser.CompanyId
  152. item.CompanyName = infoUser.CompanyName
  153. item.AdminId = AdminUser.AdminId
  154. item.Source = 2
  155. //优先绑定用户修改过的外呼手机号
  156. if infoUser.OutboundMobile != "" {
  157. item.OutboundMobile = infoUser.OutboundMobile
  158. if infoUser.OutboundCountryCode == "" {
  159. item.CountryCode = "86"
  160. } else {
  161. item.CountryCode = infoUser.OutboundCountryCode
  162. }
  163. } else {
  164. item.OutboundMobile = infoUser.Mobile
  165. if infoUser.CountryCode == "" {
  166. item.CountryCode = "86"
  167. } else {
  168. item.CountryCode = infoUser.CountryCode
  169. }
  170. }
  171. items = append(items, item)
  172. itemsBill = append(itemsBill, itemBill)
  173. }
  174. }
  175. }
  176. err = cygx.AddCygxActivitySpecialTrip(items, itemsBill)
  177. if err != nil {
  178. br.Msg = "操作失败"
  179. br.ErrMsg = "新增用户失败,Err:" + err.Error()
  180. return
  181. }
  182. br.Ret = 200
  183. br.Success = true
  184. br.Msg = "操作成功"
  185. br.IsAddLog = true
  186. }
  187. // @Title 报名列表
  188. // @Description 报名列表接口
  189. // @Param ActivityId query int true "活动ID"
  190. // @Param IsExport query bool false "是否导出excel,默认是false"
  191. // @Success 200 {object} cygx.GetAppointmentSpecialListRsep
  192. // @router /special/tripList [get]
  193. func (this *ActivitySpecialTripCoAntroller) TripList() {
  194. br := new(models.BaseResponse).Init()
  195. defer func() {
  196. this.Data["json"] = br
  197. this.ServeJSON()
  198. }()
  199. sysUser := this.SysUser
  200. if sysUser == nil {
  201. br.Msg = "请登录"
  202. br.ErrMsg = "请登录,SysUser Is Empty"
  203. return
  204. }
  205. isExport, _ := this.GetBool("IsExport", false)
  206. activityId, _ := this.GetInt("ActivityId")
  207. if activityId < 1 {
  208. br.Msg = "活动不存在"
  209. return
  210. }
  211. respList := new(cygx.GetAppointmentSpecialListRsep)
  212. activityInfo, _ := cygx.GetAddActivityInfoSpecialById(activityId)
  213. if activityInfo == nil {
  214. br.Msg = "活动不存在"
  215. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  216. return
  217. }
  218. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  219. resp := new(cygx.CanDownload)
  220. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  221. if errAdmin != nil {
  222. br.Msg = "获取失败"
  223. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  224. return
  225. }
  226. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  227. resp.IsCanDownload = true
  228. }
  229. memberType := "Admin"
  230. sqlStr := ` AND s.is_cancel = 0`
  231. totalStr := sqlStr
  232. list, err := cygx.GetCygxActivitySpecialTripList(activityId, sqlStr)
  233. if err != nil {
  234. br.Msg = "获取失败"
  235. br.ErrMsg = "获取失败,Err:" + err.Error()
  236. return
  237. }
  238. //线上活动,销售查看自己客户,销售组长查看组员
  239. if resp.IsCanDownload == false && activityInfo.SpecialType == 1 {
  240. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  241. if err != nil {
  242. br.Msg = "获取失败"
  243. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  244. return
  245. }
  246. for _, v := range list {
  247. if _, ok := mapMobile[v.Mobile]; ok {
  248. respList.List = append(respList.List, v)
  249. }
  250. }
  251. if adminInfo.RoleTypeCode == "rai_group" {
  252. //组长查看本组所有组员
  253. memberType = "GroupLeader"
  254. } else {
  255. //组员查看自己
  256. memberType = "Sale"
  257. }
  258. } else {
  259. respList.List = list
  260. }
  261. if len(respList.List) == 0 {
  262. respList.List = make([]*cygx.CygxActivitySpecialTripResp, 0)
  263. }
  264. //导出excel
  265. if isExport {
  266. TripListExport(this, respList.List)
  267. return
  268. }
  269. total, errtotal := cygx.GetActivitySpecialTripTotal(activityId, totalStr)
  270. if errtotal != nil {
  271. br.Msg = "获取失败"
  272. br.ErrMsg = "客户总数获取失败,Err:" + errtotal.Error()
  273. return
  274. }
  275. myTotal := len(respList.List)
  276. respList.Source = 1
  277. respList.Total = total
  278. respList.MyTotal = myTotal
  279. respList.ActivityId = activityId
  280. respList.SpecialType = activityInfo.SpecialType
  281. if activityInfo.LimitPeopleNum > 0 {
  282. respList.IsLimitPeople = 1
  283. }
  284. respList.MemberType = memberType
  285. br.Ret = 200
  286. br.Success = true
  287. br.Msg = "获取成功"
  288. br.Data = respList
  289. }
  290. // TripListExport 下载报名信息
  291. func TripListExport(this *ActivitySpecialTripCoAntroller, listDate []*cygx.CygxActivitySpecialTripResp) {
  292. br := new(models.BaseResponse).Init()
  293. defer func() {
  294. this.Data["json"] = br
  295. this.ServeJSON()
  296. }()
  297. sysUser := this.SysUser
  298. if sysUser == nil {
  299. br.Msg = "请登录"
  300. br.ErrMsg = "请登录,SysUser Is Empty"
  301. return
  302. }
  303. activityId, _ := this.GetInt("ActivityId")
  304. activityInfo, _ := cygx.GetAddActivityInfoSpecialById(activityId)
  305. if activityInfo == nil {
  306. br.Msg = "活动不存在"
  307. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  308. return
  309. }
  310. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  311. resp := new(cygx.CanDownload)
  312. adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
  313. if errAdmin != nil {
  314. br.Msg = "获取失败"
  315. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  316. return
  317. }
  318. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  319. resp.IsCanDownload = true
  320. }
  321. //创建excel
  322. dir, err := os.Executable()
  323. exPath := filepath.Dir(dir)
  324. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  325. xlsxFile := xlsx.NewFile()
  326. if err != nil {
  327. br.Msg = "生成文件失败"
  328. br.ErrMsg = "生成文件失败"
  329. return
  330. }
  331. style := xlsx.NewStyle()
  332. alignment := xlsx.Alignment{
  333. Horizontal: "center",
  334. Vertical: "center",
  335. WrapText: true,
  336. }
  337. style.Alignment = alignment
  338. style.ApplyAlignment = true
  339. sheetName := "报名名单"
  340. sheet, err := xlsxFile.AddSheet(sheetName)
  341. if err != nil {
  342. br.Msg = "新增Sheet失败"
  343. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  344. return
  345. }
  346. //标头
  347. if activityInfo.SpecialType == 1 || resp.IsCanDownload {
  348. rowTitle := sheet.AddRow()
  349. cellA := rowTitle.AddCell()
  350. cellA.Value = "姓名"
  351. cellB := rowTitle.AddCell()
  352. cellB.Value = "手机号"
  353. cellC := rowTitle.AddCell()
  354. cellC.Value = "公司名称"
  355. cellD := rowTitle.AddCell()
  356. cellD.Value = "所属销售"
  357. for _, item := range listDate {
  358. row := sheet.AddRow()
  359. cellA := row.AddCell()
  360. cellA.Value = item.RealName
  361. cellB := row.AddCell()
  362. cellB.Value = item.Mobile
  363. cellC := row.AddCell()
  364. cellC.Value = item.CompanyName
  365. cellD := row.AddCell()
  366. cellD.Value = item.SellerName
  367. }
  368. } else {
  369. rowTitle := sheet.AddRow()
  370. cellA := rowTitle.AddCell()
  371. cellA.Value = "姓名"
  372. cellB := rowTitle.AddCell()
  373. cellB.Value = "公司名称"
  374. cellC := rowTitle.AddCell()
  375. cellC.Value = "所属销售"
  376. for _, item := range listDate {
  377. row := sheet.AddRow()
  378. cellA := row.AddCell()
  379. cellA.Value = item.RealName
  380. cellB := row.AddCell()
  381. cellB.Value = item.CompanyName
  382. cellC := row.AddCell()
  383. cellC.Value = item.SellerName
  384. }
  385. }
  386. err = xlsxFile.Save(downLoadnFilePath)
  387. if err != nil {
  388. br.Msg = "保存文件失败"
  389. br.ErrMsg = "保存文件失败"
  390. return
  391. }
  392. downloadFileName := activityInfo.ResearchTheme + ".xlsx"
  393. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  394. defer func() {
  395. os.Remove(downLoadnFilePath)
  396. }()
  397. br.Success = true
  398. br.Ret = 200
  399. br.IsAddLog = true
  400. }
  401. // @Title 取消报名
  402. // @Description 取消报名接口
  403. // @Param request body cygx.ActivitySpecialTripCancelReq true "type json string"
  404. // @Success 200 操作成功
  405. // @router /special/trip/cancel [post]
  406. func (this *ActivitySpecialTripCoAntroller) TripCancel() {
  407. br := new(models.BaseResponse).Init()
  408. defer func() {
  409. this.Data["json"] = br
  410. this.ServeJSON()
  411. }()
  412. sysUser := this.SysUser
  413. if sysUser == nil {
  414. br.Msg = "请登录"
  415. br.ErrMsg = "请登录,SysUser Is Empty"
  416. return
  417. }
  418. var req cygx.ActivitySpecialTripCancelReq
  419. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  420. if err != nil {
  421. br.Msg = "参数解析异常!"
  422. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  423. return
  424. }
  425. userId := req.UserId
  426. activityId := req.ActivityId
  427. total, err := cygx.GetActivitySpecialTripCountByThisUser(activityId, strconv.Itoa(userId))
  428. if err != nil {
  429. br.Msg = "获取失败"
  430. br.ErrMsg = "获取失败,Err:" + err.Error()
  431. return
  432. }
  433. if total == 0 {
  434. br.Msg = "获取报名信息失败"
  435. br.ErrMsg = "获取失败,activityId:" + strconv.Itoa(activityId)
  436. return
  437. }
  438. activityInfo, errInfo := cygx.GetAddActivityInfoSpecialById(activityId)
  439. if activityInfo == nil {
  440. br.Msg = "操作失败"
  441. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  442. return
  443. }
  444. if errInfo != nil {
  445. br.Msg = "操作失败"
  446. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  447. return
  448. }
  449. infoUser, err := cygx.GetUserAndCompanyNameList(userId)
  450. if err != nil {
  451. br.Msg = "获取失败"
  452. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  453. return
  454. }
  455. //流水记录表
  456. itemBill := new(cygx.CygxActivitySpecialTripBill)
  457. itemBill.UserId = infoUser.UserId
  458. itemBill.ActivityId = activityInfo.ActivityId
  459. itemBill.CreateTime = time.Now()
  460. itemBill.Mobile = infoUser.Mobile
  461. itemBill.Email = infoUser.Email
  462. itemBill.CompanyId = infoUser.CompanyId
  463. itemBill.CompanyName = infoUser.CompanyName
  464. itemBill.RealName = infoUser.RealName
  465. itemBill.Source = 2
  466. itemBill.DoType = 2
  467. itemBill.BillDetailed = 1 // 流水加一
  468. itemBill.RegisterPlatform = 1
  469. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  470. itemBill.AdminId = sysUser.AdminId
  471. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  472. //48小时之内的取消也扣除一次参会记录
  473. var isValid int
  474. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  475. isValid = 1
  476. itemBill.BillDetailed = 0 // 48小时之内取消的,照样扣点,流水不进行加一
  477. }
  478. err = cygx.ActivitySpecialTripCancel(isValid, activityId, userId)
  479. if err != nil {
  480. br.Msg = "修改失败"
  481. br.ErrMsg = "修改失败 Err:" + err.Error()
  482. return
  483. }
  484. err = cygx.AddCygxActivitySpecialTripBill(itemBill)
  485. if err != nil {
  486. br.Msg = "修改失败"
  487. br.ErrMsg = "修改失败流水记录添加失败 Err:" + err.Error()
  488. return
  489. }
  490. br.Ret = 200
  491. br.Success = true
  492. br.Msg = "操作成功"
  493. br.IsAddLog = true
  494. }
  495. // @Title 到会详情/提交到会详情
  496. // @Description 报名详情列表接口
  497. // @Param ActivityId query int true "活动ID"
  498. // @Success 200 {object} cygx.GetAppointmentSpecialListRsep
  499. // @router /special/trip/meetDetial [get]
  500. func (this *ActivitySpecialTripCoAntroller) MeetDetial() {
  501. br := new(models.BaseResponse).Init()
  502. defer func() {
  503. this.Data["json"] = br
  504. this.ServeJSON()
  505. }()
  506. AdminUser := this.SysUser
  507. if AdminUser == nil {
  508. br.Msg = "请登录"
  509. br.ErrMsg = "请登录,SysUser Is Empty"
  510. return
  511. }
  512. activityId, _ := this.GetInt("ActivityId")
  513. if activityId < 1 {
  514. br.Msg = "活动不存在"
  515. return
  516. }
  517. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  518. if err != nil {
  519. br.Msg = "活动不存在"
  520. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  521. return
  522. }
  523. respList := new(cygx.SpecialMeetingDetailRespList)
  524. if activityInfo.IsSubmitMeeting == 0 {
  525. sqlStr := ` AND s.is_cancel = 0`
  526. list, err := cygx.GetCygxActivitySpecialTripList(activityId, sqlStr)
  527. if err != nil {
  528. br.Msg = "获取失败"
  529. br.ErrMsg = "获取失败,Err:" + err.Error()
  530. return
  531. }
  532. for _, v := range list {
  533. item := new(cygx.CygxActivitySpecialMeetingDetailResp)
  534. item.UserId = v.UserId
  535. item.RealName = v.RealName
  536. item.CompanyName = v.CompanyName
  537. respList.List = append(respList.List, item)
  538. }
  539. } else {
  540. respList.List, err = cygx.GetCygxActivitySpecialMeetingDetailListByActivity(activityId)
  541. if err != nil {
  542. br.Msg = "获取失败"
  543. br.ErrMsg = "获取失败,Err:" + err.Error()
  544. return
  545. }
  546. UserMap, err := cygxService.GetSpecialTripUserMap(activityId)
  547. if err != nil {
  548. br.Msg = "获取失败"
  549. br.ErrMsg = "获取失败,Err:" + err.Error()
  550. return
  551. }
  552. for k, v := range respList.List {
  553. if v.IsMeeting == 1 {
  554. if _, ok := UserMap[v.UserId]; !ok {
  555. respList.List[k].IsMeeting = 2
  556. }
  557. respList.List[k].Operation = true
  558. }
  559. }
  560. }
  561. br.Ret = 200
  562. br.Success = true
  563. br.Msg = "获取成功"
  564. br.Data = respList
  565. }
  566. // @Title 提交线下到会情况
  567. // @Description 提交线下到会情况接口
  568. // @Param request body cygx.MeetingDoRep true "type json string"
  569. // @Success 200 操作成功
  570. // @router /special/trip/meetingDo [post]
  571. func (this *ActivitySpecialTripCoAntroller) MeetingDo() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. this.Data["json"] = br
  575. this.ServeJSON()
  576. }()
  577. AdminUser := this.SysUser
  578. if AdminUser == nil {
  579. br.Msg = "请登录"
  580. br.ErrMsg = "请登录,用户信息为空"
  581. br.Ret = 408
  582. return
  583. }
  584. var req cygx.MeetingSpeciaDoRep
  585. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  586. if err != nil {
  587. br.Msg = "参数解析异常!"
  588. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  589. return
  590. }
  591. var userIdArr []int
  592. meetingUids := req.UserIds
  593. if len(meetingUids) == 0 {
  594. meetingUids = "0"
  595. } else {
  596. //过滤字段
  597. slice := strings.Split(meetingUids, ",")
  598. meetingUids = ""
  599. for _, v := range slice {
  600. if v != "" {
  601. meetingUids += v + ","
  602. userId, _ := strconv.Atoi(v)
  603. if userId > 0 {
  604. userIdArr = append(userIdArr, userId)
  605. }
  606. }
  607. }
  608. meetingUids = strings.TrimRight(meetingUids, ",")
  609. }
  610. activityId := req.ActivityId
  611. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  612. if err != nil {
  613. br.Msg = "活动不存在"
  614. br.ErrMsg = "活动ID错误,Err:activityId:" + strconv.Itoa(activityId)
  615. return
  616. }
  617. //校验活动后台管理员、销售是否有修改权限
  618. havePower, popupMsg, err := cygxService.CheckActivitySpecialUpdatePower(AdminUser.AdminId, activityInfo)
  619. if err != nil {
  620. br.Msg = "获取管理员身份信息失败"
  621. br.ErrMsg = "获取管理员身份信息失败,Err:" + err.Error()
  622. return
  623. }
  624. if !havePower {
  625. br.Msg = popupMsg
  626. return
  627. }
  628. noMeetingUids, err := cygx.GetSpecialTripUserIds(activityId, meetingUids) //未到会的用户ID
  629. if err != nil {
  630. br.Msg = "获取信息失败"
  631. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  632. return
  633. }
  634. var allUids string
  635. if len(noMeetingUids) > 0 {
  636. allUids = noMeetingUids + "," + meetingUids
  637. } else {
  638. allUids = meetingUids
  639. }
  640. listUser, err := cygx.GetUserAndCompanyNameListByUids(allUids)
  641. if err != nil {
  642. br.Msg = "获取失败"
  643. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  644. return
  645. }
  646. UserMap, err := cygxService.GetSpecialTripUserMap(activityId)
  647. if err != nil {
  648. br.Msg = "获取失败"
  649. br.ErrMsg = "获取失败,Err:" + err.Error()
  650. return
  651. }
  652. var items []*cygx.CygxActivitySpecialMeetingDetail
  653. for _, v := range listUser {
  654. var item = new(cygx.CygxActivitySpecialMeetingDetail)
  655. item.UserId = v.UserId
  656. item.ActivityId = activityId
  657. item.CreateTime = time.Now()
  658. item.Mobile = v.Mobile
  659. item.Email = v.Email
  660. item.CompanyId = v.CompanyId
  661. item.CompanyName = v.CompanyName
  662. item.IsMeeting = 1
  663. //添加空降人员字段
  664. if _, ok := UserMap[v.UserId]; !ok {
  665. item.IsAirborne = 1
  666. }
  667. items = append(items, item)
  668. }
  669. err = cygx.MeetingDopecialMeet(meetingUids, noMeetingUids, activityId, items)
  670. if err != nil {
  671. br.Msg = "操作失败"
  672. br.ErrMsg = "操作失败,Err:" + err.Error()
  673. return
  674. }
  675. go cygxService.ActivitySpecialUserLabelLogAdd(activityId, userIdArr)
  676. //添加操作日志记录
  677. br.Ret = 200
  678. br.Success = true
  679. br.Msg = "操作成功"
  680. br.IsAddLog = true
  681. }
  682. // @Title 修改外呼号码
  683. // @Description 修改外呼号码接口
  684. // @Param request body cygx.OutboundMobileEditResp true "type json string"
  685. // @Success 200 操作成功
  686. // @router /special/trip/outboundMobileEdit [post]
  687. func (this *ActivitySpecialTripCoAntroller) OutboundMobileEdit() {
  688. br := new(models.BaseResponse).Init()
  689. defer func() {
  690. this.Data["json"] = br
  691. this.ServeJSON()
  692. }()
  693. sysUser := this.SysUser
  694. if sysUser == nil {
  695. br.Msg = "请登录"
  696. br.ErrMsg = "请登录,SysUser Is Empty"
  697. return
  698. }
  699. var req cygx.OutboundMobileEditResp
  700. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  701. if err != nil {
  702. br.Msg = "参数解析异常!"
  703. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  704. return
  705. }
  706. id := req.Id
  707. outboundMobile := req.OutboundMobile
  708. countryCode := req.CountryCode
  709. err = cygx.SpecialTripOutboundMobileEdit(id, outboundMobile, countryCode)
  710. if err != nil {
  711. br.Msg = "修改失败"
  712. br.ErrMsg = "修改失败 Err:" + err.Error()
  713. return
  714. }
  715. br.Ret = 200
  716. br.Success = true
  717. br.Msg = "操作成功"
  718. br.IsAddLog = true
  719. }