activity.go 28 KB

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