activity.go 28 KB

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