互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package client
  2. import (
  3. "fmt"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. "hudongzhuanjia/utils/code"
  7. "time"
  8. )
  9. type UpperWallCtl struct {
  10. controllers.AuthorCtl
  11. }
  12. //发送上墙消息
  13. // todo: 支付接口
  14. func (t *UpperWallCtl) Send() {
  15. uid := t.MustGetUID()
  16. activityId := t.MustGetInt64("activity_id")
  17. category := t.MustGetInt("category")
  18. content, _ := t.Get("content")
  19. img, _ := t.Get("img")
  20. //获取主活动信息
  21. activity := new(models.Activity)
  22. exist, err := models.Get(activity, activityId)
  23. t.CheckErr(err)
  24. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  25. t.CheckRunning(activity.Status)
  26. msgWall := new(models.MsgWallServer)
  27. exist, err = msgWall.GetByActivityId(activityId)
  28. t.CheckErr(err)
  29. if !exist || msgWall.UpWallStatus == "关闭" {
  30. t.ERROR("上墙活动尚未开启", code.MSG_ERR)
  31. }
  32. //获取用信息
  33. user := new(models.User)
  34. exist, err = models.Get(user, uid)
  35. t.CheckErr(err)
  36. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  37. uw := new(models.UpperWall)
  38. uw.RehearsalId = activity.RehearsalId
  39. uw.ActivityId = activityId
  40. uw.Category = fmt.Sprintf("%v", category)
  41. uw.UserId = user.Id
  42. uw.Content = content
  43. uw.Img = img
  44. uw.Status = 0
  45. uw.CreatedAt = time.Now()
  46. uw.UpdatedAt = time.Now()
  47. _, err = models.Add(uw)
  48. t.CheckErr(err)
  49. t.SUCCESS("成功")
  50. }
  51. type UpperWallResult struct {
  52. Id int64 `json:"id"`
  53. Content string `json:"content"`
  54. Img string `json:"img"`
  55. Category string `json:"category"`
  56. Status int `json:"status"`
  57. }
  58. func (t *UpperWallCtl) List() {
  59. activityId := t.MustGetInt64("activity_id")
  60. userId := t.MustGetUID()
  61. activity := new(models.Activity)
  62. exist, err := models.Get(activity, activityId)
  63. t.CheckErr(err)
  64. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  65. list := make([]*UpperWallResult, 0)
  66. err = models.GetUpperWallResultByUserIdAndActivityId(list, userId, activity.Id, activity.RehearsalId)
  67. t.CheckErr(err)
  68. t.JSON(map[string]interface{}{
  69. "list": list,
  70. "total": len(list),
  71. })
  72. }