activity_special.go 17 KB

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