activity_special.go 17 KB

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