65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Author: ywxapp<admin@ywxapp.cn>
|
||
// +----------------------------------------------------------------------
|
||
declare (strict_types = 1);
|
||
|
||
namespace ywxapp\model;
|
||
|
||
use think\model\concern\SoftDelete;
|
||
use ywxapp\model\BaseModel;
|
||
|
||
|
||
class Links extends BaseModel
|
||
{
|
||
use SoftDelete;
|
||
|
||
// 软删除时间字段(与 autoWriteTimestamp=int 保持一致,类型为 int)
|
||
protected $deleteTime = 'delete_at';
|
||
|
||
/**
|
||
* 模型配置
|
||
* @return array
|
||
*/
|
||
protected function getOptions(): array
|
||
{
|
||
return [
|
||
'strict' => true,
|
||
'name' => 'links',
|
||
'autoWriteTimestamp' => 'int',
|
||
'createTime' => 'create_at',
|
||
'updateTime' => 'update_at',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 运行时自愈:确保 links 主表存在(install.sql 为事实源)。
|
||
*/
|
||
public static function ensureSchema(): void
|
||
{
|
||
BaseModel::ensureTableFromInstall(BaseModel::currentPrefix(), 'links');
|
||
}
|
||
|
||
/**
|
||
* 初始化:自愈建表,避免远程库缺失 wxapp_links 导致 1146。
|
||
*/
|
||
protected function initialize()
|
||
{
|
||
parent::initialize();
|
||
self::ensureSchema();
|
||
}
|
||
|
||
/**
|
||
* 获取器:状态文本
|
||
*/
|
||
public function getStatusTextAttr($value, $data)
|
||
{
|
||
$status = [0 => '禁用', 1 => '启用'];
|
||
return $status[$data['status']] ?? '未知';
|
||
}
|
||
}
|