activity_special.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //专项调研活动
  13. type ActivitySpecialCoAntroller struct {
  14. BaseAuthController
  15. }
  16. // @Title 专项产业调研列表
  17. // @Description 获取专项产业调研列表接口
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Success 200 {object} models.GetCygxActivitySpecialDetailListResp
  21. // @router /list [get]
  22. func (this *ActivitySpecialCoAntroller) SpecialList() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. user := this.User
  29. if user == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. return
  33. }
  34. pageSize, _ := this.GetInt("PageSize")
  35. currentIndex, _ := this.GetInt("CurrentIndex")
  36. if pageSize <= 0 {
  37. pageSize = utils.PageSize20
  38. }
  39. if currentIndex <= 0 {
  40. currentIndex = 1
  41. }
  42. list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "")
  43. if errList != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取失败,Err:" + errList.Error()
  46. return
  47. }
  48. page := paging.GetPaging(currentIndex, pageSize, total)
  49. resp := new(models.GetCygxActivitySpecialDetailListResp)
  50. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  51. if err != nil {
  52. br.Msg = "获取数据失败!"
  53. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  54. return
  55. }
  56. if count == 1 && user.UserId > 0 {
  57. resp.IsFollow = true
  58. }
  59. if user.Mobile != "" {
  60. resp.IsBindingMobile = true
  61. }
  62. resp.List = list
  63. resp.Paging = page
  64. br.Ret = 200
  65. br.Success = true
  66. br.Msg = "获取成功"
  67. br.Data = resp
  68. }
  69. // @Title 专项产业调研详情
  70. // @Description 获取专项产业调研详情接口
  71. // @Param ActivityId query int true "活动ID"
  72. // @Success Ret=200 {object} models.CygxActivitySpecialResp
  73. // @router /detail [get]
  74. func (this *ActivitySpecialCoAntroller) SpecialDetail() {
  75. br := new(models.BaseResponse).Init()
  76. defer func() {
  77. this.Data["json"] = br
  78. this.ServeJSON()
  79. }()
  80. user := this.User
  81. if user == nil {
  82. br.Msg = "请登录"
  83. br.ErrMsg = "请登录,用户信息为空"
  84. br.Ret = 408
  85. return
  86. }
  87. uid := user.UserId
  88. activityId, _ := this.GetInt("ActivityId")
  89. if activityId < 1 {
  90. br.Msg = "请输入活动ID"
  91. return
  92. }
  93. resp := new(models.CygxActivitySpecialResp)
  94. activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
  95. if err != nil && err.Error() != utils.ErrNoRow() {
  96. br.Msg = "获取信息失败"
  97. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  98. return
  99. }
  100. if activityInfo == nil {
  101. br.Msg = "活动不存在"
  102. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  103. return
  104. }
  105. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  106. if err != nil {
  107. br.Msg = "获取信息失败"
  108. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  109. return
  110. }
  111. //判断有没有对应的权限,如果没有则给出对应的状态码
  112. if havePower {
  113. resp.HasPermission = 1
  114. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  115. if err != nil {
  116. br.Msg = "获取数据失败!"
  117. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  118. return
  119. }
  120. if count == 1 {
  121. resp.IsFollow = true
  122. }
  123. activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
  124. if err != nil {
  125. br.Msg = "获取数据失败!"
  126. br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
  127. return
  128. }
  129. var condition string
  130. var pars []interface{}
  131. condition += ` AND activity_id = ? `
  132. pars = append(pars, activityInfo.ActivityId)
  133. tripTota, err := models.GetActivitySpecialTripCountByActivityId(condition, pars)
  134. if err != nil {
  135. br.Msg = "获取数据失败!"
  136. br.ErrMsg = "GetActivitySpecialTripCountByActivityId,Err:" + err.Error()
  137. return
  138. }
  139. activityInfo.TripNum = tripTota
  140. activityInfo.ActivityTypeName = "专项调研"
  141. resp.Detail = activityInfo
  142. resp.Detail = activityInfo
  143. } else {
  144. hasPermission, sellerName, sellerMobile, err := services.GetUserHasPermission(user)
  145. if err != nil {
  146. br.Msg = "获取信息失败"
  147. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  148. return
  149. }
  150. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  151. resp.HasPermission = hasPermission
  152. resp.SellerName = sellerName
  153. resp.SellerMobile = sellerMobile
  154. }
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. br.Data = resp
  159. }
  160. // @Title报名
  161. // @Description 报名
  162. // @Param request body models.ActivityIdRep true "type json string"
  163. // @Success Ret=200 {object} models.SignupSpecialStatus
  164. // @router /add [post]
  165. func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. this.Data["json"] = br
  169. this.ServeJSON()
  170. }()
  171. user := this.User
  172. if user == nil {
  173. br.Msg = "请登录"
  174. br.ErrMsg = "请登录,用户信息为空"
  175. br.Ret = 408
  176. return
  177. }
  178. uid := user.UserId
  179. var req models.ActivityIdRep
  180. resp := new(models.SignupSpecialStatus)
  181. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  182. if err != nil {
  183. br.Msg = "参数解析异常!"
  184. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  185. return
  186. }
  187. activityId := req.ActivityId
  188. hasPermission := 0
  189. //判断是否已经申请过
  190. applyCount, err := models.GetApplyRecordCount(uid)
  191. if err != nil && err.Error() != utils.ErrNoRow() {
  192. br.Msg = "获取信息失败"
  193. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  194. return
  195. }
  196. //获取FICC销售信息
  197. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  198. if err != nil && err.Error() != utils.ErrNoRow() {
  199. br.Msg = "申请失败"
  200. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  201. return
  202. }
  203. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  204. if activityInfo == nil {
  205. br.Msg = "操作失败"
  206. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  207. return
  208. }
  209. if errInfo != nil {
  210. br.Msg = "操作失败"
  211. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  212. return
  213. }
  214. //HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  215. //var companyDetailStatus string
  216. if user.CompanyId > 1 {
  217. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  218. if err != nil {
  219. br.Msg = "获取信息失败"
  220. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  221. return
  222. }
  223. if companyPermission == "" {
  224. if applyCount > 0 {
  225. hasPermission = 4
  226. } else {
  227. if sellerItem != nil {
  228. hasPermission = 5
  229. } else {
  230. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  231. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  232. if err != nil && err.Error() != utils.ErrNoRow() {
  233. br.Msg = "获取信息失败"
  234. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  235. return
  236. }
  237. if sellerItemQy != nil {
  238. hasPermission = 2
  239. resp.SellerMobile = sellerItemQy.Mobile
  240. resp.SellerName = sellerItemQy.RealName
  241. } else {
  242. hasPermission = 3
  243. }
  244. }
  245. }
  246. resp.HasPermission = hasPermission
  247. resp.ActivityId = activityId
  248. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  249. br.Ret = 200
  250. br.Success = true
  251. br.Msg = "获取成功"
  252. br.Data = resp
  253. return
  254. }
  255. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  256. if err != nil {
  257. br.Msg = "获取信息失败!"
  258. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  259. return
  260. }
  261. if companyDetail == nil {
  262. br.Msg = "获取信息失败!"
  263. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  264. return
  265. }
  266. }
  267. var userType int
  268. var permissionStr string
  269. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  270. if err != nil {
  271. br.Msg = "获取信息失败!"
  272. br.ErrMsg = "获取失败,Err:" + err.Error()
  273. return
  274. }
  275. if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, "研选") {
  276. br.Msg = "您暂无查看该活动权限"
  277. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  278. return
  279. }
  280. if user.CompanyId > 1 {
  281. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  282. //冻结客户
  283. if err != nil {
  284. if err.Error() == utils.ErrNoRow() {
  285. if applyCount > 0 {
  286. hasPermission = 4
  287. } else {
  288. if sellerItem != nil {
  289. hasPermission = 5
  290. } else {
  291. hasPermission = 3
  292. }
  293. }
  294. resp.ActivityId = activityId
  295. resp.HasPermission = hasPermission
  296. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  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. //判断是否有权限
  309. var havePower bool
  310. if strings.Contains(permissionStr, activityInfo.ActivityTypeName) {
  311. havePower = true
  312. }
  313. if havePower {
  314. hasPermission = 1
  315. } else {
  316. if companyItem.ProductId == 2 {
  317. hasPermission = 2
  318. resp.SellerMobile = companyItem.Mobile
  319. resp.SellerName = companyItem.SellerName
  320. if permissionStr == "专家" {
  321. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  322. } else {
  323. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  324. }
  325. } else {
  326. hasPermission = 5
  327. }
  328. }
  329. } else { //潜在客户
  330. if applyCount > 0 {
  331. hasPermission = 4
  332. } else {
  333. if sellerItem != nil {
  334. hasPermission = 5
  335. } else {
  336. hasPermission = 3
  337. }
  338. }
  339. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  340. }
  341. resp.HasPermission = hasPermission
  342. resp.ActivityId = activityId
  343. if hasPermission == 1 {
  344. signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
  345. if err != nil {
  346. br.Msg = "获取信息失败"
  347. br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
  348. return
  349. }
  350. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  351. if err != nil {
  352. br.Msg = "获取信息失败"
  353. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  354. return
  355. }
  356. resp.PopupMsg = popupMsg
  357. resp.PopupMsg2 = popupMsg2
  358. resp.SignupStatus = signupStatus
  359. if signupStatus == 1 {
  360. //判断是删除还是添加
  361. if total == 0 {
  362. //获取销售信息
  363. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  364. if err != nil {
  365. br.Msg = "操作失败"
  366. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  367. return
  368. }
  369. item := new(models.CygxActivitySpecialTrip)
  370. item.UserId = uid
  371. item.RealName = user.RealName
  372. item.ActivityId = activityId
  373. item.CreateTime = time.Now()
  374. item.Mobile = user.Mobile
  375. item.Email = user.Email
  376. item.CompanyId = user.CompanyId
  377. item.CompanyName = user.CompanyName
  378. if sellerItem != nil {
  379. item.SellerName = sellerItem.RealName
  380. }
  381. err = models.AddCygxActivitySpecialTrip(item)
  382. if err != nil {
  383. br.Msg = "操作失败"
  384. br.ErrMsg = "操作失败,Err:" + err.Error()
  385. return
  386. }
  387. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  388. ////给所属销售发送消息
  389. //if sellerItem.Mobile != "" {
  390. // openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  391. // if openIpItem != nil && openIpItem.OpenId != "" {
  392. // if sellerItem != nil {
  393. // go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
  394. // }
  395. // }
  396. //}
  397. // 给芳姐发消息
  398. //cnf, _ := models.GetConfigByCode("tpl_msg")
  399. //if cnf != nil {
  400. // openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  401. // if openIpItem != nil && openIpItem.OpenId != "" {
  402. // actList, _ := models.GetActivityListSpecialAll(activityId)
  403. // if len(actList) == 5 {
  404. // var companyName string
  405. // for _, v := range actList {
  406. // companyName += "【" + v.CompanyName + "】"
  407. // }
  408. // go services.SendSpecialTemplateMsg(companyName, "", "", activityInfo.ResearchTheme, "", openIpItem)
  409. // }
  410. // }
  411. //}
  412. ////用户专项调研操作行为,模板消息推送
  413. //go services.SpecialActivityUserRemind(user, activityInfo, 1)
  414. }
  415. }
  416. }
  417. br.Ret = 200
  418. br.Success = true
  419. br.Msg = "操作成功"
  420. br.Data = resp
  421. }
  422. // @Title 取消报名
  423. // @Description 取消报名
  424. // @Param request body models.ActivityIdRep true "type json string"
  425. // @Success Ret=200 {object} models.SignupStatus
  426. // @router /trip/cancel [post]
  427. func (this *ActivitySpecialCoAntroller) Tripcancel() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. user := this.User
  434. if user == nil {
  435. br.Msg = "请登录"
  436. br.ErrMsg = "请登录,用户信息为空"
  437. br.Ret = 408
  438. return
  439. }
  440. uid := user.UserId
  441. var req models.ActivityIdRep
  442. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  443. if err != nil {
  444. br.Msg = "参数解析异常!"
  445. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  446. return
  447. }
  448. activityId := req.ActivityId
  449. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  450. if activityInfo == nil {
  451. br.Msg = "操作失败"
  452. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  453. return
  454. }
  455. if errInfo != nil {
  456. br.Msg = "操作失败"
  457. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  458. return
  459. }
  460. err = models.CancelActivitySpecialTrip(uid, activityInfo)
  461. if err != nil {
  462. br.Msg = "操作失败"
  463. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  464. return
  465. }
  466. br.Ret = 200
  467. br.Success = true
  468. br.Msg = "会议提醒已取消"
  469. }