Browse Source

更换图片地址前缀,启用阿里云CDN

master
ahbmz 4 years ago
parent
commit
bfe77eddd0
  1. 37
      app/api/controller/Content.php
  2. BIN
      public/uploads/20221101/2ef8fcf3d44ad36e75d227d34accdefa.png
  3. BIN
      public/uploads/20221101/804ea1842bbdda00b59e97bd1456e712.png

37
app/api/controller/Content.php

@ -57,6 +57,7 @@ class Content extends Base
{ {
//广告 //广告
$_data['ad'] = Db::name('ad')->where('status', 1)->order('sort DESC,create_time DESC')->limit(6)->select(); $_data['ad'] = Db::name('ad')->where('status', 1)->order('sort DESC,create_time DESC')->limit(6)->select();
$_data['ad'] = $this->replace_img_http($_data['ad']->toArray());
//三个产品分类 //三个产品分类
$field = 'id,create_time,sort,status,cate_id,title,author,source,image'; $field = 'id,create_time,sort,status,cate_id,title,author,source,image';
$_data['yinshidapeng'] = Db::name('product')->where('cate_id', 9) $_data['yinshidapeng'] = Db::name('product')->where('cate_id', 9)
@ -67,6 +68,13 @@ class Content extends Base
->field($field)->order('sort DESC,create_time DESC')->limit(4)->select(); ->field($field)->order('sort DESC,create_time DESC')->limit(4)->select();
$_data['kepianxinshang'] = Db::name('product')->where('cate_id', 15) $_data['kepianxinshang'] = Db::name('product')->where('cate_id', 15)
->field($field)->order('sort DESC,create_time DESC')->limit(4)->select(); ->field($field)->order('sort DESC,create_time DESC')->limit(4)->select();
//替换CDN图片
$_data['yinshidapeng'] = $this->replace_img_http($_data['yinshidapeng']->toArray());
$_data['shijingpianchang'] = $this->replace_img_http($_data['shijingpianchang']->toArray());
$_data['peitaosheshi'] = $this->replace_img_http($_data['peitaosheshi']->toArray());
$_data['kepianxinshang'] = $this->replace_img_http($_data['kepianxinshang']->toArray());
return $this->result($_data, 1, ''); return $this->result($_data, 1, '');
} }
@ -85,7 +93,7 @@ class Content extends Base
{ {
//联系我们 //联系我们
$_data = Db::name('page')->where('id', 1)->field('content')->find(); $_data = Db::name('page')->where('id', 1)->field('content')->find();
$_data['content'] = strip_tags($_data['content']); $_data['content'] = $_data['content'];
// $_data['map'] = Db::name('page')->where('id', 1)->field('content')->find(); // $_data['map'] = Db::name('page')->where('id', 1)->field('content')->find();
$_system = Db::name('system')->where('id', 1)->find(); $_system = Db::name('system')->where('id', 1)->find();
$_data['address'] = $_system['address']; $_data['address'] = $_system['address'];
@ -137,6 +145,7 @@ class Content extends Base
$_data = $_db->where('cate_id', $cate_id)->field('id,image,cate_id,title') $_data = $_db->where('cate_id', $cate_id)->field('id,image,cate_id,title')
->where('status', 1) ->where('status', 1)
->page($page, $limit)->select(); ->page($page, $limit)->select();
$_data = $this->replace_img_http($_data->toArray());
return $this->result($_data, 1, ''); return $this->result($_data, 1, '');
} }
@ -161,10 +170,14 @@ class Content extends Base
//替换img 标签 //替换img 标签
// $_data['detail']['content'] = $this->replace_img_alt($_data['detail']['content']); // $_data['detail']['content'] = $this->replace_img_alt($_data['detail']['content']);
//$_data['detail']['content'] = str_ireplace('<img', '<image', $_data['detail']['content']); //$_data['detail']['content'] = str_ireplace('<img', '<image', $_data['detail']['content']);
//替换cdn前缀
$_data['detail']['content'] = $this->replace_img_http($_data['detail']['content']);
$_data['detail']['image'] = $this->replace_img_http($_data['detail']['image']);
$_cate = Db::name('cate')->where('id', $_data['detail']['cate_id'])->find(); $_cate = Db::name('cate')->where('id', $_data['detail']['cate_id'])->find();
$_data['detail']['source'] = $_cate['cate_name']; $_data['detail']['source'] = $_cate['cate_name'];
$_data['postion']= Db::name('product')->field('id,title,image')->limit(4) $_data['postion'] = Db::name('product')->field('id,title,image')->limit(4)
->order('sort DESC,create_time DESC')->select(); ->order('sort DESC,create_time DESC')->select();
$_data['postion'] = $this->replace_img_http($_data['postion']->toArray());
return $this->result($_data, 1, ''); return $this->result($_data, 1, '');
} }
@ -191,4 +204,24 @@ class Content extends Base
} }
private function replace_img_http($http = '')
{
if (empty($http)) {
return;
}
$find_url = 'https://api.junfei.iiixo.com/uploads';
$replace_url = 'http://cdn.junfei.iiixo.com';
if (is_array($http)) {
array_walk($http, function (&$v, $k) use ($find_url, $replace_url) {
$v['image'] = str_replace($find_url, $replace_url, $v['image']);
});
return $http;
}
$http = str_replace($find_url, $replace_url, $http);
return $http;
}
} }

BIN
public/uploads/20221101/2ef8fcf3d44ad36e75d227d34accdefa.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
public/uploads/20221101/804ea1842bbdda00b59e97bd1456e712.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Loading…
Cancel
Save