后台-图片处理

wxl
674780036@qq.com 9 months ago
parent 2c11f483e6
commit 875a131332
  1. 20
      app/common/model/ActiveMain.php
  2. 23
      app/store/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']);
}
}

@ -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;
}

Loading…
Cancel
Save