互动
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.

86 lines
2.2 KiB

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. "github.com/ouxuanserver/osmanthuswine/src/core"
  9. )
  10. type UpperWallCtl struct {
  11. controllers.AuthorCtl
  12. }
  13. //发送上墙消息
  14. // todo: 支付接口
  15. func (t *UpperWallCtl) Send() {
  16. uid := t.MustGetUID()
  17. activityId := t.MustGetInt64("activity_id")
  18. category := t.MustGetInt("category")
  19. content, _ := t.Get("content")
  20. img, _ := t.Get("img")
  21. //获取主活动信息
  22. activity := new(models.Activity)
  23. exist, err := models.GetById(activity, activityId)
  24. t.CheckErr(err)
  25. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  26. t.CheckRunning(activity.Status)
  27. msgWall := new(models.MsgWallServer)
  28. exist, err = msgWall.GetByActivityId(activityId)
  29. t.CheckErr(err)
  30. if !exist || msgWall.UpWallStatus == "关闭" {
  31. t.ERROR("上墙活动尚未开启", code.MSG_ERR)
  32. }
  33. //获取用信息
  34. user := new(models.User)
  35. exist, err = models.GetById(user, uid)
  36. t.CheckErr(err)
  37. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  38. uw := new(models.UpperWall)
  39. uw.RehearsalId = activity.RehearsalId
  40. uw.ActivityId = activityId
  41. uw.Category = fmt.Sprintf("%v", category)
  42. uw.UserId = user.Id
  43. uw.Content = content
  44. uw.Img = img
  45. uw.Status = 0
  46. uw.CreatedAt = time.Now()
  47. uw.UpdatedAt = time.Now()
  48. _, err = core.GetXormAuto().Insert(uw)
  49. t.CheckErr(err)
  50. t.SUCCESS("成功")
  51. }
  52. type UWListResult struct {
  53. Id int64 `json:"id"`
  54. Content string `json:"content"`
  55. Img string `json:"img"`
  56. Category string `json:"category"`
  57. Status int `json:"status"`
  58. }
  59. func (t *UpperWallCtl) List() {
  60. activityId := t.MustGetInt64("activity_id")
  61. uid := t.MustGetUID()
  62. activity := new(models.Activity)
  63. exist, err := models.GetById(activity, activityId)
  64. t.CheckErr(err)
  65. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  66. list := make([]*UWListResult, 0)
  67. err = core.GetXormAuto().Table(new(models.UpperWall)).Select("id, content, img, category, status").
  68. Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?", uid, activityId, activity.RehearsalId).
  69. OrderBy("created_at desc").Find(&list)
  70. t.CheckErr(err)
  71. t.JSON(map[string]interface{}{
  72. "list": list,
  73. "total": len(list),
  74. })
  75. }