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.
98 lines
2.3 KiB
98 lines
2.3 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class AudienceSmsLog extends Model
|
|
{
|
|
public const SCENE_PRE_REGISTER = 'pre_register';
|
|
|
|
public const SCENE_APPROVED = 'approved';
|
|
|
|
public const SCENE_AUDIENCE_LOGIN = 'audience_login';
|
|
|
|
public const SCENE_PARTICIPANT_LOGIN = 'participant_login';
|
|
|
|
public const STATUS_PENDING = 'pending';
|
|
|
|
public const STATUS_SENDING = 'sending';
|
|
|
|
public const STATUS_DELIVERED = 'delivered';
|
|
|
|
public const STATUS_DROPPED = 'dropped';
|
|
|
|
public const STATUS_FAILED = 'failed';
|
|
|
|
protected $fillable = [
|
|
'competition_id',
|
|
'audience_registration_id',
|
|
'scene',
|
|
'mobile',
|
|
'template_id',
|
|
'content',
|
|
'vars_json',
|
|
'send_id',
|
|
'status',
|
|
'fee',
|
|
'report_state',
|
|
'dropped_reason',
|
|
'sent_at',
|
|
'delivered_at',
|
|
'last_synced_at',
|
|
];
|
|
|
|
/**
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'vars_json' => 'array',
|
|
'fee' => 'integer',
|
|
'sent_at' => 'datetime',
|
|
'delivered_at' => 'datetime',
|
|
'last_synced_at' => 'datetime',
|
|
];
|
|
|
|
public function competition(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Competition::class);
|
|
}
|
|
|
|
public function registration(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AudienceRegistration::class, 'audience_registration_id');
|
|
}
|
|
|
|
public function isFailed(): bool
|
|
{
|
|
return in_array($this->status, [self::STATUS_DROPPED, self::STATUS_FAILED], true);
|
|
}
|
|
|
|
public function isTerminalSuccess(): bool
|
|
{
|
|
return $this->status === self::STATUS_DELIVERED;
|
|
}
|
|
|
|
public function canResend(): bool
|
|
{
|
|
return $this->isFailed();
|
|
}
|
|
|
|
public function isLoginScene(): bool
|
|
{
|
|
return in_array($this->scene, [self::SCENE_AUDIENCE_LOGIN, self::SCENE_PARTICIPANT_LOGIN], true);
|
|
}
|
|
|
|
public static function sceneLabel(string $scene): string
|
|
{
|
|
return match ($scene) {
|
|
self::SCENE_APPROVED => '审核通过',
|
|
self::SCENE_PRE_REGISTER => '预报名成功',
|
|
self::SCENE_AUDIENCE_LOGIN => '观众登录验证码',
|
|
self::SCENE_PARTICIPANT_LOGIN => '选手登录验证码',
|
|
default => '短信',
|
|
};
|
|
}
|
|
}
|