123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Models;
- use Auth;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- /**
- * 工单.
- *
- * @property int $id
- * @property int $user_id 用户ID
- * @property int|null $admin_id 管理员ID
- * @property string $title 标题
- * @property string $content 内容
- * @property int $status 状态:0-待处理、1-已处理未关闭、2-已关闭
- * @property \Illuminate\Support\Carbon $created_at 创建时间
- * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
- * @property-read \App\Models\User|null $admin
- * @property-read string $status_label
- * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TicketReply[] $reply
- * @property-read int|null $reply_count
- * @property-read \App\Models\User $user
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket query()
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket uid()
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereAdminId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereContent($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereTitle($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereUpdatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|Ticket whereUserId($value)
- * @mixin \Eloquent
- */
- class Ticket extends Model
- {
- protected $table = 'ticket';
- protected $guarded = [];
- public function scopeUid($query)
- {
- return $query->whereUserId(Auth::id());
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function admin(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function reply(): HasMany
- {
- return $this->hasMany(TicketReply::class);
- }
- public function close(): bool
- {
- $this->status = 2;
- return $this->save();
- }
- public function getStatusLabelAttribute(): string
- {
- switch ($this->attributes['status']) {
- case 0:
- $status_label = '<span class="badge badge-lg badge-success">'.trans('user.status.pending').'</span>';
- break;
- case 1:
- $status_label = '<span class="badge badge-lg badge-danger">'.trans('user.status.reply').'</span>';
- break;
- case 2:
- $status_label = '<span class="badge badge-lg badge-default">'.trans('user.status.closed').'</span>';
- break;
- default:
- $status_label = '<span class="badge badge-lg badge-default">'.trans('user.unknown').'</span>';
- }
- return $status_label;
- }
- }
|