activity.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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. condition += ` AND art.publish_status = 1 AND art.active_state IN(1,2) `
  189. total, err := models.GetScheduleCount(uid)
  190. if err != nil {
  191. br.Msg = "获取失败"
  192. br.ErrMsg = "获取失败,Err:" + err.Error()
  193. return
  194. }
  195. list, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  196. if errList != nil {
  197. br.Msg = "获取失败"
  198. br.ErrMsg = "获取失败,Err:" + errList.Error()
  199. return
  200. }
  201. for k, v := range list {
  202. if strings.Contains(v.ActivityName, "【") {
  203. list[k].IsBrackets = 1
  204. }
  205. }
  206. page := paging.GetPaging(currentIndex, pageSize, total)
  207. resp := new(models.GetCygxActivityListRep)
  208. resp.List = list
  209. resp.Paging = page
  210. br.Ret = 200
  211. br.Success = true
  212. br.Msg = "获取成功"
  213. br.Data = resp
  214. }
  215. // @Title 活动详情
  216. // @Description 获取活动详情接口
  217. // @Param ActivityId query int true "活动ID"
  218. // @Success Ret=200 {object} models.CygxActivityResp
  219. // @router /detail [get]
  220. func (this *ActivityCoAntroller) Detail() {
  221. br := new(models.BaseResponse).Init()
  222. defer func() {
  223. this.Data["json"] = br
  224. this.ServeJSON()
  225. }()
  226. user := this.User
  227. if user == nil {
  228. br.Msg = "请登录"
  229. br.ErrMsg = "请登录,用户信息为空"
  230. br.Ret = 408
  231. return
  232. }
  233. uid := user.UserId
  234. activityId, _ := this.GetInt("ActivityId")
  235. if activityId < 1 {
  236. br.Msg = "请输入活动ID"
  237. return
  238. }
  239. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  240. if activityInfo == nil {
  241. br.Msg = "活动不存在"
  242. br.ErrMsg = "活动ID错误,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
  243. return
  244. }
  245. detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  246. if errDetail != nil {
  247. br.Msg = "获取信息失败"
  248. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  249. return
  250. }
  251. if activityInfo.IsSignup > 0 {
  252. detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
  253. if errDetail != nil {
  254. br.Msg = "获取信息失败"
  255. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  256. return
  257. }
  258. activityInfo.SignupType = detail.SignupType
  259. }
  260. activityInfo.ShowType = detail.ShowType
  261. resp := new(models.CygxActivityResp)
  262. hasPermission := 0
  263. //判断是否已经申请过
  264. applyCount, err := models.GetApplyRecordCount(uid)
  265. if err != nil && err.Error() != utils.ErrNoRow() {
  266. br.Msg = "获取信息失败"
  267. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  268. return
  269. }
  270. if user.CompanyId > 1 {
  271. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  272. if err != nil {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  275. return
  276. }
  277. companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
  278. if err != nil {
  279. br.Msg = "获取信息失败"
  280. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  281. return
  282. }
  283. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  284. //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  285. if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
  286. resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  287. resp.SellerMobile = companyItem.Mobile
  288. resp.OperationMode = "Call"
  289. hasPermission = 2
  290. } else {
  291. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  292. hasPermission = 1
  293. resp.HaqveJurisdiction = true
  294. } else {
  295. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  296. resp.SellerMobile = companyItem.Mobile
  297. resp.OperationMode = "Call"
  298. hasPermission = 2
  299. }
  300. }
  301. } else { //潜在客户
  302. if applyCount > 0 {
  303. hasPermission = 4
  304. } else {
  305. hasPermission = 3
  306. }
  307. resp.OperationMode = "Apply"
  308. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  309. }
  310. if hasPermission == 1 {
  311. resp.Detail = activityInfo
  312. }
  313. resp.HasPermission = hasPermission
  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.ActivitySingnupRep true "type json string"
  322. // @Success Ret=200 {object} models.SignupStatus
  323. // @router /signup/add [post]
  324. func (this *ActivityCoAntroller) SignupAdd() {
  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 signupStatus string
  339. signupStatus := ""
  340. var req models.ActivitySingnupRep
  341. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  342. if err != nil {
  343. br.Msg = "参数解析异常!"
  344. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  345. return
  346. }
  347. activityId := req.ActivityId
  348. signupType := req.SignupType
  349. //if signupType != 1 && signupType != 2 {
  350. // br.Msg = "请选择正确的报名方式!"
  351. // return
  352. //}
  353. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  354. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  355. item := new(models.CygxActivitySignup)
  356. resp := new(models.SignupStatus)
  357. hasPermission := 0
  358. //判断是否已经申请过
  359. applyCount, err := models.GetApplyRecordCount(uid)
  360. if err != nil && err.Error() != utils.ErrNoRow() {
  361. br.Msg = "获取信息失败"
  362. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  363. return
  364. }
  365. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  366. if activityInfo == nil {
  367. br.Msg = "操作失败"
  368. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  369. return
  370. }
  371. if errInfo != nil {
  372. br.Msg = "操作失败"
  373. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  374. return
  375. }
  376. if user.CompanyId > 1 {
  377. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  378. if err != nil {
  379. br.Msg = "获取信息失败"
  380. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  381. return
  382. }
  383. companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
  384. if err != nil {
  385. br.Msg = "获取信息失败"
  386. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  387. return
  388. }
  389. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  390. //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  391. if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
  392. resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  393. resp.SellerMobile = companyItem.Mobile
  394. resp.OperationMode = "Call"
  395. hasPermission = 2
  396. } else {
  397. fmt.Println(activityInfo.ChartPermissionName)
  398. fmt.Println(permissionStr)
  399. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  400. hasPermission = 1
  401. signupStatus = "Success"
  402. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  403. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  404. signupStatus = "Overtime"
  405. }
  406. total, errtotal := models.GetActivitySignupCount(uid, activityId)
  407. if errtotal != nil {
  408. br.Msg = "获取失败"
  409. br.ErrMsg = "获取失败,Err:" + errtotal.Error()
  410. return
  411. }
  412. if total > 0 {
  413. br.Msg = "您已报名这个活动"
  414. return
  415. }
  416. if signupStatus == "Success" {
  417. item.UserId = uid
  418. item.ActivityId = activityId
  419. item.CreateTime = time.Now()
  420. item.Mobile = user.Mobile
  421. item.Email = user.Email
  422. item.CompanyId = user.CompanyId
  423. item.CompanyName = user.CompanyName
  424. item.SignupType = signupType
  425. _, errSignup := models.AddActivitySignup(item)
  426. if errSignup != nil {
  427. br.Msg = "操作失败"
  428. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  429. return
  430. }
  431. }
  432. resp.HaqveJurisdiction = true
  433. } else {
  434. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  435. resp.SellerMobile = companyItem.Mobile
  436. resp.OperationMode = "Call"
  437. hasPermission = 2
  438. }
  439. }
  440. } else { //潜在客户
  441. if applyCount > 0 {
  442. hasPermission = 4
  443. } else {
  444. hasPermission = 3
  445. }
  446. resp.OperationMode = "Apply"
  447. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  448. }
  449. resp.SignupType = signupType
  450. resp.SignupStatus = signupStatus
  451. resp.HasPermission = hasPermission
  452. if signupStatus == "Success" {
  453. resp.ActivityId = activityId
  454. }
  455. if activityId%2 == 1 {
  456. resp.GoFollow = true
  457. }
  458. br.Ret = 200
  459. br.Success = true
  460. br.Msg = "操作成功"
  461. br.Data = resp
  462. }
  463. // @Title 活动取消报名
  464. // @Description 活动取消报名接口
  465. // @Param request body models.ActivitySingnupRep true "type json string"
  466. // @Success Ret=200 {object} models.SignupStatus
  467. // @router /signup/cancel [post]
  468. func (this *ActivityCoAntroller) SignupCancel() {
  469. br := new(models.BaseResponse).Init()
  470. defer func() {
  471. this.Data["json"] = br
  472. this.ServeJSON()
  473. }()
  474. user := this.User
  475. if user == nil {
  476. br.Msg = "请登录"
  477. br.ErrMsg = "请登录,用户信息为空"
  478. br.Ret = 408
  479. return
  480. }
  481. uid := user.UserId
  482. var req models.ActivitySingnupRep
  483. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  484. if err != nil {
  485. br.Msg = "参数解析异常!"
  486. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  487. return
  488. }
  489. activityId := req.ActivityId
  490. signupType := req.SignupType
  491. //if signupType != 1 && signupType != 2 {
  492. // br.Msg = "请选择正确的报名方式!"
  493. // return
  494. //}
  495. item := new(models.CygxActivitySignup)
  496. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  497. if activityInfo == nil {
  498. br.Msg = "操作失败"
  499. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  500. return
  501. }
  502. if errInfo != nil {
  503. br.Msg = "操作失败"
  504. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  505. return
  506. }
  507. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  508. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  509. if signupType == 1 {
  510. br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
  511. } else {
  512. br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
  513. }
  514. return
  515. }
  516. total, err := models.GetActivitySignupCount(uid, activityId)
  517. if err != nil {
  518. br.Msg = "获取失败"
  519. br.ErrMsg = "获取失败,Err:" + err.Error()
  520. return
  521. }
  522. if total == 0 {
  523. br.Msg = "您暂未报名这个活动"
  524. return
  525. }
  526. item.UserId = uid
  527. item.ActivityId = activityId
  528. item.CreateTime = time.Now()
  529. item.Mobile = user.Mobile
  530. item.Email = user.Email
  531. item.CompanyId = user.CompanyId
  532. item.CompanyName = user.CompanyName
  533. resp := new(models.SignupStatus)
  534. resp.ActivityId = activityId
  535. _, errSignup := models.CancelActivitySignup(item)
  536. if errSignup != nil {
  537. br.Msg = "操作失败"
  538. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  539. return
  540. }
  541. br.Ret = 200
  542. br.Success = true
  543. br.Msg = "操作成功"
  544. br.Data = resp
  545. }
  546. // @Title 用户搜索详情
  547. // @Description 获取用户搜索详情接口
  548. // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
  549. // @Success Ret=200 {object} models.ActivityUserSearchContentList
  550. // @router /getUserSearchContent [get]
  551. func (this *ActivityCoAntroller) GetUserSearchContent() {
  552. br := new(models.BaseResponse).Init()
  553. defer func() {
  554. this.Data["json"] = br
  555. this.ServeJSON()
  556. }()
  557. user := this.User
  558. if user == nil {
  559. br.Msg = "请登录"
  560. br.ErrMsg = "请登录,用户信息为空"
  561. br.Ret = 408
  562. return
  563. }
  564. uid := user.UserId
  565. detailSeearch := new(models.CygxActivityUserSearchContent)
  566. detailSeearch.IsShowJurisdiction = 0
  567. detailSeearch.ChartPermissionids = ""
  568. detailSeearch.ActiveState = ""
  569. detail, _ := models.GetUserSearchContentByUid(uid)
  570. if detail == nil {
  571. detail = detailSeearch
  572. }
  573. //if err != nil {
  574. // br.Msg = "获取信息失败"
  575. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  576. // return
  577. //}
  578. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  579. //chartPermissionidsSlice := strings.Split(detail.ChartPermissionids, ",")
  580. //activityTypeidsSlice := strings.Split(detail.ActivityTypeids, ",")
  581. //activeStateSlice := strings.Split(detail.ActiveState, ",") //"活动进行状态 未开始:1、进行中2、已结束3"`
  582. listActivityType, errActivityType := models.GetActivityTypeList()
  583. if errActivityType != nil {
  584. br.Msg = "获取失败"
  585. br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
  586. return
  587. }
  588. //for _, v := range activityTypeidsSlice {
  589. // for k2, v2 := range listActivityType {
  590. // if strconv.Itoa(v2.ActivityTypeId) == v {
  591. // listActivityType[k2].IsChoose = true
  592. // }
  593. // }
  594. //}
  595. var listChartPermissionid []*models.ActivityChartPermission
  596. var errChart error
  597. if isShowJurisdiction == 1 {
  598. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  599. listChartPermissionid = listChartPermissionidAll
  600. errChart = errChartAll
  601. } else if isShowJurisdiction == 2 {
  602. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  603. listChartPermissionid = listChartPermissionidAll
  604. errChart = errChartAll
  605. } else {
  606. if detail.IsShowJurisdiction == 1 {
  607. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  608. listChartPermissionid = listChartPermissionidAll
  609. errChart = errChartAll
  610. } else {
  611. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  612. listChartPermissionid = listChartPermissionidAll
  613. errChart = errChartAll
  614. }
  615. }
  616. if errChart != nil {
  617. br.Msg = "获取信息失败"
  618. br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
  619. return
  620. }
  621. //for _, v := range chartPermissionidsSlice {
  622. // for k2, v2 := range listChartPermissionid {
  623. // if strconv.Itoa(v2.ChartPermissionId) == v {
  624. // listChartPermissionid[k2].IsChoose = true
  625. // }
  626. // }
  627. //}
  628. resp := new(models.ActivityUserSearchContentList)
  629. if detail.IsShowJurisdiction == 1 {
  630. resp.IsShowJurisdiction = true
  631. }
  632. fmt.Println(isShowJurisdiction)
  633. if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
  634. resp.IsShowJurisdiction = true
  635. for k, _ := range listChartPermissionid {
  636. listChartPermissionid[k].IsChoose = true
  637. }
  638. }
  639. if isShowJurisdiction == 2 {
  640. resp.IsShowJurisdiction = false
  641. }
  642. activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
  643. //for _, v := range activeStateSlice {
  644. // for k2, v2 := range activeStateList {
  645. // if strconv.Itoa(v2.Id) == v {
  646. // //activeStateList[k2].IsChoose = true
  647. // }
  648. // }
  649. //}
  650. if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
  651. activeStateList[0].IsChoose = true
  652. }
  653. resp.ListActivityType = listActivityType
  654. resp.ListChartPermission = listChartPermissionid
  655. resp.ListActivityStaus = activeStateList
  656. br.Ret = 200
  657. br.Success = true
  658. br.Msg = "获取成功"
  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/add [post]
  666. func (this *ActivityCoAntroller) MeetingReminderAdd() {
  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 signupStatus string
  681. signupStatus := "Success"
  682. var req models.ActivityIdRep
  683. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  684. if err != nil {
  685. br.Msg = "参数解析异常!"
  686. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  687. return
  688. }
  689. activityId := req.ActivityId
  690. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  691. item := new(models.CygxActivityMeetingReminder)
  692. resp := new(models.SignupStatus)
  693. hasPermission := 0
  694. //判断是否已经申请过
  695. applyCount, err := models.GetApplyRecordCount(uid)
  696. if err != nil && err.Error() != utils.ErrNoRow() {
  697. br.Msg = "获取信息失败"
  698. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  699. return
  700. }
  701. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  702. if activityInfo == nil {
  703. br.Msg = "操作失败"
  704. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  705. return
  706. }
  707. if errInfo != nil {
  708. br.Msg = "操作失败"
  709. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  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. if user.CompanyId > 1 {
  718. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  719. if err != nil {
  720. br.Msg = "获取信息失败"
  721. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  722. return
  723. }
  724. companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
  725. if err != nil {
  726. br.Msg = "获取信息失败"
  727. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  728. return
  729. }
  730. if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
  731. resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  732. resp.SellerMobile = companyItem.Mobile
  733. resp.OperationMode = "Call"
  734. hasPermission = 2
  735. } else {
  736. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  737. hasPermission = 1
  738. signupStatus = "Success"
  739. totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
  740. if errMeeting != nil {
  741. br.Msg = "获取失败"
  742. br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
  743. return
  744. }
  745. if totalMeeting > 0 {
  746. br.Msg = "您已预约,请勿重复预约"
  747. return
  748. }
  749. item.UserId = uid
  750. item.ActivityId = activityId
  751. item.CreateTime = time.Now()
  752. item.Mobile = user.Mobile
  753. item.Email = user.Email
  754. item.CompanyId = user.CompanyId
  755. item.CompanyName = user.CompanyName
  756. _, errSignup := models.AddActivityMeetingReminder(item)
  757. if errSignup != nil {
  758. br.Msg = "操作失败"
  759. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  760. return
  761. }
  762. resp.HaqveJurisdiction = true
  763. } else {
  764. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  765. resp.SellerMobile = companyItem.Mobile
  766. resp.OperationMode = "Call"
  767. hasPermission = 2
  768. }
  769. }
  770. } else { //潜在客户
  771. if applyCount > 0 {
  772. hasPermission = 4
  773. } else {
  774. hasPermission = 3
  775. }
  776. resp.OperationMode = "Apply"
  777. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  778. }
  779. resp.HasPermission = hasPermission
  780. resp.SignupStatus = signupStatus
  781. resp.ActivityId = activityId
  782. if activityId%2 == 1 {
  783. resp.GoFollow = true
  784. }
  785. br.Ret = 200
  786. br.Success = true
  787. if hasPermission == 1 {
  788. br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
  789. }
  790. br.Data = resp
  791. }
  792. // @Title 取消会议提醒
  793. // @Description 取消会议提醒接口
  794. // @Param request body models.ActivityIdRep true "type json string"
  795. // @Success Ret=200 {object} models.SignupStatus
  796. // @router /meetingReminder/cancel [post]
  797. func (this *ActivityCoAntroller) MeetingReminderCancel() {
  798. br := new(models.BaseResponse).Init()
  799. defer func() {
  800. this.Data["json"] = br
  801. this.ServeJSON()
  802. }()
  803. user := this.User
  804. if user == nil {
  805. br.Msg = "请登录"
  806. br.ErrMsg = "请登录,用户信息为空"
  807. br.Ret = 408
  808. return
  809. }
  810. uid := user.UserId
  811. var req models.ActivityIdRep
  812. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  813. if err != nil {
  814. br.Msg = "参数解析异常!"
  815. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  816. return
  817. }
  818. activityId := req.ActivityId
  819. signupStatus := "Success"
  820. item := new(models.CygxActivityMeetingReminder)
  821. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  822. if activityInfo == nil {
  823. br.Msg = "操作失败"
  824. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  825. return
  826. }
  827. if errInfo != nil {
  828. br.Msg = "操作失败"
  829. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  830. return
  831. }
  832. //if signupStatus == "Success" {
  833. total, err := models.GetActivityMeetingReminderCount(uid, activityId)
  834. if err != nil {
  835. br.Msg = "获取失败"
  836. br.ErrMsg = "获取失败,Err:" + err.Error()
  837. return
  838. }
  839. if total == 0 {
  840. br.Msg = "您暂未添加该活动会议提醒"
  841. return
  842. }
  843. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  844. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  845. br.Msg = "活动开始前15分钟无法取消会议提醒"
  846. return
  847. }
  848. item.UserId = uid
  849. item.ActivityId = activityId
  850. item.CreateTime = time.Now()
  851. item.Mobile = user.Mobile
  852. item.Email = user.Email
  853. item.CompanyId = user.CompanyId
  854. item.CompanyName = user.CompanyName
  855. _, errSignup := models.CancelActivityMeetingReminder(item)
  856. if errSignup != nil {
  857. br.Msg = "操作失败"
  858. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  859. return
  860. }
  861. //}
  862. resp := new(models.SignupStatus)
  863. resp.SignupStatus = signupStatus
  864. resp.ActivityId = activityId
  865. br.Ret = 200
  866. br.Success = true
  867. br.Msg = "会议提醒已取消"
  868. br.Data = resp
  869. }