diff --git a/app/common/model/Maintenance.php b/app/common/model/Maintenance.php index 9597d4a3..b3de56d4 100644 --- a/app/common/model/Maintenance.php +++ b/app/common/model/Maintenance.php @@ -14,6 +14,7 @@ namespace app\common\model; use cores\BaseModel; use think\model\relation\BelongsTo; +use think\model\relation\HasOne; /** * 文件库分组模型 @@ -36,4 +37,11 @@ class Maintenance extends BaseModel $module = self::getCalledModule(); return $this->BelongsTo("app\\{$module}\\model\\MaintenanceCategory", 'category_id'); } + + public function catImg(): HasOne + { + $module = self::getCalledModule(); + return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') + ->bind(['img_url' => 'preview_url']); + } } diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index a8d750cf..357ea6cf 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -47,7 +47,7 @@ class MaintenanceCategory extends BaseModel public function getList(array $where = []): \think\Collection { return $this->where($where) - ->with(['maintenances']) + ->with(['maintenances.catImg']) ->order(['sort', $this->getPk()]) ->select(); } diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php index a94dc005..0dd57317 100644 --- a/app/store/model/Maintenance.php +++ b/app/store/model/Maintenance.php @@ -109,11 +109,4 @@ 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']); - } }