= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
[
'attribute' => 'status',
'label' => '状态',
'format' => 'raw',
'value' => function (Tickets $model) {
return match ($model->status) {
Tickets::STATUS_OPEN => '
工单已开启',
Tickets::STATUS_ADMIN_REPLY => '
管理员已回复',
Tickets::STATUS_USER_REPLY => '
用户已回复',
Tickets::STATUS_CLOSED => '
工单已关闭',
default => '
未知状态',
};
}
],
[
'attribute' => 'user_id',
'label' => '用户',
'format' => 'html',
'value' => function (Tickets $model) {
return $model->user->username . '
(ID: ' . $model->user->id . ')';
}
],
[
'attribute' => 'ip',
'label' => '用户IP',
],
[
'attribute' => 'created_at',
'label' => '创建时间',
'format' => 'raw', // 使用 raw 格式,这样 Yii2 不会对 value 的返回值进行 HTML 编码
'value' => function (Tickets $model) {
$dateTime = new DateTime($model->created_at, new DateTimeZone('GMT+8'));
return $model->created_at . '
(' . Yii::$app->formatter->asRelativeTime($dateTime) . ')';
}
],
[
'attribute' => 'updated_at',
'label' => '最近更新时间',
'format' => 'raw', // 使用 raw 格式,这样 Yii2 不会对 value 的返回值进行 HTML 编码
'value' => function (Tickets $model) {
$dateTime = new DateTime($model->updated_at, new DateTimeZone('GMT+8'));
return $model->updated_at . '
(' . Yii::$app->formatter->asRelativeTime($dateTime) . ')';
}
]
],
]) ?>
= ($model->status === Tickets::STATUS_CLOSED) ? '' : Html::a('关闭工单', ['ticket-delete', 'id' => $model->id], ['class' => 'btn btn-danger',
'data' => ['confirm' => '您确定要关闭这个工单吗?',
'method' => 'post',],]) ?>