diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index 9e42ffe1..6f6dc629 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -36,15 +36,6 @@ class MaintenanceCategory extends BaseModel return static::get($categoryId); } - public function catImg(): HasOne - { - $module = self::getCalledModule(); - return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') - ->bind(['img_url' => 'preview_url']); - } - - - /** * 获取列表 * @param array $where @@ -55,7 +46,7 @@ class MaintenanceCategory extends BaseModel */ public function getList(array $where = []): \think\Collection { - return $this->where($where)->with(['catImg']) + return $this->where($where) ->order(['sort', $this->getPk()]) ->select(); } diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php index a3011868..a94dc005 100644 --- a/app/store/model/Maintenance.php +++ b/app/store/model/Maintenance.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\store\model; use app\common\model\Maintenance as MaintenanceModel; +use think\model\relation\HasOne; /** * 文章模型 @@ -41,7 +42,7 @@ class Maintenance extends MaintenanceModel $params['status'] > -1 && $filter[] = ['status', '=', $params['status']]; $params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']]; // 查询列表数据 - $data = $this->where($filter) + $data = $this->where($filter)->with(['catImg']) ->where('is_delete', '=', 0) ->order(['sort' => 'asc', 'create_time' => 'desc']) ->paginate(15); @@ -108,4 +109,11 @@ class Maintenance extends MaintenanceModel { return (new static)->where($where)->where('is_delete', '=', 0)->count(); } + + public function catImg(): HasOne + { + $module = self::getCalledModule(); + return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') + ->bind(['img_url' => 'preview_url']); + } }