From 875a131332002baa81cd5d15460d0eabacd95eb4 Mon Sep 17 00:00:00 2001 From: "674780036@qq.com" <674780036@qq.com> Date: Tue, 27 Feb 2024 14:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0-=E5=9B=BE=E7=89=87=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/ActiveMain.php | 20 ++++++++++++++++++++ app/store/model/ActiveMain.php | 23 +---------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/common/model/ActiveMain.php b/app/common/model/ActiveMain.php index 19dc3101..39df29fc 100644 --- a/app/common/model/ActiveMain.php +++ b/app/common/model/ActiveMain.php @@ -39,4 +39,24 @@ class ActiveMain extends BaseModel return $this->hasMany('activeCol', 'active_id', 'id'); } + /** + * icon_image关联 + * @return HasOne + */ + public function indexImage(): HasOne + { + return $this->hasOne('UploadFile', 'file_id', 'index_image_id') + ->bind(['image_url' => 'preview_url']); + } + + /** + * index_image关联 + * @return HasOne + */ + public function themeImage(): HasOne + { + return $this->hasOne('UploadFile', 'file_id', 'theme_image_id') + ->bind(['image_url' => 'preview_url']); + } + } diff --git a/app/store/model/ActiveMain.php b/app/store/model/ActiveMain.php index 4bd5d92f..9384ee55 100644 --- a/app/store/model/ActiveMain.php +++ b/app/store/model/ActiveMain.php @@ -24,15 +24,6 @@ use think\model\relation\HasOne; */ class ActiveMain extends ActiveMainModal { - /** - * 关联图片 - * @return HasOne - */ - public function index_icon_image(): HasOne - { - return $this->hasOne('UploadFile', 'file_id', 'index_icon') - ->bind(['image_url' => 'preview_url']); - } /** * 获取列表记录 @@ -42,19 +33,7 @@ class ActiveMain extends ActiveMainModal public function getList(): \think\Paginator { $data = $this->paginate(); - - foreach ($data as &$item) { - $index_icon_image_ids = UploadFile::whereIn('file_id', explode(",", $item['index_icon']))->field('file_id,file_path,file_type,storage,domain')->select()->toArray(); - foreach ($index_icon_image_ids as &$index_icon_image_id) { - $index_icon_image_id['file_path'] = getUrl($index_icon_image_id['file_path'], $index_icon_image_id['domain']); - } - $item['index_icons'] =$index_icon_image_ids ?? []; - $theme_pic_image_ids = UploadFile::whereIn('file_id', explode(",", $item['theme_pic']))->field('file_id,file_path,file_type,storage,domain')->select()->toArray(); - foreach ($theme_pic_image_ids as &$theme_pic_image_id) { - $theme_pic_image_id['file_path'] = getUrl($theme_pic_image_id['file_path'], $theme_pic_image_id['domain']); - } - $item['theme_pics'] =$theme_pic_image_ids ?? []; - } + $data = self::preload($data, ['indexImage','themeImage']); return $data; }