You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.0 KiB
91 lines
2.0 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class AudienceRegistration extends Model
|
|
{
|
|
public const PURPOSES = [
|
|
'项目交流',
|
|
'产业合作',
|
|
'投资对接',
|
|
'学习参访',
|
|
'媒体报道',
|
|
'其他',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'competition_id',
|
|
'audience_session_id',
|
|
'user_id',
|
|
'name',
|
|
'phone',
|
|
'company',
|
|
'job',
|
|
'purpose',
|
|
'ticket_code',
|
|
'registered_at',
|
|
'checked_in_at',
|
|
'checked_in_by_admin_id',
|
|
'checked_in_by_competition_admin_id',
|
|
];
|
|
|
|
/**
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'registered_at' => 'datetime',
|
|
'checked_in_at' => 'datetime',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $row) {
|
|
if (! filled($row->ticket_code)) {
|
|
$row->ticket_code = self::newTicketCode();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static function newTicketCode(): string
|
|
{
|
|
do {
|
|
$code = bin2hex(random_bytes(8));
|
|
} while (self::query()->where('ticket_code', $code)->exists());
|
|
|
|
return $code;
|
|
}
|
|
|
|
public function competition(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Competition::class);
|
|
}
|
|
|
|
public function session(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AudienceSession::class, 'audience_session_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function checkedInBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'checked_in_by_admin_id');
|
|
}
|
|
|
|
public function checkedInByCompetitionAdmin(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CompetitionAdmin::class, 'checked_in_by_competition_admin_id');
|
|
}
|
|
|
|
public function isCheckedIn(): bool
|
|
{
|
|
return $this->checked_in_at !== null;
|
|
}
|
|
}
|