activity_special.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. itemBill := new(models.CygxActivitySpecialTripBill)
  225. itemBill.UserId = user.UserId
  226. itemBill.ActivityId = activityInfo.ActivityId
  227. itemBill.CreateTime = time.Now()
  228. itemBill.Mobile = user.Mobile
  229. itemBill.Email = user.Email
  230. itemBill.CompanyId = user.CompanyId
  231. itemBill.CompanyName = user.CompanyName
  232. itemBill.RealName = user.RealName
  233. itemBill.Source = 1
  234. itemBill.DoType = 1
  235. itemBill.BillDetailed = -1 // 流水减一
  236. itemBill.RegisterPlatform = 1
  237. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  238. var itemMeeting = new(models.CygxActivitySpecialMeetingDetail)
  239. itemMeeting.UserId = user.UserId
  240. itemMeeting.ActivityId = activityId
  241. itemMeeting.CreateTime = time.Now()
  242. itemMeeting.Mobile = user.Mobile
  243. itemMeeting.Email = user.Email
  244. itemMeeting.CompanyId = user.CompanyId
  245. itemMeeting.CompanyName = user.CompanyName
  246. itemMeeting.RealName = user.RealName
  247. go services.ActivitySpecialUserRmind(user, activityId, 2)
  248. //判断是删除还是添加
  249. if total == 0 {
  250. //获取销售信息
  251. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  252. if err != nil {
  253. br.Msg = "操作失败"
  254. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  255. return
  256. }
  257. item := new(models.CygxActivitySpecialTrip)
  258. item.UserId = uid
  259. item.RealName = user.RealName
  260. item.ActivityId = activityId
  261. item.CreateTime = time.Now()
  262. item.Mobile = user.Mobile
  263. item.Email = user.Email
  264. item.CompanyId = user.CompanyId
  265. item.CompanyName = user.CompanyName
  266. item.IsValid = 1
  267. if sellerItem != nil {
  268. item.SellerName = sellerItem.RealName
  269. }
  270. if user.OutboundMobile != "" {
  271. item.OutboundMobile = user.OutboundMobile
  272. if user.OutboundCountryCode == "" {
  273. item.CountryCode = "86"
  274. } else {
  275. item.CountryCode = user.OutboundCountryCode
  276. }
  277. } else {
  278. item.OutboundMobile = user.Mobile
  279. if user.CountryCode == "" {
  280. item.CountryCode = "86"
  281. } else {
  282. item.CountryCode = user.CountryCode
  283. }
  284. }
  285. err = models.AddCygxActivitySpecialTrip(item)
  286. if err != nil {
  287. br.Msg = "操作失败"
  288. br.ErrMsg = "操作失败,Err:" + err.Error()
  289. return
  290. }
  291. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  292. } else {
  293. updateParams := make(map[string]interface{})
  294. updateParams["IsValid"] = 1
  295. updateParams["CreateTime"] = time.Now()
  296. updateParams["IsCancel"] = 0
  297. whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
  298. err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
  299. if err != nil {
  300. br.Msg = "报名失败,"
  301. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  302. return
  303. }
  304. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  305. //48小时之内的取消也扣除一次参会记录
  306. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  307. itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
  308. }
  309. }
  310. //添加流水记录
  311. err = models.AddCygxActivitySpecialTripBill(itemBill)
  312. if err != nil {
  313. br.Msg = "报名失败,"
  314. br.ErrMsg = "AddCygxActivitySpecialTripBill,Err:" + err.Error()
  315. return
  316. }
  317. //添加数据到会信息
  318. err = models.AddCygxActivitySpecialMeetingDetail(itemMeeting)
  319. if err != nil {
  320. br.Msg = "报名失败,"
  321. br.ErrMsg = "AddCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  322. return
  323. }
  324. }
  325. } else {
  326. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  327. if err != nil {
  328. br.Msg = "获取信息失败"
  329. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  330. return
  331. }
  332. resp.PopupMsg = popupMsg
  333. resp.HasPermission = hasPermission
  334. resp.SellerName = sellerName
  335. resp.SellerMobile = sellerMobile
  336. }
  337. resp.ActivityId = activityId
  338. br.Ret = 200
  339. br.Success = true
  340. br.Msg = "操作成功"
  341. br.Data = resp
  342. }
  343. // @Title 取消报名
  344. // @Description 取消报名
  345. // @Param request body models.ActivityIdRep true "type json string"
  346. // @Success Ret=200 {object} models.SignupStatus
  347. // @router /trip/cancel [post]
  348. func (this *ActivitySpecialCoAntroller) Tripcancel() {
  349. br := new(models.BaseResponse).Init()
  350. defer func() {
  351. this.Data["json"] = br
  352. this.ServeJSON()
  353. }()
  354. user := this.User
  355. if user == nil {
  356. br.Msg = "请登录"
  357. br.ErrMsg = "请登录,用户信息为空"
  358. br.Ret = 408
  359. return
  360. }
  361. uid := user.UserId
  362. var req models.ActivityIdRep
  363. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  364. if err != nil {
  365. br.Msg = "参数解析异常!"
  366. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  367. return
  368. }
  369. activityId := req.ActivityId
  370. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
  371. if activityInfo == nil {
  372. br.Msg = "操作失败"
  373. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  374. return
  375. }
  376. if errInfo != nil {
  377. br.Msg = "操作失败"
  378. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  379. return
  380. }
  381. //流水记录表
  382. itemBill := new(models.CygxActivitySpecialTripBill)
  383. itemBill.UserId = user.UserId
  384. itemBill.ActivityId = activityInfo.ActivityId
  385. itemBill.CreateTime = time.Now()
  386. itemBill.Mobile = user.Mobile
  387. itemBill.Email = user.Email
  388. itemBill.CompanyId = user.CompanyId
  389. itemBill.CompanyName = user.CompanyName
  390. itemBill.RealName = user.RealName
  391. itemBill.Source = 1
  392. itemBill.DoType = 2
  393. itemBill.BillDetailed = 1 // 流水加一
  394. itemBill.RegisterPlatform = 1
  395. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  396. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  397. //48小时之内的取消也扣除一次参会记录
  398. var isValid int
  399. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  400. isValid = 1
  401. itemBill.BillDetailed = 0 //48小时之内取消的活动扣点不返回
  402. }
  403. err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
  404. if err != nil {
  405. br.Msg = "操作失败"
  406. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  407. return
  408. }
  409. err = models.CancelCygxActivitySpecialMeetingDetail(uid, activityId)
  410. if err != nil {
  411. br.Msg = "操作失败"
  412. br.ErrMsg = "CancelCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  413. return
  414. }
  415. go models.AddCygxActivitySpecialTripBill(itemBill)
  416. br.Ret = 200
  417. br.Success = true
  418. br.Msg = "已取消"
  419. }