activity.go 32 KB

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