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.
yanzong/app/api/model/Server/ServerCategory.php

51 lines
1.1 KiB

<?php
namespace app\api\model\Server;
use app\api\model\UploadFile;
use app\common\model\ServerCategory as BaseServerCategory;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\HasOne;
class ServerCategory extends BaseServerCategory
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'store_id',
'create_time',
'update_time',
'status',
'image_id',
];
/**
* 分类图片
* @return HasOne
*/
public function image(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'image_id')
->bind(['image_url' => 'preview_url']);
}
/**
* @notes:获取全部记录
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function list(): array
{
return $this->with(['image'])
->order(['sort', 'create_time'])
->select()
->toArray();
}
}