activity.go 22 KB

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