activity_special.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // 专项调研活动
  13. type ActivitySpecialController struct {
  14. BaseAuthController
  15. }
  16. // @Title 专项产业调研列表
  17. // @Description 获取专项产业调研列表接口
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  21. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  22. // @Param WhichDay query string false "哪一天 今天:1、明天:2, 本周:3 上周:4,本月:5上月:6多个用 , 隔开"
  23. // @Success 200 {object} models.GetCygxActivitySpecialDetailListResp
  24. // @router /list [get]
  25. func (this *ActivitySpecialController) SpecialList() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. user := this.User
  32. if user == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. return
  36. }
  37. pageSize, _ := this.GetInt("PageSize")
  38. currentIndex, _ := this.GetInt("CurrentIndex")
  39. chartPermissionIds := this.GetString("ChartPermissionIds")
  40. whichDay := this.GetString("WhichDay")
  41. activeState := this.GetString("ActiveState")
  42. if pageSize <= 0 {
  43. pageSize = utils.PageSize20
  44. }
  45. if currentIndex <= 0 {
  46. currentIndex = 1
  47. }
  48. if activeState == "1" {
  49. activeState = ""
  50. }
  51. conditionActivity := services.ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState)
  52. list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "", conditionActivity, activeState)
  53. if errList != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取失败,Err:" + errList.Error()
  56. return
  57. }
  58. page := paging.GetPaging(currentIndex, pageSize, total)
  59. resp := new(models.GetCygxActivitySpecialDetailListResp)
  60. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  61. if err != nil {
  62. br.Msg = "获取数据失败!"
  63. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  64. return
  65. }
  66. if count == 1 && user.UserId > 0 {
  67. resp.IsFollow = true
  68. }
  69. if user.Mobile != "" {
  70. resp.IsBindingMobile = true
  71. }
  72. if len(list) == 0 {
  73. list = make([]*models.CygxActivitySpecialDetail, 0)
  74. }
  75. resp.List = list
  76. resp.Paging = page
  77. br.Ret = 200
  78. br.Success = true
  79. br.Msg = "获取成功"
  80. br.Data = resp
  81. }
  82. // @Title 专项产业调研详情
  83. // @Description 获取专项产业调研详情接口
  84. // @Param ActivityId query int true "活动ID"
  85. // @Success Ret=200 {object} models.CygxActivitySpecialResp
  86. // @router /detail [get]
  87. func (this *ActivitySpecialController) SpecialDetail() {
  88. br := new(models.BaseResponse).Init()
  89. defer func() {
  90. this.Data["json"] = br
  91. this.ServeJSON()
  92. }()
  93. user := this.User
  94. if user == nil {
  95. br.Msg = "请登录"
  96. br.ErrMsg = "请登录,用户信息为空"
  97. br.Ret = 408
  98. return
  99. }
  100. uid := user.UserId
  101. activityId, _ := this.GetInt("ActivityId")
  102. if activityId < 1 {
  103. br.Msg = "请输入活动ID"
  104. return
  105. }
  106. resp := new(models.CygxActivitySpecialResp)
  107. activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
  108. if err != nil && err.Error() != utils.ErrNoRow() {
  109. br.Msg = "获取信息失败"
  110. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  111. return
  112. }
  113. if activityInfo == nil {
  114. br.Msg = "活动不存在"
  115. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  116. return
  117. }
  118. //havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  119. //if err != nil {
  120. // br.Msg = "获取信息失败"
  121. // br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  122. // return
  123. //}
  124. var havePower bool
  125. havePower = true
  126. //判断有没有对应的权限,如果没有则给出对应的状态码
  127. if havePower {
  128. resp.HasPermission = 1
  129. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  130. if err != nil {
  131. br.Msg = "获取数据失败!"
  132. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  133. return
  134. }
  135. if count == 1 {
  136. resp.IsFollow = true
  137. }
  138. activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
  139. if err != nil {
  140. br.Msg = "获取数据失败!"
  141. br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
  142. return
  143. }
  144. var condition string
  145. var pars []interface{}
  146. condition += ` AND t.activity_id = ? AND t.is_cancel = 0 `
  147. pars = append(pars, activityInfo.ActivityId)
  148. tripTota, err := models.GetActivitySpecialTripCountByActivityId(condition, pars)
  149. if err != nil {
  150. br.Msg = "获取数据失败!"
  151. br.ErrMsg = "GetActivitySpecialTripCountByActivityId,Err:" + err.Error()
  152. return
  153. }
  154. activityInfo.TripNum = tripTota
  155. activityInfo.ActivityTypeName = "专项调研"
  156. resp.Detail = activityInfo
  157. resp.Detail = activityInfo
  158. } else {
  159. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  160. if err != nil {
  161. br.Msg = "获取信息失败"
  162. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  163. return
  164. }
  165. resp.PopupMsg = popupMsg
  166. resp.HasPermission = hasPermission
  167. resp.SellerName = sellerName
  168. resp.SellerMobile = sellerMobile
  169. }
  170. br.Ret = 200
  171. br.Success = true
  172. br.Msg = "获取成功"
  173. br.Data = resp
  174. }
  175. // @Title报名
  176. // @Description 报名
  177. // @Param request body models.ActivityIdRep true "type json string"
  178. // @Success Ret=200 {object} models.SignupSpecialStatus
  179. // @router /trip/add [post]
  180. func (this *ActivitySpecialController) SpecialTripAdd() {
  181. br := new(models.BaseResponse).Init()
  182. defer func() {
  183. this.Data["json"] = br
  184. this.ServeJSON()
  185. }()
  186. user := this.User
  187. if user == nil {
  188. br.Msg = "请登录"
  189. br.ErrMsg = "请登录,用户信息为空"
  190. br.Ret = 408
  191. return
  192. }
  193. uid := user.UserId
  194. var req models.ActivityIdRep
  195. resp := new(models.SignupSpecialStatus)
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. activityId := req.ActivityId
  203. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  204. if activityInfo == nil {
  205. br.Msg = "操作失败"
  206. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  207. return
  208. }
  209. if errInfo != nil {
  210. br.Msg = "操作失败"
  211. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  212. return
  213. }
  214. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  215. if err != nil {
  216. br.Msg = "获取信息失败"
  217. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  218. return
  219. }
  220. //判断有没有对应的权限,如果没有则给出对应的状态码
  221. if havePower {
  222. resp.HasPermission = 1
  223. signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
  224. if err != nil {
  225. br.Msg = "获取信息失败"
  226. br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
  227. return
  228. }
  229. resp.PopupMsg = popupMsg
  230. resp.PopupMsg2 = popupMsg2
  231. resp.SignupStatus = signupStatus
  232. if signupStatus == 1 {
  233. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  234. if err != nil {
  235. br.Msg = "获取信息失败"
  236. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  237. return
  238. }
  239. //流水记录表
  240. itemBill := new(models.CygxActivitySpecialTripBill)
  241. itemBill.UserId = user.UserId
  242. itemBill.ActivityId = activityInfo.ActivityId
  243. itemBill.CreateTime = time.Now()
  244. itemBill.Mobile = user.Mobile
  245. itemBill.Email = user.Email
  246. itemBill.CompanyId = user.CompanyId
  247. itemBill.CompanyName = user.CompanyName
  248. itemBill.RealName = user.RealName
  249. itemBill.Source = 1
  250. itemBill.DoType = 1
  251. itemBill.BillDetailed = -1 // 流水减一
  252. itemBill.RegisterPlatform = 1
  253. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  254. itemBill.ChartPermissionName = activityInfo.ChartPermissionName
  255. var itemMeeting = new(models.CygxActivitySpecialMeetingDetail)
  256. itemMeeting.UserId = user.UserId
  257. itemMeeting.ActivityId = activityId
  258. itemMeeting.CreateTime = time.Now()
  259. itemMeeting.Mobile = user.Mobile
  260. itemMeeting.Email = user.Email
  261. itemMeeting.CompanyId = user.CompanyId
  262. itemMeeting.CompanyName = user.CompanyName
  263. itemMeeting.RealName = user.RealName
  264. go services.ActivitySpecialUserRmind(user, activityId, 2)
  265. go services.ActivitySpecialUserAddTrip(user, activityId)
  266. //判断是删除还是添加
  267. if total == 0 {
  268. //获取销售信息
  269. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  270. if err != nil {
  271. br.Msg = "操作失败"
  272. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  273. return
  274. }
  275. item := new(models.CygxActivitySpecialTrip)
  276. item.UserId = uid
  277. item.RealName = user.RealName
  278. item.ActivityId = activityId
  279. item.CreateTime = time.Now()
  280. item.Mobile = user.Mobile
  281. item.Email = user.Email
  282. item.CompanyId = user.CompanyId
  283. item.CompanyName = user.CompanyName
  284. item.IsValid = 1
  285. if sellerItem != nil {
  286. item.SellerName = sellerItem.RealName
  287. }
  288. if user.OutboundMobile != "" {
  289. item.OutboundMobile = user.OutboundMobile
  290. if user.OutboundCountryCode == "" {
  291. item.CountryCode = "86"
  292. } else {
  293. item.CountryCode = user.OutboundCountryCode
  294. }
  295. } else {
  296. item.OutboundMobile = user.Mobile
  297. if user.CountryCode == "" {
  298. item.CountryCode = "86"
  299. } else {
  300. item.CountryCode = user.CountryCode
  301. }
  302. }
  303. err = models.AddCygxActivitySpecialTrip(item)
  304. if err != nil {
  305. br.Msg = "操作失败"
  306. br.ErrMsg = "操作失败,Err:" + err.Error()
  307. return
  308. }
  309. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  310. } else {
  311. updateParams := make(map[string]interface{})
  312. updateParams["IsValid"] = 1
  313. updateParams["CreateTime"] = time.Now()
  314. updateParams["IsCancel"] = 0
  315. whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
  316. err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
  317. if err != nil {
  318. br.Msg = "报名失败,"
  319. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  320. return
  321. }
  322. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  323. //48小时之内的取消也扣除一次参会记录
  324. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  325. itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
  326. }
  327. }
  328. userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
  329. if err != nil {
  330. br.Msg = "获取专项调研剩余次数失败"
  331. br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  332. return
  333. }
  334. if userType == 2 {
  335. tripRemaining = tripRemaining + itemBill.BillDetailed
  336. itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  337. } else {
  338. for k, num := range mapChartName {
  339. if activityInfo.ChartPermissionName == k {
  340. num = num + itemBill.BillDetailed
  341. }
  342. itemBill.Total += k + strconv.Itoa(num) + "次+"
  343. }
  344. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  345. }
  346. //添加流水记录
  347. err = models.AddCygxActivitySpecialTripBill(itemBill)
  348. if err != nil {
  349. br.Msg = "报名失败,"
  350. br.ErrMsg = "AddCygxActivitySpecialTripBill,Err:" + err.Error()
  351. return
  352. }
  353. //添加数据到会信息
  354. err = models.AddCygxActivitySpecialMeetingDetail(itemMeeting)
  355. if err != nil {
  356. br.Msg = "报名失败,"
  357. br.ErrMsg = "AddCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  358. return
  359. }
  360. }
  361. } else {
  362. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  363. if err != nil {
  364. br.Msg = "获取信息失败"
  365. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  366. return
  367. }
  368. resp.PopupMsg = popupMsg
  369. resp.HasPermission = hasPermission
  370. resp.SellerName = sellerName
  371. resp.SellerMobile = sellerMobile
  372. }
  373. resp.ActivityId = activityId
  374. br.Ret = 200
  375. br.Success = true
  376. br.Msg = "操作成功"
  377. br.Data = resp
  378. }
  379. // @Title 取消报名
  380. // @Description 取消报名
  381. // @Param request body models.ActivityIdRep true "type json string"
  382. // @Success Ret=200 {object} models.SignupStatus
  383. // @router /trip/cancel [post]
  384. func (this *ActivitySpecialController) Tripcancel() {
  385. br := new(models.BaseResponse).Init()
  386. defer func() {
  387. this.Data["json"] = br
  388. this.ServeJSON()
  389. }()
  390. user := this.User
  391. if user == nil {
  392. br.Msg = "请登录"
  393. br.ErrMsg = "请登录,用户信息为空"
  394. br.Ret = 408
  395. return
  396. }
  397. uid := user.UserId
  398. var req models.ActivityIdRep
  399. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  400. if err != nil {
  401. br.Msg = "参数解析异常!"
  402. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  403. return
  404. }
  405. activityId := req.ActivityId
  406. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  407. if activityInfo == nil {
  408. br.Msg = "操作失败"
  409. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  410. return
  411. }
  412. if errInfo != nil {
  413. br.Msg = "操作失败"
  414. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  415. return
  416. }
  417. //流水记录表
  418. itemBill := new(models.CygxActivitySpecialTripBill)
  419. itemBill.UserId = user.UserId
  420. itemBill.ActivityId = activityInfo.ActivityId
  421. itemBill.CreateTime = time.Now()
  422. itemBill.Mobile = user.Mobile
  423. itemBill.Email = user.Email
  424. itemBill.CompanyId = user.CompanyId
  425. itemBill.CompanyName = user.CompanyName
  426. itemBill.RealName = user.RealName
  427. itemBill.Source = 1
  428. itemBill.DoType = 2
  429. itemBill.BillDetailed = 1 // 流水加一
  430. itemBill.RegisterPlatform = 1
  431. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  432. itemBill.ChartPermissionName = activityInfo.ChartPermissionName
  433. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  434. //48小时之内的取消也扣除一次参会记录
  435. var isValid int
  436. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  437. isValid = 1
  438. itemBill.BillDetailed = 0 //48小时之内取消的活动扣点不返回
  439. }
  440. userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
  441. if err != nil {
  442. br.Msg = "获取专项调研剩余次数失败"
  443. br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  444. return
  445. }
  446. if userType == 2 {
  447. tripRemaining += itemBill.BillDetailed
  448. itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  449. } else {
  450. for k, num := range mapChartName {
  451. if activityInfo.ChartPermissionName == k {
  452. num += itemBill.BillDetailed
  453. }
  454. itemBill.Total += k + strconv.Itoa(num) + "次+"
  455. }
  456. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  457. }
  458. err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
  459. if err != nil {
  460. br.Msg = "操作失败"
  461. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  462. return
  463. }
  464. err = models.CancelCygxActivitySpecialMeetingDetail(uid, activityId)
  465. if err != nil {
  466. br.Msg = "操作失败"
  467. br.ErrMsg = "CancelCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  468. return
  469. }
  470. go models.AddCygxActivitySpecialTripBill(itemBill)
  471. br.Ret = 200
  472. br.Success = true
  473. br.Msg = "已取消"
  474. }
  475. // @Title 感兴趣、不感兴趣
  476. // @Description 感兴趣、不感兴趣接口
  477. // @Param request body models.ActivityIdRep true "type json string"
  478. // @Success Ret=200 {object} models.SignupSpecialStatus
  479. // @router /signup/add [post]
  480. func (this *ActivitySpecialController) SpecialSignupAdd() {
  481. br := new(models.BaseResponse).Init()
  482. defer func() {
  483. this.Data["json"] = br
  484. this.ServeJSON()
  485. }()
  486. user := this.User
  487. if user == nil {
  488. br.Msg = "请登录"
  489. br.ErrMsg = "请登录,用户信息为空"
  490. br.Ret = 408
  491. return
  492. }
  493. uid := user.UserId
  494. var req models.ActivityIdRep
  495. resp := new(models.SignupSpecialStatus)
  496. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  497. if err != nil {
  498. br.Msg = "参数解析异常!"
  499. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  500. return
  501. }
  502. activityId := req.ActivityId
  503. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  504. if activityInfo == nil {
  505. br.Msg = "操作失败"
  506. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  507. return
  508. }
  509. if errInfo != nil {
  510. br.Msg = "操作失败"
  511. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  512. return
  513. }
  514. //havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  515. //if err != nil {
  516. // br.Msg = "获取信息失败"
  517. // br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  518. // return
  519. //}
  520. var havePower bool
  521. havePower = true
  522. //判断有没有对应的权限,如果没有则给出对应的状态码
  523. if havePower {
  524. resp.HasPermission = 1
  525. total, err := models.GetUserCygxActivitySpecialSignup(user.UserId, activityId)
  526. if err != nil {
  527. br.Msg = "获取信息失败"
  528. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  529. return
  530. }
  531. resp.SignupStatus = 1
  532. //判断是删除还是添加
  533. if total == 0 {
  534. //获取销售信息
  535. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  536. if err != nil {
  537. br.Msg = "操作失败"
  538. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  539. return
  540. }
  541. item := new(models.CygxActivitySpecialSignup)
  542. item.RegisterPlatform = utils.REGISTER_PLATFORM
  543. item.UserId = uid
  544. item.RealName = user.RealName
  545. item.ActivityId = activityId
  546. item.CreateTime = time.Now()
  547. item.Mobile = user.Mobile
  548. item.Email = user.Email
  549. item.CompanyId = user.CompanyId
  550. item.CompanyName = user.CompanyName
  551. if sellerItem != nil {
  552. item.SellerName = sellerItem.RealName
  553. }
  554. err = models.AddCygxActivitySpecialSignup(item)
  555. if err != nil {
  556. br.Msg = "操作失败"
  557. br.ErrMsg = "操作失败,Err:" + err.Error()
  558. return
  559. }
  560. resp.Status = 1
  561. resp.PopupMsg = "感谢反馈"
  562. resp.PopupMsg2 = "此调研具体行程尚未确认,待预报名人数满10人后弘则会确定行程并推送给您活动日期,只有在确认行程中再次报名才完成占位。"
  563. //给所属销售发送消息
  564. //if sellerItem.Mobile != "" {
  565. // openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  566. // if openIpItem != nil && openIpItem.OpenId != "" {
  567. // if sellerItem != nil {
  568. // //go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
  569. // }
  570. // }
  571. //}
  572. // 给芳姐发消息
  573. actList, _ := models.GetActivityListSpecialByActivityId(activityId)
  574. if len(actList) == 10 {
  575. go services.SendWxMsgActivitySpecial10(activityInfo)
  576. }
  577. //用户专项调研操作行为,模板消息推送
  578. //go services.SpecialActivityUserRemind(user, activityInfo, 1)
  579. } else {
  580. err = models.DeleteCygxActivitySpecialSignup(user.UserId, activityId)
  581. if err != nil {
  582. br.Msg = "操作失败"
  583. br.ErrMsg = "操作失败,Err:" + err.Error()
  584. return
  585. }
  586. resp.Status = 2
  587. }
  588. } else {
  589. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  590. if err != nil {
  591. br.Msg = "获取信息失败"
  592. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  593. return
  594. }
  595. resp.PopupMsg = popupMsg
  596. resp.HasPermission = hasPermission
  597. resp.SellerName = sellerName
  598. resp.SellerMobile = sellerMobile
  599. }
  600. br.Ret = 200
  601. br.Success = true
  602. br.Msg = "操作成功"
  603. br.Data = resp
  604. }
  605. // @Title 新调研通知取消跟添加
  606. // @Description 新调研通知取消跟添加接口
  607. // @Param request body models.ArticleCollectResp true "type json string"
  608. // @Success 200
  609. // @router /follow [post]
  610. func (this *ActivitySpecialController) SpecialMsg() {
  611. br := new(models.BaseResponse).Init()
  612. defer func() {
  613. this.Data["json"] = br
  614. this.ServeJSON()
  615. }()
  616. user := this.User
  617. if user == nil {
  618. br.Msg = "请重新登录"
  619. br.Ret = 408
  620. return
  621. }
  622. resp := new(models.ArticleCollectResp)
  623. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  624. if err != nil {
  625. br.Msg = "获取数据失败!"
  626. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  627. return
  628. }
  629. if count == 0 {
  630. item := new(models.CygxUserFollowSpecial)
  631. item.UserId = user.UserId
  632. item.RealName = user.RealName
  633. item.CreateTime = time.Now()
  634. item.Mobile = user.Mobile
  635. item.Email = user.Email
  636. item.CompanyId = user.CompanyId
  637. item.CompanyName = user.CompanyName
  638. item.CreateTime = time.Now()
  639. err := models.AddUserFollowSpecial(item)
  640. if err != nil {
  641. br.Msg = "操作失败!"
  642. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  643. return
  644. }
  645. resp.Status = 1
  646. } else {
  647. err := models.DeleteCygxUserFollowSpecial(user.UserId)
  648. if err != nil {
  649. br.Msg = "操作失败!"
  650. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  651. return
  652. }
  653. resp.Status = 2
  654. }
  655. br.Ret = 200
  656. br.Data = resp
  657. br.Success = true
  658. br.Msg = "操作成功!"
  659. }