activity_special.go 14 KB

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