activity_special.go 16 KB

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