activity_special.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 t.activity_id = ? AND t.is_cancel = 0 `
  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, popupMsg, err := services.GetUserHasPermission(user)
  144. if err != nil {
  145. br.Msg = "获取信息失败"
  146. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  147. return
  148. }
  149. resp.PopupMsg = 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. resp.PopupMsg = popupMsg
  214. resp.PopupMsg2 = popupMsg2
  215. resp.SignupStatus = signupStatus
  216. if signupStatus == 1 {
  217. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  218. if err != nil {
  219. br.Msg = "获取信息失败"
  220. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  221. return
  222. }
  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. item.IsValid = 1
  242. if sellerItem != nil {
  243. item.SellerName = sellerItem.RealName
  244. }
  245. err = models.AddCygxActivitySpecialTrip(item)
  246. if err != nil {
  247. br.Msg = "操作失败"
  248. br.ErrMsg = "操作失败,Err:" + err.Error()
  249. return
  250. }
  251. go services.ActivitySpecialUserRmind(user, activityId, 2)
  252. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  253. } else {
  254. updateParams := make(map[string]interface{})
  255. updateParams["IsValid"] = 1
  256. updateParams["CreateTime"] = time.Now()
  257. updateParams["IsCancel"] = 0
  258. whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
  259. err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
  260. if err != nil {
  261. br.Msg = "报名失败,"
  262. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  263. return
  264. }
  265. }
  266. }
  267. } else {
  268. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  269. if err != nil {
  270. br.Msg = "获取信息失败"
  271. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  272. return
  273. }
  274. resp.PopupMsg = popupMsg
  275. resp.HasPermission = hasPermission
  276. resp.SellerName = sellerName
  277. resp.SellerMobile = sellerMobile
  278. }
  279. resp.ActivityId = activityId
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "操作成功"
  283. br.Data = resp
  284. }
  285. // @Title 取消报名
  286. // @Description 取消报名
  287. // @Param request body models.ActivityIdRep true "type json string"
  288. // @Success Ret=200 {object} models.SignupStatus
  289. // @router /trip/cancel [post]
  290. func (this *ActivitySpecialCoAntroller) Tripcancel() {
  291. br := new(models.BaseResponse).Init()
  292. defer func() {
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. user := this.User
  297. if user == nil {
  298. br.Msg = "请登录"
  299. br.ErrMsg = "请登录,用户信息为空"
  300. br.Ret = 408
  301. return
  302. }
  303. uid := user.UserId
  304. var req models.ActivityIdRep
  305. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  306. if err != nil {
  307. br.Msg = "参数解析异常!"
  308. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  309. return
  310. }
  311. activityId := req.ActivityId
  312. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  313. if activityInfo == nil {
  314. br.Msg = "操作失败"
  315. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  316. return
  317. }
  318. if errInfo != nil {
  319. br.Msg = "操作失败"
  320. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  321. return
  322. }
  323. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  324. //48小时之内的取消也扣除一次参会记录
  325. var isValid int
  326. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  327. isValid = 1
  328. }
  329. err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
  330. if err != nil {
  331. br.Msg = "操作失败"
  332. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  333. return
  334. }
  335. br.Ret = 200
  336. br.Success = true
  337. br.Msg = "已取消"
  338. }