activity_special.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/services"
  8. "hongze/hongze_clpt/utils"
  9. "strconv"
  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. conditionActivity := services.ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState)
  49. fmt.Println(conditionActivity)
  50. list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "", conditionActivity)
  51. if errList != nil {
  52. br.Msg = "获取失败"
  53. br.ErrMsg = "获取失败,Err:" + errList.Error()
  54. return
  55. }
  56. page := paging.GetPaging(currentIndex, pageSize, total)
  57. resp := new(models.GetCygxActivitySpecialDetailListResp)
  58. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  59. if err != nil {
  60. br.Msg = "获取数据失败!"
  61. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  62. return
  63. }
  64. if count == 1 && user.UserId > 0 {
  65. resp.IsFollow = true
  66. }
  67. if user.Mobile != "" {
  68. resp.IsBindingMobile = true
  69. }
  70. if len(list) == 0 {
  71. list = make([]*models.CygxActivitySpecialDetail, 0)
  72. }
  73. resp.List = list
  74. resp.Paging = page
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. br.Data = resp
  79. }
  80. // @Title 专项产业调研详情
  81. // @Description 获取专项产业调研详情接口
  82. // @Param ActivityId query int true "活动ID"
  83. // @Success Ret=200 {object} models.CygxActivitySpecialResp
  84. // @router /detail [get]
  85. func (this *ActivitySpecialController) SpecialDetail() {
  86. br := new(models.BaseResponse).Init()
  87. defer func() {
  88. this.Data["json"] = br
  89. this.ServeJSON()
  90. }()
  91. user := this.User
  92. if user == nil {
  93. br.Msg = "请登录"
  94. br.ErrMsg = "请登录,用户信息为空"
  95. br.Ret = 408
  96. return
  97. }
  98. uid := user.UserId
  99. activityId, _ := this.GetInt("ActivityId")
  100. if activityId < 1 {
  101. br.Msg = "请输入活动ID"
  102. return
  103. }
  104. resp := new(models.CygxActivitySpecialResp)
  105. activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
  106. if err != nil && err.Error() != utils.ErrNoRow() {
  107. br.Msg = "获取信息失败"
  108. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  109. return
  110. }
  111. if activityInfo == nil {
  112. br.Msg = "活动不存在"
  113. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  114. return
  115. }
  116. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  117. if err != nil {
  118. br.Msg = "获取信息失败"
  119. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  120. return
  121. }
  122. //判断有没有对应的权限,如果没有则给出对应的状态码
  123. if havePower {
  124. resp.HasPermission = 1
  125. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  126. if err != nil {
  127. br.Msg = "获取数据失败!"
  128. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  129. return
  130. }
  131. if count == 1 {
  132. resp.IsFollow = true
  133. }
  134. activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
  135. if err != nil {
  136. br.Msg = "获取数据失败!"
  137. br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
  138. return
  139. }
  140. var condition string
  141. var pars []interface{}
  142. condition += ` AND t.activity_id = ? AND t.is_cancel = 0 `
  143. pars = append(pars, activityInfo.ActivityId)
  144. tripTota, err := models.GetActivitySpecialTripCountByActivityId(condition, pars)
  145. if err != nil {
  146. br.Msg = "获取数据失败!"
  147. br.ErrMsg = "GetActivitySpecialTripCountByActivityId,Err:" + err.Error()
  148. return
  149. }
  150. activityInfo.TripNum = tripTota
  151. activityInfo.ActivityTypeName = "专项调研"
  152. resp.Detail = activityInfo
  153. resp.Detail = activityInfo
  154. } else {
  155. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  156. if err != nil {
  157. br.Msg = "获取信息失败"
  158. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  159. return
  160. }
  161. resp.PopupMsg = popupMsg
  162. resp.HasPermission = hasPermission
  163. resp.SellerName = sellerName
  164. resp.SellerMobile = sellerMobile
  165. }
  166. br.Ret = 200
  167. br.Success = true
  168. br.Msg = "获取成功"
  169. br.Data = resp
  170. }
  171. // @Title报名
  172. // @Description 报名
  173. // @Param request body models.ActivityIdRep true "type json string"
  174. // @Success Ret=200 {object} models.SignupSpecialStatus
  175. // @router /trip/add [post]
  176. func (this *ActivitySpecialController) SpecialTripAdd() {
  177. br := new(models.BaseResponse).Init()
  178. defer func() {
  179. this.Data["json"] = br
  180. this.ServeJSON()
  181. }()
  182. user := this.User
  183. if user == nil {
  184. br.Msg = "请登录"
  185. br.ErrMsg = "请登录,用户信息为空"
  186. br.Ret = 408
  187. return
  188. }
  189. uid := user.UserId
  190. var req models.ActivityIdRep
  191. resp := new(models.SignupSpecialStatus)
  192. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  193. if err != nil {
  194. br.Msg = "参数解析异常!"
  195. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  196. return
  197. }
  198. activityId := req.ActivityId
  199. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  200. if activityInfo == nil {
  201. br.Msg = "操作失败"
  202. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  203. return
  204. }
  205. if errInfo != nil {
  206. br.Msg = "操作失败"
  207. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  208. return
  209. }
  210. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  211. if err != nil {
  212. br.Msg = "获取信息失败"
  213. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  214. return
  215. }
  216. //判断有没有对应的权限,如果没有则给出对应的状态码
  217. if havePower {
  218. resp.HasPermission = 1
  219. signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
  220. if err != nil {
  221. br.Msg = "获取信息失败"
  222. br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
  223. return
  224. }
  225. resp.PopupMsg = popupMsg
  226. resp.PopupMsg2 = popupMsg2
  227. resp.SignupStatus = signupStatus
  228. if signupStatus == 1 {
  229. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  230. if err != nil {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  233. return
  234. }
  235. //判断是删除还是添加
  236. if total == 0 {
  237. //获取销售信息
  238. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  239. if err != nil {
  240. br.Msg = "操作失败"
  241. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  242. return
  243. }
  244. item := new(models.CygxActivitySpecialTrip)
  245. item.UserId = uid
  246. item.RealName = user.RealName
  247. item.ActivityId = activityId
  248. item.CreateTime = time.Now()
  249. item.Mobile = user.Mobile
  250. item.Email = user.Email
  251. item.CompanyId = user.CompanyId
  252. item.CompanyName = user.CompanyName
  253. item.IsValid = 1
  254. if sellerItem != nil {
  255. item.SellerName = sellerItem.RealName
  256. }
  257. err = models.AddCygxActivitySpecialTrip(item)
  258. if err != nil {
  259. br.Msg = "操作失败"
  260. br.ErrMsg = "操作失败,Err:" + err.Error()
  261. return
  262. }
  263. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  264. } else {
  265. updateParams := make(map[string]interface{})
  266. updateParams["IsValid"] = 1
  267. updateParams["CreateTime"] = time.Now()
  268. updateParams["IsCancel"] = 0
  269. whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
  270. err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
  271. if err != nil {
  272. br.Msg = "报名失败,"
  273. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  274. return
  275. }
  276. }
  277. }
  278. } else {
  279. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  280. if err != nil {
  281. br.Msg = "获取信息失败"
  282. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  283. return
  284. }
  285. resp.PopupMsg = popupMsg
  286. resp.HasPermission = hasPermission
  287. resp.SellerName = sellerName
  288. resp.SellerMobile = sellerMobile
  289. }
  290. resp.ActivityId = activityId
  291. br.Ret = 200
  292. br.Success = true
  293. br.Msg = "操作成功"
  294. br.Data = resp
  295. }
  296. // @Title 取消报名
  297. // @Description 取消报名
  298. // @Param request body models.ActivityIdRep true "type json string"
  299. // @Success Ret=200 {object} models.SignupStatus
  300. // @router /trip/cancel [post]
  301. func (this *ActivitySpecialController) Tripcancel() {
  302. br := new(models.BaseResponse).Init()
  303. defer func() {
  304. this.Data["json"] = br
  305. this.ServeJSON()
  306. }()
  307. user := this.User
  308. if user == nil {
  309. br.Msg = "请登录"
  310. br.ErrMsg = "请登录,用户信息为空"
  311. br.Ret = 408
  312. return
  313. }
  314. uid := user.UserId
  315. var req models.ActivityIdRep
  316. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  317. if err != nil {
  318. br.Msg = "参数解析异常!"
  319. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  320. return
  321. }
  322. activityId := req.ActivityId
  323. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  324. if activityInfo == nil {
  325. br.Msg = "操作失败"
  326. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  327. return
  328. }
  329. if errInfo != nil {
  330. br.Msg = "操作失败"
  331. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  332. return
  333. }
  334. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  335. //48小时之内的取消也扣除一次参会记录
  336. var isValid int
  337. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  338. isValid = 1
  339. }
  340. err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
  341. if err != nil {
  342. br.Msg = "操作失败"
  343. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  344. return
  345. }
  346. br.Ret = 200
  347. br.Success = true
  348. br.Msg = "已取消"
  349. }
  350. // @Title 感兴趣、不感兴趣
  351. // @Description 感兴趣、不感兴趣接口
  352. // @Param request body models.ActivityIdRep true "type json string"
  353. // @Success Ret=200 {object} models.SignupSpecialStatus
  354. // @router /signup/add [post]
  355. func (this *ActivitySpecialController) SpecialSignupAdd() {
  356. br := new(models.BaseResponse).Init()
  357. defer func() {
  358. this.Data["json"] = br
  359. this.ServeJSON()
  360. }()
  361. user := this.User
  362. if user == nil {
  363. br.Msg = "请登录"
  364. br.ErrMsg = "请登录,用户信息为空"
  365. br.Ret = 408
  366. return
  367. }
  368. uid := user.UserId
  369. var req models.ActivityIdRep
  370. resp := new(models.SignupSpecialStatus)
  371. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  372. if err != nil {
  373. br.Msg = "参数解析异常!"
  374. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  375. return
  376. }
  377. activityId := req.ActivityId
  378. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  379. if activityInfo == nil {
  380. br.Msg = "操作失败"
  381. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  382. return
  383. }
  384. if errInfo != nil {
  385. br.Msg = "操作失败"
  386. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  387. return
  388. }
  389. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  390. if err != nil {
  391. br.Msg = "获取信息失败"
  392. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  393. return
  394. }
  395. //判断有没有对应的权限,如果没有则给出对应的状态码
  396. if havePower {
  397. resp.HasPermission = 1
  398. total, err := models.GetUserCygxActivitySpecialSignup(user.UserId, activityId)
  399. if err != nil {
  400. br.Msg = "获取信息失败"
  401. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  402. return
  403. }
  404. resp.SignupStatus = 1
  405. //判断是删除还是添加
  406. if total == 0 {
  407. //获取销售信息
  408. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  409. if err != nil {
  410. br.Msg = "操作失败"
  411. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  412. return
  413. }
  414. item := new(models.CygxActivitySpecialSignup)
  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. }