89 lines
1.8 KiB
PHP
Raw Normal View History

2025-05-20 16:33:23 +08:00
<?php
namespace app\common\model\home;
use app\common\model\BaseModel;
use think\Model;
use traits\model\SoftDelete;
class NewsCate extends BaseModel
{
use SoftDelete;
// 表名
protected $name = 'news_cate';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'status_text',
'hot_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 getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getHotList()
{
return ['0' => __('Hot 0'), '1' => __('Hot 1')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
public function getHotTextAttr($value, $data)
{
$value = $value ?: ($data['hot'] ?? '');
$list = $this->getHotList();
return $list[$value] ?? '';
}
public function getImageAttr($value, $data)
{
if (!empty($value)) return cdnurl($value, true);
}
public static function allList($page, $limit,$params=[]){
$sort = "weigh desc,id desc";
// if(!empty($params['status'])){
// $params['status'] = '1';
// }
return (new self)->getBaseList($params, $page, $limit,$sort);
}
}