activity_special.go 14 KB

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