activity_special.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. "time"
  10. )
  11. //专项调研活动
  12. type ActivitySpecialCoAntroller struct {
  13. BaseAuthController
  14. }
  15. // @Title 专项产业调研列表
  16. // @Description 获取专项产业调研列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Success 200 {object} models.GetCygxActivitySpecialDetailListResp
  20. // @router /list [get]
  21. func (this *ActivitySpecialCoAntroller) SpecialList() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. return
  32. }
  33. pageSize, _ := this.GetInt("PageSize")
  34. currentIndex, _ := this.GetInt("CurrentIndex")
  35. if pageSize <= 0 {
  36. pageSize = utils.PageSize20
  37. }
  38. if currentIndex <= 0 {
  39. currentIndex = 1
  40. }
  41. list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "")
  42. if errList != nil {
  43. br.Msg = "获取失败"
  44. br.ErrMsg = "获取失败,Err:" + errList.Error()
  45. return
  46. }
  47. page := paging.GetPaging(currentIndex, pageSize, total)
  48. resp := new(models.GetCygxActivitySpecialDetailListResp)
  49. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  50. if err != nil {
  51. br.Msg = "获取数据失败!"
  52. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  53. return
  54. }
  55. if count == 1 && user.UserId > 0 {
  56. resp.IsFollow = true
  57. }
  58. if user.Mobile != "" {
  59. resp.IsBindingMobile = true
  60. }
  61. resp.List = list
  62. resp.Paging = page
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "获取成功"
  66. br.Data = resp
  67. }
  68. // @Title 专项产业调研详情
  69. // @Description 获取专项产业调研详情接口
  70. // @Param ActivityId query int true "活动ID"
  71. // @Success Ret=200 {object} models.CygxActivitySpecialResp
  72. // @router /detail [get]
  73. func (this *ActivitySpecialCoAntroller) SpecialDetail() {
  74. br := new(models.BaseResponse).Init()
  75. defer func() {
  76. this.Data["json"] = br
  77. this.ServeJSON()
  78. }()
  79. user := this.User
  80. if user == nil {
  81. br.Msg = "请登录"
  82. br.ErrMsg = "请登录,用户信息为空"
  83. br.Ret = 408
  84. return
  85. }
  86. uid := user.UserId
  87. activityId, _ := this.GetInt("ActivityId")
  88. if activityId < 1 {
  89. br.Msg = "请输入活动ID"
  90. return
  91. }
  92. resp := new(models.CygxActivitySpecialResp)
  93. activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
  94. if err != nil && err.Error() != utils.ErrNoRow() {
  95. br.Msg = "获取信息失败"
  96. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  97. return
  98. }
  99. if activityInfo == nil {
  100. br.Msg = "活动不存在"
  101. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  102. return
  103. }
  104. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  105. if err != nil {
  106. br.Msg = "获取信息失败"
  107. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  108. return
  109. }
  110. //判断有没有对应的权限,如果没有则给出对应的状态码
  111. if havePower {
  112. resp.HasPermission = 1
  113. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  114. if err != nil {
  115. br.Msg = "获取数据失败!"
  116. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  117. return
  118. }
  119. if count == 1 {
  120. resp.IsFollow = true
  121. }
  122. activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
  123. if err != nil {
  124. br.Msg = "获取数据失败!"
  125. br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
  126. return
  127. }
  128. var condition string
  129. var pars []interface{}
  130. condition += ` AND activity_id = ? `
  131. pars = append(pars, activityInfo.ActivityId)
  132. tripTota, err := models.GetActivitySpecialTripCountByActivityId(condition, pars)
  133. if err != nil {
  134. br.Msg = "获取数据失败!"
  135. br.ErrMsg = "GetActivitySpecialTripCountByActivityId,Err:" + err.Error()
  136. return
  137. }
  138. activityInfo.TripNum = tripTota
  139. activityInfo.ActivityTypeName = "专项调研"
  140. resp.Detail = activityInfo
  141. resp.Detail = activityInfo
  142. } else {
  143. hasPermission, sellerName, sellerMobile, err := services.GetUserHasPermission(user)
  144. if err != nil {
  145. br.Msg = "获取信息失败"
  146. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  147. return
  148. }
  149. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  150. resp.HasPermission = hasPermission
  151. resp.SellerName = sellerName
  152. resp.SellerMobile = sellerMobile
  153. }
  154. br.Ret = 200
  155. br.Success = true
  156. br.Msg = "获取成功"
  157. br.Data = resp
  158. }
  159. // @Title报名
  160. // @Description 报名
  161. // @Param request body models.ActivityIdRep true "type json string"
  162. // @Success Ret=200 {object} models.SignupSpecialStatus
  163. // @router /add [post]
  164. func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
  165. br := new(models.BaseResponse).Init()
  166. defer func() {
  167. this.Data["json"] = br
  168. this.ServeJSON()
  169. }()
  170. user := this.User
  171. if user == nil {
  172. br.Msg = "请登录"
  173. br.ErrMsg = "请登录,用户信息为空"
  174. br.Ret = 408
  175. return
  176. }
  177. uid := user.UserId
  178. var req models.ActivityIdRep
  179. resp := new(models.SignupSpecialStatus)
  180. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  181. if err != nil {
  182. br.Msg = "参数解析异常!"
  183. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  184. return
  185. }
  186. activityId := req.ActivityId
  187. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  188. if activityInfo == nil {
  189. br.Msg = "操作失败"
  190. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  191. return
  192. }
  193. if errInfo != nil {
  194. br.Msg = "操作失败"
  195. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  196. return
  197. }
  198. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  199. if err != nil {
  200. br.Msg = "获取信息失败"
  201. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  202. return
  203. }
  204. //判断有没有对应的权限,如果没有则给出对应的状态码
  205. if havePower {
  206. resp.HasPermission = 1
  207. signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
  208. if err != nil {
  209. br.Msg = "获取信息失败"
  210. br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
  211. return
  212. }
  213. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  214. if err != nil {
  215. br.Msg = "获取信息失败"
  216. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  217. return
  218. }
  219. resp.PopupMsg = popupMsg
  220. resp.PopupMsg2 = popupMsg2
  221. resp.SignupStatus = signupStatus
  222. if signupStatus == 1 {
  223. //判断是删除还是添加
  224. if total == 0 {
  225. //获取销售信息
  226. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  227. if err != nil {
  228. br.Msg = "操作失败"
  229. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  230. return
  231. }
  232. item := new(models.CygxActivitySpecialTrip)
  233. item.UserId = uid
  234. item.RealName = user.RealName
  235. item.ActivityId = activityId
  236. item.CreateTime = time.Now()
  237. item.Mobile = user.Mobile
  238. item.Email = user.Email
  239. item.CompanyId = user.CompanyId
  240. item.CompanyName = user.CompanyName
  241. if sellerItem != nil {
  242. item.SellerName = sellerItem.RealName
  243. }
  244. err = models.AddCygxActivitySpecialTrip(item)
  245. if err != nil {
  246. br.Msg = "操作失败"
  247. br.ErrMsg = "操作失败,Err:" + err.Error()
  248. return
  249. }
  250. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  251. ////给所属销售发送消息
  252. //if sellerItem.Mobile != "" {
  253. // openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  254. // if openIpItem != nil && openIpItem.OpenId != "" {
  255. // if sellerItem != nil {
  256. // go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
  257. // }
  258. // }
  259. //}
  260. // 给芳姐发消息
  261. //cnf, _ := models.GetConfigByCode("tpl_msg")
  262. //if cnf != nil {
  263. // openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  264. // if openIpItem != nil && openIpItem.OpenId != "" {
  265. // actList, _ := models.GetActivityListSpecialAll(activityId)
  266. // if len(actList) == 5 {
  267. // var companyName string
  268. // for _, v := range actList {
  269. // companyName += "【" + v.CompanyName + "】"
  270. // }
  271. // go services.SendSpecialTemplateMsg(companyName, "", "", activityInfo.ResearchTheme, "", openIpItem)
  272. // }
  273. // }
  274. //}
  275. ////用户专项调研操作行为,模板消息推送
  276. //go services.SpecialActivityUserRemind(user, activityInfo, 1)
  277. }
  278. }
  279. } else {
  280. hasPermission, sellerName, sellerMobile, err := services.GetUserHasPermission(user)
  281. if err != nil {
  282. br.Msg = "获取信息失败"
  283. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  284. return
  285. }
  286. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  287. resp.HasPermission = hasPermission
  288. resp.SellerName = sellerName
  289. resp.SellerMobile = sellerMobile
  290. }
  291. resp.ActivityId = activityId
  292. br.Ret = 200
  293. br.Success = true
  294. br.Msg = "操作成功"
  295. br.Data = resp
  296. }
  297. // @Title 取消报名
  298. // @Description 取消报名
  299. // @Param request body models.ActivityIdRep true "type json string"
  300. // @Success Ret=200 {object} models.SignupStatus
  301. // @router /trip/cancel [post]
  302. func (this *ActivitySpecialCoAntroller) Tripcancel() {
  303. br := new(models.BaseResponse).Init()
  304. defer func() {
  305. this.Data["json"] = br
  306. this.ServeJSON()
  307. }()
  308. user := this.User
  309. if user == nil {
  310. br.Msg = "请登录"
  311. br.ErrMsg = "请登录,用户信息为空"
  312. br.Ret = 408
  313. return
  314. }
  315. uid := user.UserId
  316. var req models.ActivityIdRep
  317. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  318. if err != nil {
  319. br.Msg = "参数解析异常!"
  320. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  321. return
  322. }
  323. activityId := req.ActivityId
  324. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  325. if activityInfo == nil {
  326. br.Msg = "操作失败"
  327. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  328. return
  329. }
  330. if errInfo != nil {
  331. br.Msg = "操作失败"
  332. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  333. return
  334. }
  335. err = models.CancelActivitySpecialTrip(uid, activityInfo)
  336. if err != nil {
  337. br.Msg = "操作失败"
  338. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  339. return
  340. }
  341. br.Ret = 200
  342. br.Success = true
  343. br.Msg = "会议提醒已取消"
  344. }