generated from liutk/owl-admin-base
89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Ad extends Model
|
|
{
|
|
use Filterable;
|
|
use HasFactory;
|
|
|
|
public const TYPE_OFF = 0; //无跳转
|
|
|
|
public const TYPE_WEB = 1; //网页跳转
|
|
|
|
public const TYPE_APP = 2; //应用跳转
|
|
|
|
public const TYPE_MINI = 3; //小程序跳转
|
|
|
|
protected function serializeDate(\DateTimeInterface $date)
|
|
{
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
protected $casts = [
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
'published_at' => 'datetime',
|
|
'is_enable' => 'boolean',
|
|
'jump_config' => 'array',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'resource',
|
|
'address',
|
|
'remark',
|
|
'published_at',
|
|
'is_enable',
|
|
'sort',
|
|
'jump_type',
|
|
'jump_config',
|
|
];
|
|
|
|
public static function jumpTypeMap(): array
|
|
{
|
|
return [
|
|
self::TYPE_WEB => '网页跳转',
|
|
self::TYPE_APP => '应用跳转',
|
|
self::TYPE_MINI => '小程序跳转',
|
|
self::TYPE_OFF => '无跳转',
|
|
];
|
|
}
|
|
|
|
public static function jumpTypeMapLabel()
|
|
{
|
|
return [
|
|
self::TYPE_OFF => "<span class='label'>无跳转</span>",
|
|
self::TYPE_WEB => "<span class='label label-info'>网页跳转</span>",
|
|
self::TYPE_APP => "<span class='label label-warning'>应用跳转</span>",
|
|
self::TYPE_MINI => "<span class='label label-green'>小程序跳转</span>",
|
|
'*' => '其他:${jump_type}',
|
|
];
|
|
}
|
|
|
|
public static function typeMapLabel()
|
|
{
|
|
return [
|
|
self::TYPE_IN => "<span class='label label-info'>入住缴费</span>",
|
|
self::TYPE_CONTINUE => "<span class='label label-warning'>续住缴费</span>",
|
|
self::TYPE_EXIT => "<span class='label label-danger'>离开结算</span>",
|
|
'*' => '其他:${live_in}',
|
|
];
|
|
}
|
|
|
|
public function scopeShow()
|
|
{
|
|
$q->where('is_enable', true)->where('published_at', '>=', now());
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
$q->orderBy('sort', 'asc')
|
|
->orderBy('published_at', 'desc')
|
|
->orderBy('created_at', 'desc');
|
|
}
|
|
}
|