From f4463a951c70695cabf76dd6accb769dd584e9fd Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Tue, 27 Feb 2024 22:01:07 +0800 Subject: [PATCH] 1 --- app/api/model/ActiveCol.php | 8 ++++++++ app/api/model/ActiveMain.php | 4 ++-- app/common/model/ActiveCol.php | 9 +++++++++ app/common/model/ActiveMain.php | 4 ++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/api/model/ActiveCol.php b/app/api/model/ActiveCol.php index 51bfa851..3d420357 100644 --- a/app/api/model/ActiveCol.php +++ b/app/api/model/ActiveCol.php @@ -20,7 +20,15 @@ use app\common\model\ActiveCol as ActiveColModel; */ class ActiveCol extends ActiveColModel { + //追加字段 + protected $append = [ + 'col_pic' + ]; + public function getColPicAttr($value, $data) { + $file = $this->with(['colImage'])->find(); + return $file['col_image_url']; + } } diff --git a/app/api/model/ActiveMain.php b/app/api/model/ActiveMain.php index 4934e2d1..8e07748e 100644 --- a/app/api/model/ActiveMain.php +++ b/app/api/model/ActiveMain.php @@ -42,11 +42,11 @@ class ActiveMain extends ActiveMainModel public function getIndexIconAttr($value, $data) { $file = $this->with('indexImage')->find(); - return $file['indexImage']['preview_url']; + return $file['index_image_url']; } public function getThemePicAttr($value, $data) { $file = $this->with('themeImage')->find(); - return $file['themeImage']['preview_url']; + return $file['theme_image_url']; } } diff --git a/app/common/model/ActiveCol.php b/app/common/model/ActiveCol.php index f5a0af0d..ca843b50 100644 --- a/app/common/model/ActiveCol.php +++ b/app/common/model/ActiveCol.php @@ -28,5 +28,14 @@ class ActiveCol extends BaseModel // 定义主键 protected $pk = 'id'; + /** + * col_image关联 + * @return HasOne + */ + public function colImage(): HasOne + { + return $this->hasOne('UploadFile', 'file_id', 'col_image_id') + ->bind(['col_image_url' => 'preview_url']); + } } diff --git a/app/common/model/ActiveMain.php b/app/common/model/ActiveMain.php index 39df29fc..8523ddd4 100644 --- a/app/common/model/ActiveMain.php +++ b/app/common/model/ActiveMain.php @@ -46,7 +46,7 @@ class ActiveMain extends BaseModel public function indexImage(): HasOne { return $this->hasOne('UploadFile', 'file_id', 'index_image_id') - ->bind(['image_url' => 'preview_url']); + ->bind(['index_image_url' => 'preview_url']); } /** @@ -56,7 +56,7 @@ class ActiveMain extends BaseModel public function themeImage(): HasOne { return $this->hasOne('UploadFile', 'file_id', 'theme_image_id') - ->bind(['image_url' => 'preview_url']); + ->bind(['theme_image_url' => 'preview_url']); } }