Your Name 6 months ago
parent 9dbc48a80c
commit 00c1032162
  1. 40
      addons/alioss/controller/Index.php
  2. 36
      application/admin/command/UserLevel.php
  3. 4
      application/api/controller/Article.php
  4. 2
      application/api/controller/Company.php
  5. 4
      application/api/controller/Notice.php
  6. 1
      application/command.php
  7. 8
      application/common.php

@ -279,4 +279,44 @@ class Index extends Controller
}
}
/**
* 附件库图片同步阿里云OSS
*/
public function uploadLocalToOss()
{
$config = get_addon_config('alioss');
if ($config['uploadmode'] != 'server') {
$this->error("无需执行该操作");
}
if (!$config['accessKeyId'] || !$config['accessKeySecret']) {
$this->error("请先配置好阿里云OSS");
}
if (!class_exists('\OSS\OssClient')) {
$this->error("请安装composer require symfony/polyfill-php72");
}
$oss = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']);
$attachments = Attachment::where('storage', 'local')
->where('createtime', '>', '1711610369')->select();
$i = 1;
foreach ($attachments as $attachment) {
$filePath = ROOT_PATH . 'public' . $attachment->url;
// var_dump($filePath);
try {
// var_dump($config);
$ret = $oss->uploadFile($config['bucket'], ltrim($attachment->url, "/"), $filePath);
sleep(1);
$i++;
//成功不做任何操作
} catch (\Exception $e) {
\think\Log::write($e->getMessage());
$this->error($e->getMessage());
}
}
$this->success("同步成功 {$i}条数据");
}
}

@ -4,6 +4,8 @@ namespace app\admin\command;
use app\admin\model\AuthRule;
use app\admin\model\User;
use app\common\model\Attachment;
use OSS\OssClient;
use ReflectionClass;
use ReflectionMethod;
use think\Cache;
@ -32,8 +34,40 @@ class UserLevel extends Command
protected function execute(Input $input, Output $output)
{
$config = get_addon_config('alioss');
if ($config['uploadmode'] != 'server') {
throw new Exception("无需执行该操作");
}
if (!$config['accessKeyId'] || !$config['accessKeySecret']) {
throw new Exception("请先配置好阿里云OSS");
}
if (!class_exists('\OSS\OssClient')) {
throw new Exception("请安装composer require symfony/polyfill-php72");
}
$oss = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']);
$attachments = Attachment::where('storage', 'local')
->where('createtime', '>', '1711610369')->select();
$i = 1;
foreach ($attachments as $attachment) {
$filePath = ROOT_PATH . 'public' . $attachment->url;
// var_dump($filePath);
try {
echo $filePath.PHP_EOL;
$ret = $oss->uploadFile($config['bucket'], ltrim($attachment->url, "/"), $filePath);
var_dump($ret);
sleep(1);
$i++;
//成功不做任何操作
} catch (\Exception $e) {
\think\Log::write($e->getMessage());
throw new Exception($e->getMessage());
}
}
$output->info("同步成功 {$i}条数据");
$output->info("Build Successed!");
}
/**

@ -27,7 +27,7 @@ class Article extends Api
->paginate();
foreach ($list as &$row) {
$row['image'] = $this->request->domain().$row['image'];
$row['image'] = formatImage($row['image']);
}
$this->success('营销配置', $list);
}
@ -41,7 +41,7 @@ class Article extends Api
->where('status', 1)
->where('id', $id)
->find();
$detail['image'] = $this->request->domain().$detail['image'];
$detail['image'] = formatImage($detail['image']);
$this->success('success', $detail);
}
}

@ -20,7 +20,7 @@ class Company extends Api
public function list() {
$list = $this->model->where('status', 1)->paginate(10);
foreach ($list as &$row) {
$row['image'] = $this->request->domain().$row['image'];
$row['image'] = formatImage($row['image']);
}
$this->success('资质列表', $list);
}

@ -18,7 +18,7 @@ class Notice extends Api {
public function list() {
$list = $this->model->where('status', 1)->paginate(10);
foreach ($list as &$row) {
$row['image'] = $this->request->domain().$row['image'];
$row['image'] = formatImage($row['image']);
}
$this->success('公告列表', $list);
}
@ -32,7 +32,7 @@ class Notice extends Api {
->where('status', 1)
->where('id', $id)
->find();
$detail['image'] = $this->request->domain().$detail['image'];
$detail['image'] = formatImage($detail['image']);
$this->success('success', $detail);
}
}

@ -17,4 +17,5 @@ return [
'app\admin\command\Min',
'app\admin\command\Addon',
'app\admin\command\Api',
'app\admin\command\UserLevel',
];

@ -562,7 +562,13 @@ EOT;
}
function formatImage($url) {
return request()->domain().$url;
$config = get_addon_config('alioss');
if ($config['apiupload'] == 1) {
$url = $config['cdnurl'] . $url;
} else {
$url = request()->domain().$url;
}
return $url;
}
function dd($data) {

Loading…
Cancel
Save