activity.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "rdluck_tools/paging"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //活动
  13. type ActivityCoAntroller struct {
  14. BaseAuthController
  15. }
  16. // @Title 活动类型列表
  17. // @Description活动类型列表接口
  18. // @Success 200 {object} models.ActivityTypeListResp
  19. // @router /activityTypelist [get]
  20. func (this *ActivityCoAntroller) List() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. user := this.User
  27. if user == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser Is Empty"
  30. br.Ret = 408
  31. return
  32. }
  33. resp := new(models.ActivityTypeListResp)
  34. list, err := models.GetActivityTypeList()
  35. if err != nil {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  38. return
  39. }
  40. resp.List = list
  41. br.Ret = 200
  42. br.Success = true
  43. br.Msg = "获取成功"
  44. br.Data = resp
  45. }
  46. // @Title 活动列表
  47. // @Description 获取活动列表接口
  48. // @Param PageSize query int true "每页数据条数"
  49. // @Param CurrentIndex query int true "当前页页码,从1开始"
  50. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  51. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  52. // @Param KeyWord query string false "搜索关键词"
  53. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  54. // @Param IsShowJurisdiction query int false "是否仅展示有权限的,1是,2否 默认为零"
  55. // @Success 200 {object} models.GetCygxActivityListRep
  56. // @router /list [get]
  57. func (this *ActivityCoAntroller) ActivityList() {
  58. br := new(models.BaseResponse).Init()
  59. defer func() {
  60. this.Data["json"] = br
  61. this.ServeJSON()
  62. }()
  63. user := this.User
  64. if user == nil {
  65. br.Msg = "请登录"
  66. br.ErrMsg = "请登录,SysUser Is Empty"
  67. return
  68. }
  69. uid := user.UserId
  70. pageSize, _ := this.GetInt("PageSize")
  71. currentIndex, _ := this.GetInt("CurrentIndex")
  72. chartPermissionIds := this.GetString("ChartPermissionIds")
  73. activityTypeIds := this.GetString("ActivityTypeIds")
  74. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  75. keyWord := this.GetString("KeyWord")
  76. activeState := this.GetString("ActiveState")
  77. if activeState == "" {
  78. activeState = "1"
  79. }
  80. //if isShowJurisdiction != 1 {
  81. // isShowJurisdiction = 0
  82. //}
  83. itemSearch := new(models.CygxActivityUserSearchContent)
  84. itemSearch.UserId = uid
  85. itemSearch.CreateTime = time.Now()
  86. itemSearch.Mobile = user.Mobile
  87. itemSearch.Email = user.Email
  88. itemSearch.CompanyId = user.CompanyId
  89. itemSearch.CompanyName = user.CompanyName
  90. itemSearch.ModifyTime = time.Now()
  91. itemSearch.ChartPermissionids = chartPermissionIds
  92. itemSearch.ActivityTypeids = activityTypeIds
  93. itemSearch.ActiveState = activeState
  94. itemSearch.IsShowJurisdiction = isShowJurisdiction
  95. _, errSearch := models.AddUserSearchContent(itemSearch)
  96. if errSearch != nil {
  97. br.Msg = "操作失败"
  98. br.ErrMsg = "操作失败,Err:" + errSearch.Error()
  99. return
  100. }
  101. if isShowJurisdiction == 1 && chartPermissionIds == "" {
  102. resp := new(models.GetCygxActivityListRep)
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "获取成功"
  106. br.Data = resp
  107. }
  108. var startSize int
  109. if pageSize <= 0 {
  110. pageSize = utils.PageSize20
  111. }
  112. if currentIndex <= 0 {
  113. currentIndex = 1
  114. }
  115. startSize = utils.StartIndex(currentIndex, pageSize)
  116. var condition string
  117. var pars []interface{}
  118. if keyWord != "" {
  119. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' ) `
  120. }
  121. //行业名称
  122. if len(chartPermissionIds) > 0 {
  123. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  124. }
  125. condition += ` AND art.publish_status = 1 AND art.active_state IN (` + activeState + `)`
  126. total, err := models.GetActivityCount(condition, pars)
  127. if err != nil {
  128. br.Msg = "获取失败"
  129. br.ErrMsg = "获取失败,Err:" + err.Error()
  130. return
  131. }
  132. if activeState != "1" {
  133. condition += ` ORDER BY art.activity_time DESC `
  134. }
  135. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  136. if errList != nil {
  137. br.Msg = "获取失败"
  138. br.ErrMsg = "获取失败,Err:" + errList.Error()
  139. return
  140. }
  141. for k, v := range list {
  142. if strings.Contains(v.ActivityName, "【") {
  143. list[k].IsBrackets = 1
  144. }
  145. }
  146. page := paging.GetPaging(currentIndex, pageSize, total)
  147. resp := new(models.GetCygxActivityListRep)
  148. resp.List = list
  149. resp.Paging = page
  150. br.Ret = 200
  151. br.Success = true
  152. br.Msg = "获取成功"
  153. br.Data = resp
  154. }
  155. // @Title 我的日程
  156. // @Description 我的日程列表接口
  157. // @Param PageSize query int true "每页数据条数"
  158. // @Param CurrentIndex query int true "当前页页码,从1开始"
  159. // @Success 200 {object} models.GetCygxActivityListRep
  160. // @router /scheduleList [get]
  161. func (this *ActivityCoAntroller) ScheduleList() {
  162. br := new(models.BaseResponse).Init()
  163. defer func() {
  164. this.Data["json"] = br
  165. this.ServeJSON()
  166. }()
  167. user := this.User
  168. if user == nil {
  169. br.Msg = "请登录"
  170. br.ErrMsg = "请登录,SysUser Is Empty"
  171. return
  172. }
  173. uid := user.UserId
  174. pageSize, _ := this.GetInt("PageSize")
  175. currentIndex, _ := this.GetInt("CurrentIndex")
  176. var startSize int
  177. if pageSize <= 0 {
  178. pageSize = utils.PageSize20
  179. }
  180. if currentIndex <= 0 {
  181. currentIndex = 1
  182. }
  183. startSize = utils.StartIndex(currentIndex, pageSize)
  184. var condition string
  185. var pars []interface{}
  186. condition += ` AND art.publish_status = 1 AND art.active_state IN(1,2) AND s.is_cancel = 0 AND s.fail_type = 0 `
  187. total, err := models.GetScheduleCount(condition, uid)
  188. if err != nil {
  189. br.Msg = "获取失败"
  190. br.ErrMsg = "获取失败,Err:" + err.Error()
  191. return
  192. }
  193. list, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  194. if errList != nil {
  195. br.Msg = "获取失败"
  196. br.ErrMsg = "获取失败,Err:" + errList.Error()
  197. return
  198. }
  199. for k, v := range list {
  200. if strings.Contains(v.ActivityName, "【") {
  201. list[k].IsBrackets = 1
  202. }
  203. }
  204. page := paging.GetPaging(currentIndex, pageSize, total)
  205. resp := new(models.GetCygxActivityListRep)
  206. resp.List = list
  207. resp.Paging = page
  208. br.Ret = 200
  209. br.Success = true
  210. br.Msg = "获取成功"
  211. br.Data = resp
  212. }
  213. // @Title 活动详情
  214. // @Description 获取活动详情接口
  215. // @Param ActivityId query int true "活动ID"
  216. // @Success Ret=200 {object} models.ActivityDetail
  217. // @router /detail [get]
  218. func (this *ActivityCoAntroller) Detail() {
  219. br := new(models.BaseResponse).Init()
  220. defer func() {
  221. this.Data["json"] = br
  222. this.ServeJSON()
  223. }()
  224. user := this.User
  225. if user == nil {
  226. br.Msg = "请登录"
  227. br.ErrMsg = "请登录,用户信息为空"
  228. br.Ret = 408
  229. return
  230. }
  231. uid := user.UserId
  232. activityId, _ := this.GetInt("ActivityId")
  233. if activityId < 1 {
  234. br.Msg = "请输入活动ID"
  235. return
  236. }
  237. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  238. if activityInfo == nil {
  239. br.Msg = "活动不存在"
  240. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  241. return
  242. }
  243. detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  244. if errDetail != nil {
  245. br.Msg = "获取信息失败"
  246. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  247. return
  248. }
  249. if activityInfo.IsSignup > 0 {
  250. detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
  251. if errDetail != nil {
  252. br.Msg = "获取信息失败"
  253. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  254. return
  255. }
  256. activityInfo.SignupType = detail.SignupType
  257. }
  258. activityInfo.ShowType = detail.ShowType
  259. br.Ret = 200
  260. br.Success = true
  261. br.Msg = "获取成功"
  262. br.Data = activityInfo
  263. }
  264. // @Title 活动报名
  265. // @Description 活动报名接口
  266. // @Param request body models.ActivitySingnupRep true "type json string"
  267. // @Success Ret=200 {object} models.SignupStatus
  268. // @router /signup/add [post]
  269. func (this *ActivityCoAntroller) SignupAdd() {
  270. br := new(models.BaseResponse).Init()
  271. defer func() {
  272. this.Data["json"] = br
  273. this.ServeJSON()
  274. }()
  275. user := this.User
  276. if user == nil {
  277. br.Msg = "请登录"
  278. br.ErrMsg = "请登录,用户信息为空"
  279. br.Ret = 408
  280. return
  281. }
  282. uid := user.UserId
  283. //var signupStatus string
  284. signupStatus := ""
  285. var req models.ActivitySingnupRep
  286. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  287. if err != nil {
  288. br.Msg = "参数解析异常!"
  289. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  290. return
  291. }
  292. activityId := req.ActivityId
  293. signupType := req.SignupType
  294. //if signupType != 1 && signupType != 2 {
  295. // br.Msg = "请选择正确的报名方式!"
  296. // return
  297. //}
  298. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  299. item := new(models.CygxActivitySignup)
  300. //if activityId%5 == 1 {
  301. // signupStatus = "FullStarffed"
  302. // item.FailType = 1
  303. //} else if activityId%5 == 2 {
  304. // signupStatus = "TwoPeople"
  305. // item.FailType = 2
  306. //} else if activityId%5 == 3 {
  307. // signupStatus = "BreakPromise"
  308. // item.FailType = 3
  309. //} else if activityId%5 == 4 {
  310. // signupStatus = "Overtime"
  311. //} else if activityId%5 == 5 {
  312. // signupStatus = "Success"
  313. //}
  314. signupStatus = "Success"
  315. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  316. if activityInfo == nil {
  317. br.Msg = "操作失败"
  318. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  319. return
  320. }
  321. if errInfo != nil {
  322. br.Msg = "操作失败"
  323. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  324. return
  325. }
  326. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  327. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  328. signupStatus = "Overtime"
  329. }
  330. total, errtotal := models.GetActivitySignupCount(uid, activityId)
  331. if errtotal != nil {
  332. br.Msg = "获取失败"
  333. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  334. return
  335. }
  336. if total > 0 {
  337. br.Msg = "您已报名这个活动"
  338. return
  339. }
  340. if signupStatus == "Success" {
  341. item.UserId = uid
  342. item.ActivityId = activityId
  343. item.CreateTime = time.Now()
  344. item.Mobile = user.Mobile
  345. item.Email = user.Email
  346. item.CompanyId = user.CompanyId
  347. item.CompanyName = user.CompanyName
  348. item.SignupType = signupType
  349. _, errSignup := models.AddActivitySignup(item)
  350. if errSignup != nil {
  351. br.Msg = "操作失败"
  352. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  353. return
  354. }
  355. }
  356. resp := new(models.SignupStatus)
  357. resp.SignupType = signupType
  358. resp.SignupStatus = signupStatus
  359. if signupStatus == "Success" {
  360. resp.ActivityId = activityId
  361. }
  362. if activityId%2 == 1 {
  363. resp.GoFollow = true
  364. }
  365. br.Ret = 200
  366. br.Success = true
  367. br.Msg = "操作成功"
  368. br.Data = resp
  369. }
  370. // @Title 活动取消报名
  371. // @Description 活动取消报名接口
  372. // @Param request body models.ActivitySingnupRep true "type json string"
  373. // @Success Ret=200 {object} models.SignupStatus
  374. // @router /signup/cancel [post]
  375. func (this *ActivityCoAntroller) SignupCancel() {
  376. br := new(models.BaseResponse).Init()
  377. defer func() {
  378. this.Data["json"] = br
  379. this.ServeJSON()
  380. }()
  381. user := this.User
  382. if user == nil {
  383. br.Msg = "请登录"
  384. br.ErrMsg = "请登录,用户信息为空"
  385. br.Ret = 408
  386. return
  387. }
  388. uid := user.UserId
  389. var req models.ActivitySingnupRep
  390. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  391. if err != nil {
  392. br.Msg = "参数解析异常!"
  393. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  394. return
  395. }
  396. activityId := req.ActivityId
  397. signupType := req.SignupType
  398. if signupType != 1 && signupType != 2 {
  399. br.Msg = "请选择正确的报名方式!"
  400. return
  401. }
  402. item := new(models.CygxActivitySignup)
  403. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  404. if activityInfo == nil {
  405. br.Msg = "操作失败"
  406. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  407. return
  408. }
  409. if errInfo != nil {
  410. br.Msg = "操作失败"
  411. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  412. return
  413. }
  414. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  415. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  416. if signupType == 1 {
  417. br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
  418. } else {
  419. br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
  420. }
  421. return
  422. }
  423. total, err := models.GetActivitySignupCount(uid, activityId)
  424. if err != nil {
  425. br.Msg = "获取失败"
  426. br.ErrMsg = "获取失败,Err:" + err.Error()
  427. return
  428. }
  429. if total == 0 {
  430. br.Msg = "您暂未报名这个活动"
  431. return
  432. }
  433. item.UserId = uid
  434. item.ActivityId = activityId
  435. item.CreateTime = time.Now()
  436. item.Mobile = user.Mobile
  437. item.Email = user.Email
  438. item.CompanyId = user.CompanyId
  439. item.CompanyName = user.CompanyName
  440. resp := new(models.SignupStatus)
  441. resp.ActivityId = activityId
  442. _, errSignup := models.CancelActivitySignup(item)
  443. if errSignup != nil {
  444. br.Msg = "操作失败"
  445. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  446. return
  447. }
  448. br.Ret = 200
  449. br.Success = true
  450. br.Msg = "操作成功"
  451. br.Data = resp
  452. }
  453. // @Title 用户搜索详情
  454. // @Description 获取用户搜索详情接口
  455. // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
  456. // @Success Ret=200 {object} models.ActivityUserSearchContentList
  457. // @router /getUserSearchContent [get]
  458. func (this *ActivityCoAntroller) GetUserSearchContent() {
  459. br := new(models.BaseResponse).Init()
  460. defer func() {
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. user := this.User
  465. if user == nil {
  466. br.Msg = "请登录"
  467. br.ErrMsg = "请登录,用户信息为空"
  468. br.Ret = 408
  469. return
  470. }
  471. uid := user.UserId
  472. detailSeearch := new(models.CygxActivityUserSearchContent)
  473. detailSeearch.IsShowJurisdiction = 0
  474. detailSeearch.ChartPermissionids = ""
  475. detailSeearch.ActiveState = ""
  476. detail, _ := models.GetUserSearchContentByUid(uid)
  477. if detail == nil {
  478. detail = detailSeearch
  479. }
  480. //if err != nil {
  481. // br.Msg = "获取信息失败"
  482. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  483. // return
  484. //}
  485. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  486. //chartPermissionidsSlice := strings.Split(detail.ChartPermissionids, ",")
  487. //activityTypeidsSlice := strings.Split(detail.ActivityTypeids, ",")
  488. //activeStateSlice := strings.Split(detail.ActiveState, ",") //"活动进行状态 未开始:1、进行中2、已结束3"`
  489. listActivityType, errActivityType := models.GetActivityTypeList()
  490. if errActivityType != nil {
  491. br.Msg = "获取失败"
  492. br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
  493. return
  494. }
  495. //for _, v := range activityTypeidsSlice {
  496. // for k2, v2 := range listActivityType {
  497. // if strconv.Itoa(v2.ActivityTypeId) == v {
  498. // listActivityType[k2].IsChoose = true
  499. // }
  500. // }
  501. //}
  502. var listChartPermissionid []*models.ActivityChartPermission
  503. var errChart error
  504. if isShowJurisdiction == 1 {
  505. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  506. listChartPermissionid = listChartPermissionidAll
  507. errChart = errChartAll
  508. } else if isShowJurisdiction == 2 {
  509. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  510. listChartPermissionid = listChartPermissionidAll
  511. errChart = errChartAll
  512. } else {
  513. if detail.IsShowJurisdiction == 1 {
  514. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  515. listChartPermissionid = listChartPermissionidAll
  516. errChart = errChartAll
  517. } else {
  518. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  519. listChartPermissionid = listChartPermissionidAll
  520. errChart = errChartAll
  521. }
  522. }
  523. if errChart != nil {
  524. br.Msg = "获取信息失败"
  525. br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
  526. return
  527. }
  528. //for _, v := range chartPermissionidsSlice {
  529. // for k2, v2 := range listChartPermissionid {
  530. // if strconv.Itoa(v2.ChartPermissionId) == v {
  531. // listChartPermissionid[k2].IsChoose = true
  532. // }
  533. // }
  534. //}
  535. resp := new(models.ActivityUserSearchContentList)
  536. if detail.IsShowJurisdiction == 1 {
  537. resp.IsShowJurisdiction = true
  538. }
  539. fmt.Println(isShowJurisdiction)
  540. if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
  541. resp.IsShowJurisdiction = true
  542. for k, _ := range listChartPermissionid {
  543. listChartPermissionid[k].IsChoose = true
  544. }
  545. }
  546. if isShowJurisdiction == 2 {
  547. resp.IsShowJurisdiction = false
  548. }
  549. activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
  550. //for _, v := range activeStateSlice {
  551. // for k2, v2 := range activeStateList {
  552. // if strconv.Itoa(v2.Id) == v {
  553. // //activeStateList[k2].IsChoose = true
  554. // }
  555. // }
  556. //}
  557. if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
  558. activeStateList[0].IsChoose = true
  559. }
  560. resp.ListActivityType = listActivityType
  561. resp.ListChartPermission = listChartPermissionid
  562. resp.ListActivityStaus = activeStateList
  563. br.Ret = 200
  564. br.Success = true
  565. br.Msg = "获取成功"
  566. br.Data = resp
  567. }
  568. // @Title 添加会议提醒
  569. // @Description 添加会议提醒接口
  570. // @Param request body models.ActivityIdRep true "type json string"
  571. // @Success Ret=200 {object} models.SignupStatus
  572. // @router /meetingReminder/add [post]
  573. func (this *ActivityCoAntroller) MeetingReminderAdd() {
  574. br := new(models.BaseResponse).Init()
  575. defer func() {
  576. this.Data["json"] = br
  577. this.ServeJSON()
  578. }()
  579. user := this.User
  580. if user == nil {
  581. br.Msg = "请登录"
  582. br.ErrMsg = "请登录,用户信息为空"
  583. br.Ret = 408
  584. return
  585. }
  586. uid := user.UserId
  587. //var signupStatus string
  588. signupStatus := "Success"
  589. var req models.ActivityIdRep
  590. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  591. if err != nil {
  592. br.Msg = "参数解析异常!"
  593. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  594. return
  595. }
  596. activityId := req.ActivityId
  597. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  598. item := new(models.CygxActivityMeetingReminder)
  599. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  600. if activityInfo == nil {
  601. br.Msg = "操作失败"
  602. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  603. return
  604. }
  605. if errInfo != nil {
  606. br.Msg = "操作失败"
  607. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  608. return
  609. }
  610. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  611. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  612. br.Msg = "活动开始前15分钟无法设置会议提醒"
  613. return
  614. }
  615. //if signupStatus == "Success" {
  616. //total, err := models.GetActivitySignupCount(uid, activityId)
  617. //if err != nil {
  618. // br.Msg = "获取失败"
  619. // br.ErrMsg = "获取失败,Err:" + err.Error()
  620. // return
  621. //}
  622. //if total == 0 {
  623. // br.Msg = "您暂未预约外呼这个活动"
  624. // return
  625. //}
  626. totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
  627. if errMeeting != nil {
  628. br.Msg = "获取失败"
  629. br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
  630. return
  631. }
  632. if totalMeeting > 0 {
  633. br.Msg = "您已预约,请勿重复预约"
  634. return
  635. }
  636. item.UserId = uid
  637. item.ActivityId = activityId
  638. item.CreateTime = time.Now()
  639. item.Mobile = user.Mobile
  640. item.Email = user.Email
  641. item.CompanyId = user.CompanyId
  642. item.CompanyName = user.CompanyName
  643. _, errSignup := models.AddActivityMeetingReminder(item)
  644. if errSignup != nil {
  645. br.Msg = "操作失败"
  646. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  647. return
  648. }
  649. //}
  650. resp := new(models.SignupStatus)
  651. resp.SignupStatus = signupStatus
  652. resp.ActivityId = activityId
  653. if activityId%2 == 1 {
  654. resp.GoFollow = true
  655. }
  656. br.Ret = 200
  657. br.Success = true
  658. br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
  659. br.Data = resp
  660. }
  661. // @Title 取消会议提醒
  662. // @Description 取消会议提醒接口
  663. // @Param request body models.ActivityIdRep true "type json string"
  664. // @Success Ret=200 {object} models.SignupStatus
  665. // @router /meetingReminder/cancel [post]
  666. func (this *ActivityCoAntroller) MeetingReminderCancel() {
  667. br := new(models.BaseResponse).Init()
  668. defer func() {
  669. this.Data["json"] = br
  670. this.ServeJSON()
  671. }()
  672. user := this.User
  673. if user == nil {
  674. br.Msg = "请登录"
  675. br.ErrMsg = "请登录,用户信息为空"
  676. br.Ret = 408
  677. return
  678. }
  679. uid := user.UserId
  680. var req models.ActivityIdRep
  681. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  682. if err != nil {
  683. br.Msg = "参数解析异常!"
  684. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  685. return
  686. }
  687. activityId := req.ActivityId
  688. signupStatus := "Success"
  689. item := new(models.CygxActivityMeetingReminder)
  690. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  691. if activityInfo == nil {
  692. br.Msg = "操作失败"
  693. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  694. return
  695. }
  696. if errInfo != nil {
  697. br.Msg = "操作失败"
  698. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  699. return
  700. }
  701. //if signupStatus == "Success" {
  702. total, err := models.GetActivityMeetingReminderCount(uid, activityId)
  703. if err != nil {
  704. br.Msg = "获取失败"
  705. br.ErrMsg = "获取失败,Err:" + err.Error()
  706. return
  707. }
  708. if total == 0 {
  709. br.Msg = "您暂未添加该活动会议提醒"
  710. return
  711. }
  712. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  713. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  714. br.Msg = "活动开始前15分钟无法取消会议提醒"
  715. return
  716. }
  717. item.UserId = uid
  718. item.ActivityId = activityId
  719. item.CreateTime = time.Now()
  720. item.Mobile = user.Mobile
  721. item.Email = user.Email
  722. item.CompanyId = user.CompanyId
  723. item.CompanyName = user.CompanyName
  724. _, errSignup := models.CancelActivityMeetingReminder(item)
  725. if errSignup != nil {
  726. br.Msg = "操作失败"
  727. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  728. return
  729. }
  730. //}
  731. resp := new(models.SignupStatus)
  732. resp.SignupStatus = signupStatus
  733. resp.ActivityId = activityId
  734. br.Ret = 200
  735. br.Success = true
  736. br.Msg = "操作成功"
  737. br.Data = resp
  738. }