activity_special_trip.go 30 KB

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