<?php declare (strict_types=1); namespace app\api\model\Server; use app\api\model\UploadFile; use app\common\model\server\RecoveryCategory as BaseRecoveryCategory; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use think\model\relation\HasOne; class RecoveryCategory extends BaseRecoveryCategory { /** * 隐藏字段 * @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']) ->where(['status' => 1]) ->order(['sort', 'create_time']) ->select() ->toArray(); } }