package client import ( "fmt" "hudongzhuanjia/controllers" "hudongzhuanjia/models" "hudongzhuanjia/services/upper_wall" "hudongzhuanjia/utils/code" "time" ) type UpperWallCtl struct { controllers.AuthorCtl } //发送上墙消息 func (t *UpperWallCtl) Send() { uid := t.MustGetUID() activityId := t.MustGetInt64("activity_id") category := t.MustGetInt("category") content, _ := t.Get("content") img, _ := t.Get("img") //获取主活动信息 activity := new(models.Activity) exist, err := models.Get(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.Get(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 = models.Add(uw) t.CheckErr(err) t.SUCCESS("成功") } func (t *UpperWallCtl) List() { activityId := t.MustGetInt64("activity_id") userId := t.MustGetUID() activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") list, err := upper_wall.GetUpperWallResult(userId, activity.Id, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ "list": list, "total": len(list), }) }