activity_special_trip.go 28 KB

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