activity.go 32 KB

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