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

package client
import (
"fmt"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
type UpperWallCtl struct {
controllers.AuthorCtl
}
//发送上墙消息
// todo: 支付接口
func (t *UpperWallCtl) Send() {
uid := t.MustGetUID()
activityId := t.MustGetActivityId()
category := t.MustGetInt("category")
content, _ := t.Get("content")
img, _ := t.Get("img")
//获取主活动信息
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
msgWall := new(models.MsgWallServer)
exist, err = msgWall.GetByActivityId(activityId)
t.CheckErr(err)
if !exist || msgWall.UpWallStatus == "关闭" {
t.ERROR("上墙活动尚未开启", code.MSG_ERR)
}
//获取用信息
user := new(models.User)
exist, err = models.GetById(user, uid)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
uw := new(models.UpperWall)
uw.RehearsalId = activity.RehearsalId
uw.ActivityId = activityId
uw.Category = fmt.Sprintf("%v", category)
uw.UserId = user.Id
uw.Content = content
uw.Img = img
uw.Status = 0
uw.CreatedAt = time.Now()
uw.UpdatedAt = time.Now()
_, err = core.GetXormAuto().Insert(uw)
t.CheckErr(err)
t.SUCCESS("成功")
}
type UWListResult struct {
Id int64 `json:"id"`
Content string `json:"content"`
Img string `json:"img"`
Category string `json:"category"`
Status int `json:"status"`
}
func (t *UpperWallCtl) List() {
activityId := t.MustGetActivityId()
uid := t.MustGetUID()
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
list := make([]*UWListResult, 0)
err = core.GetXormAuto().Table(new(models.UpperWall)).Select("id, content, img, category, status").
Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?", uid, activityId, activity.RehearsalId).
OrderBy("created_at desc").Find(&list)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"list": list,
"total": len(list),
})
}