activity_special.go 14 KB

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