activity_special_trip.go 25 KB

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