activity_special.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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 t.activity_id = ? AND t.is_cancel = 0 `
  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, popupMsg, err := services.GetUserHasPermission(user)
  145. if err != nil {
  146. br.Msg = "获取信息失败"
  147. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  148. return
  149. }
  150. resp.PopupMsg = 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. activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
  189. if activityInfo == nil {
  190. br.Msg = "操作失败"
  191. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  192. return
  193. }
  194. if errInfo != nil {
  195. br.Msg = "操作失败"
  196. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  197. return
  198. }
  199. havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
  200. if err != nil {
  201. br.Msg = "获取信息失败"
  202. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  203. return
  204. }
  205. //判断有没有对应的权限,如果没有则给出对应的状态码
  206. if havePower {
  207. resp.HasPermission = 1
  208. signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
  209. if err != nil {
  210. br.Msg = "获取信息失败"
  211. br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
  212. return
  213. }
  214. resp.PopupMsg = popupMsg
  215. resp.PopupMsg2 = popupMsg2
  216. resp.SignupStatus = signupStatus
  217. if signupStatus == 1 {
  218. total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
  219. if err != nil {
  220. br.Msg = "获取信息失败"
  221. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  222. return
  223. }
  224. //流水记录表
  225. itemBill := new(models.CygxActivitySpecialTripBill)
  226. itemBill.UserId = user.UserId
  227. itemBill.ActivityId = activityInfo.ActivityId
  228. itemBill.CreateTime = time.Now()
  229. itemBill.Mobile = user.Mobile
  230. itemBill.Email = user.Email
  231. itemBill.CompanyId = user.CompanyId
  232. itemBill.CompanyName = user.CompanyName
  233. itemBill.RealName = user.RealName
  234. itemBill.Source = 1
  235. itemBill.DoType = 1
  236. itemBill.BillDetailed = -1 // 流水减一
  237. itemBill.RegisterPlatform = 1
  238. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  239. var itemMeeting = new(models.CygxActivitySpecialMeetingDetail)
  240. itemMeeting.UserId = user.UserId
  241. itemMeeting.ActivityId = activityId
  242. itemMeeting.CreateTime = time.Now()
  243. itemMeeting.Mobile = user.Mobile
  244. itemMeeting.Email = user.Email
  245. itemMeeting.CompanyId = user.CompanyId
  246. itemMeeting.CompanyName = user.CompanyName
  247. itemMeeting.RealName = user.RealName
  248. go services.ActivitySpecialUserRmind(user, activityId, 2)
  249. //判断是删除还是添加
  250. if total == 0 {
  251. //获取销售信息
  252. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  253. if err != nil {
  254. br.Msg = "操作失败"
  255. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  256. return
  257. }
  258. item := new(models.CygxActivitySpecialTrip)
  259. item.UserId = uid
  260. item.RealName = user.RealName
  261. item.ActivityId = activityId
  262. item.CreateTime = time.Now()
  263. item.Mobile = user.Mobile
  264. item.Email = user.Email
  265. item.CompanyId = user.CompanyId
  266. item.CompanyName = user.CompanyName
  267. item.IsValid = 1
  268. if sellerItem != nil {
  269. item.SellerName = sellerItem.RealName
  270. }
  271. if user.OutboundMobile != "" {
  272. item.OutboundMobile = user.OutboundMobile
  273. if user.OutboundCountryCode == "" {
  274. item.CountryCode = "86"
  275. } else {
  276. item.CountryCode = user.OutboundCountryCode
  277. }
  278. } else {
  279. item.OutboundMobile = user.Mobile
  280. if user.CountryCode == "" {
  281. item.CountryCode = "86"
  282. } else {
  283. item.CountryCode = user.CountryCode
  284. }
  285. }
  286. err = models.AddCygxActivitySpecialTrip(item)
  287. if err != nil {
  288. br.Msg = "操作失败"
  289. br.ErrMsg = "操作失败,Err:" + err.Error()
  290. return
  291. }
  292. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  293. } else {
  294. updateParams := make(map[string]interface{})
  295. updateParams["IsValid"] = 1
  296. updateParams["CreateTime"] = time.Now()
  297. updateParams["IsCancel"] = 0
  298. whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
  299. err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
  300. if err != nil {
  301. br.Msg = "报名失败,"
  302. br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
  303. return
  304. }
  305. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  306. //48小时之内的取消也扣除一次参会记录
  307. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  308. itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
  309. }
  310. }
  311. userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
  312. if err != nil {
  313. br.Msg = "获取专项调研剩余次数失败"
  314. br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  315. return
  316. }
  317. if userType == 2 {
  318. tripRemaining = tripRemaining+itemBill.BillDetailed
  319. itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  320. } else {
  321. for k, num := range mapChartName {
  322. if activityInfo.ChartPermissionName == k {
  323. num = num+ itemBill.BillDetailed
  324. }
  325. itemBill.Total += k + strconv.Itoa(num) + "次+"
  326. }
  327. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  328. }
  329. //添加流水记录
  330. err = models.AddCygxActivitySpecialTripBill(itemBill)
  331. if err != nil {
  332. br.Msg = "报名失败,"
  333. br.ErrMsg = "AddCygxActivitySpecialTripBill,Err:" + err.Error()
  334. return
  335. }
  336. //添加数据到会信息
  337. err = models.AddCygxActivitySpecialMeetingDetail(itemMeeting)
  338. if err != nil {
  339. br.Msg = "报名失败,"
  340. br.ErrMsg = "AddCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  341. return
  342. }
  343. }
  344. } else {
  345. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
  346. if err != nil {
  347. br.Msg = "获取信息失败"
  348. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  349. return
  350. }
  351. resp.PopupMsg = popupMsg
  352. resp.HasPermission = hasPermission
  353. resp.SellerName = sellerName
  354. resp.SellerMobile = sellerMobile
  355. }
  356. resp.ActivityId = activityId
  357. br.Ret = 200
  358. br.Success = true
  359. br.Msg = "操作成功"
  360. br.Data = resp
  361. }
  362. // @Title 取消报名
  363. // @Description 取消报名
  364. // @Param request body models.ActivityIdRep true "type json string"
  365. // @Success Ret=200 {object} models.SignupStatus
  366. // @router /trip/cancel [post]
  367. func (this *ActivitySpecialCoAntroller) Tripcancel() {
  368. br := new(models.BaseResponse).Init()
  369. defer func() {
  370. this.Data["json"] = br
  371. this.ServeJSON()
  372. }()
  373. user := this.User
  374. if user == nil {
  375. br.Msg = "请登录"
  376. br.ErrMsg = "请登录,用户信息为空"
  377. br.Ret = 408
  378. return
  379. }
  380. uid := user.UserId
  381. var req models.ActivityIdRep
  382. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  383. if err != nil {
  384. br.Msg = "参数解析异常!"
  385. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  386. return
  387. }
  388. activityId := req.ActivityId
  389. activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, 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. //流水记录表
  401. itemBill := new(models.CygxActivitySpecialTripBill)
  402. itemBill.UserId = user.UserId
  403. itemBill.ActivityId = activityInfo.ActivityId
  404. itemBill.CreateTime = time.Now()
  405. itemBill.Mobile = user.Mobile
  406. itemBill.Email = user.Email
  407. itemBill.CompanyId = user.CompanyId
  408. itemBill.CompanyName = user.CompanyName
  409. itemBill.RealName = user.RealName
  410. itemBill.Source = 1
  411. itemBill.DoType = 2
  412. itemBill.BillDetailed = 1 // 流水加一
  413. itemBill.RegisterPlatform = 1
  414. itemBill.ChartPermissionId = activityInfo.ChartPermissionId
  415. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
  416. //48小时之内的取消也扣除一次参会记录
  417. var isValid int
  418. if time.Now().Add(+time.Hour * 48).After(resultTime) {
  419. isValid = 1
  420. itemBill.BillDetailed = 0 //48小时之内取消的活动扣点不返回
  421. }
  422. userType, tripRemaining, mapChartName, err := services.GetChartPermissionSpecialSurplusByCompany(user.CompanyId)
  423. if err != nil {
  424. br.Msg = "获取专项调研剩余次数失败"
  425. br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  426. return
  427. }
  428. if userType == 2 {
  429. tripRemaining += itemBill.BillDetailed
  430. itemBill.Total = strconv.Itoa(tripRemaining) + "次"
  431. } else {
  432. for k, num := range mapChartName {
  433. if activityInfo.ChartPermissionName == k {
  434. num += itemBill.BillDetailed
  435. }
  436. itemBill.Total += k + strconv.Itoa(num) + "次+"
  437. }
  438. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  439. }
  440. err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
  441. if err != nil {
  442. br.Msg = "操作失败"
  443. br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
  444. return
  445. }
  446. err = models.CancelCygxActivitySpecialMeetingDetail(uid, activityId)
  447. if err != nil {
  448. br.Msg = "操作失败"
  449. br.ErrMsg = "CancelCygxActivitySpecialMeetingDetail,Err:" + err.Error()
  450. return
  451. }
  452. go models.AddCygxActivitySpecialTripBill(itemBill)
  453. br.Ret = 200
  454. br.Success = true
  455. br.Msg = "已取消"
  456. }