activity_special_trip.go 35 KB

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