Files
chatroom/app/Models/FeedbackItem.php
lkddi 5f30220609 feat: 任命/撤销通知系统 + 用户名片UI优化
- 任命/撤销事件增加 type 字段区分类型
- 任命:全屏礼花 + 紫色弹窗 + 紫色系统消息
- 撤销:灰色弹窗 + 灰色系统消息,无礼花
- 消息分发:操作者/被操作者显示在私聊面板,其他人显示在公屏
- 系统消息加随机鼓励语(各5条轮换)
- ChatStateService 修复 Redis key 前缀扫描问题(getAllActiveRoomIds)
- 用户名片折叠优化:管理员视野、职务履历均可折叠
- 管理操作 + 职务操作合并为「🔧 管理操作」折叠区
- 悄悄话改为「🎁 送礼物」按钮,礼物面板内联展开
2026-02-28 23:44:38 +08:00

147 lines
4.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 文件功能:用户反馈主表 Model
* 对应 feedback_items 表,管理用户提交的 Bug报告和功能建议
* 包含7种处理状态、赞同数/评论数冗余统计
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class FeedbackItem extends Model
{
/**
* 允许批量赋值的字段
*/
protected $fillable = [
'user_id',
'username',
'type',
'title',
'content',
'status',
'admin_remark',
'votes_count',
'replies_count',
];
/**
* 处理状态配置(中文名 + 图标 + Tailwind 颜色)
*/
public const STATUS_CONFIG = [
'pending' => ['label' => '待处理', 'icon' => '⏳', 'color' => 'gray'],
'accepted' => ['label' => '已接受', 'icon' => '✅', 'color' => 'green'],
'in_progress' => ['label' => '开发中', 'icon' => '🔧', 'color' => 'blue'],
'fixed' => ['label' => '已修复', 'icon' => '🐛', 'color' => 'emerald'],
'done' => ['label' => '已完成', 'icon' => '🚀', 'color' => 'emerald'],
'rejected' => ['label' => '暂不同意', 'icon' => '❌', 'color' => 'red'],
'shelved' => ['label' => '已搁置', 'icon' => '📦', 'color' => 'orange'],
];
/**
* 类型配置
*/
public const TYPE_CONFIG = [
'bug' => ['label' => '🐛 Bug报告', 'color' => 'rose'],
'suggestion' => ['label' => '💡 功能建议', 'color' => 'blue'],
];
// ═══════════════ 关联关系 ═══════════════
/**
* 关联赞同记录
*/
public function votes(): HasMany
{
return $this->hasMany(FeedbackVote::class, 'feedback_id');
}
/**
* 关联补充评论
*/
public function replies(): HasMany
{
return $this->hasMany(FeedbackReply::class, 'feedback_id')->orderBy('created_at');
}
// ═══════════════ 查询作用域 ═══════════════
/**
* 按类型筛选
*
* @param string $type bug|suggestion
*/
public function scopeOfType(Builder $query, string $type): Builder
{
return $query->where('type', $type);
}
/**
* 按状态筛选
*
* @param string $status 处理状态
*/
public function scopeOfStatus(Builder $query, string $status): Builder
{
return $query->where('status', $status);
}
/**
* 待处理的反馈(用于后台徽标计数)
*/
public function scopePending(Builder $query): Builder
{
return $query->where('status', 'pending');
}
// ═══════════════ 访问器 ═══════════════
/**
* 获取状态对应的配置(标签/图标/颜色)
*/
public function getStatusConfigAttribute(): array
{
return self::STATUS_CONFIG[$this->status] ?? self::STATUS_CONFIG['pending'];
}
/**
* 获取状态中文标签
*/
public function getStatusLabelAttribute(): string
{
return $this->status_config['icon'].' '.$this->status_config['label'];
}
/**
* 获取类型中文标签
*/
public function getTypeLabelAttribute(): string
{
return self::TYPE_CONFIG[$this->type]['label'] ?? '📌 其他';
}
/**
* 判断反馈是否在24小时内用于普通用户自删权限
*/
public function getIsWithin24HoursAttribute(): bool
{
return $this->created_at->diffInHours(now()) < 24;
}
/**
* 判断当前状态是否为已处理(已修复/已完成/暂不同意/已搁置)
*/
public function getIsClosedAttribute(): bool
{
return in_array($this->status, ['fixed', 'done', 'rejected', 'shelved']);
}
}