activity_special.go 17 KB

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