103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\model\system;
|
|
|
|
use app\model\member\Member;
|
|
use core\base\BaseModel;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 问题反馈
|
|
*/
|
|
class Feedback extends BaseModel
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'sys_feedback';
|
|
|
|
protected $appends = ['created_date', 'updated_date', 'created_name', 'reply_date', 'reply_name'];
|
|
|
|
protected $hidden = ['createds', 'replyAdmin'];
|
|
|
|
protected $fillable = [
|
|
'id',
|
|
'type',
|
|
'content',
|
|
'contact',
|
|
'images',
|
|
'source',
|
|
'created_by',
|
|
'reply_content',
|
|
'reply_by',
|
|
'reply_at',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'images' => 'array',
|
|
'created_at' => 'integer',
|
|
'updated_at' => 'integer',
|
|
'deleted_at' => 'integer',
|
|
'created_by' => 'string',
|
|
'reply_by' => 'string',
|
|
'reply_at' => 'integer',
|
|
];
|
|
|
|
public function getCreatedDateAttribute(): ?string
|
|
{
|
|
$timestamp = $this->getRawOriginal('created_at');
|
|
return empty($timestamp)
|
|
? null
|
|
: \Carbon\Carbon::createFromTimestamp((int)$timestamp)
|
|
->setTimezone(config('app.default_timezone'))
|
|
->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
public function createds(): HasOne
|
|
{
|
|
return $this->hasOne(Member::class, 'id', 'created_by')
|
|
->select(['id', 'nickname', 'username']);
|
|
}
|
|
|
|
public function replyAdmin(): HasOne
|
|
{
|
|
return $this->hasOne(Admin::class, 'id', 'reply_by')
|
|
->select(['id', 'real_name', 'user_name', 'nick_name']);
|
|
}
|
|
|
|
public function getReplyDateAttribute(): ?string
|
|
{
|
|
$timestamp = $this->getRawOriginal('reply_at');
|
|
return empty($timestamp)
|
|
? null
|
|
: \Carbon\Carbon::createFromTimestamp((int)$timestamp)
|
|
->setTimezone(config('app.default_timezone'))
|
|
->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
public function getReplyNameAttribute(): ?string
|
|
{
|
|
if (empty($this->getRawOriginal('reply_by'))) {
|
|
return null;
|
|
}
|
|
|
|
$admin = $this->relationLoaded('replyAdmin')
|
|
? $this->getRelation('replyAdmin')
|
|
: $this->replyAdmin()->first();
|
|
return (string)($admin?->getRawOriginal('real_name') ?: $admin?->getRawOriginal('nick_name') ?: $admin?->getRawOriginal('user_name') ?: '管理员');
|
|
}
|
|
|
|
public function getCreatedNameAttribute(): string
|
|
{
|
|
$member = $this->relationLoaded('createds')
|
|
? $this->getRelation('createds')
|
|
: $this->createds()->first();
|
|
return (string)($member?->getRawOriginal('nickname') ?: $member?->getRawOriginal('username') ?: '匿名用户');
|
|
}
|
|
}
|