['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']); } }