qinzexin 03c19a0c31 新闻管理,接口
团务百科管理,接口
信息公开管理,接口
2025-05-21 18:06:43 +08:00

85 lines
1.8 KiB
PHP

<?php
namespace app\admin\model\home;
use think\Model;
use traits\model\SoftDelete;
class Information extends Model
{
use SoftDelete;
// 表名
protected $name = 'information';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'type_text',
'recommend_text',
'release_time_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
if (!$row['weigh']) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
}
});
}
public function getTypeList()
{
return ['1' => __('Type 1'), '2' => __('Type 2')];
}
public function getRecommendList()
{
return ['0' => __('Recommend 0'), '1' => __('Recommend 1')];
}
public function getTypeTextAttr($value, $data)
{
$value = $value ?: ($data['type'] ?? '');
$list = $this->getTypeList();
return $list[$value] ?? '';
}
public function getRecommendTextAttr($value, $data)
{
$value = $value ?: ($data['recommend'] ?? '');
$list = $this->getRecommendList();
return $list[$value] ?? '';
}
public function getReleaseTimeTextAttr($value, $data)
{
$value = $value ?: ($data['release_time'] ?? '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setReleaseTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
}