作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -73,7 +73,7 @@ class ProjectImport extends Command
$project = ProjectServer::useProject($task->project_id);
if ($project) {
foreach ($line_of_text as $k => $v) {
if ($k > 0 && $v) {
if ($k > 0 && $v[0]) {
$total_count += 1;
if ($task->type == ImportTask::TYPE_NEWS) {
if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) {
... ...
... ... @@ -316,22 +316,4 @@ class FileController
$data = ['file_download'=>url('a/download_files?path='.$info['path'])];
$this->response('success',Code::SUCCESS,$data);
}
/**
* 根据远程图片地址上传
* @param $file_url
* @return JsonResponse
* @author Akun
* @date 2023/09/21 9:40
*/
public function upRemoteUrl($file_url){
$ext = explode('.',$file_url);
$fileName = uniqid().rand(10000,99999).'.'.end($ext);
//同步数据到cos
$cosService = new CosService();
$cosService->uploadRemote($file_url,$this->path,$fileName);
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
}
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use Illuminate\Support\Facades\DB;
use mysql_xdevapi\Exception;
... ... @@ -269,31 +270,31 @@ class NewsLogic extends BaseLogic
public function importNews($project_id, $user_id, $data)
{
$category_id = '';
if (!empty($data[2])) {
if ($data[2]) {
//处理分类
$newsCategoryLogic = new NewsCategoryLogic();
$category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
}
$news = $this->model->read(['name'=>$data[0]]);
if(!$news){
$news = $this->model->read(['name' => $data[0]]);
if (!$news) {
$id = $this->model->addReturnId(
[
'name' => $data[0],
'category_id' => $category_id,
'text' => $data[4],
'remark' => $data[3],
'image' => '',//TODO: 远程图片下载本地
'seo_title' => $data[6],
'seo_keywords' => $data[7],
'seo_description' => $data[8],
'text' => $data[4] ?? '',
'remark' => $data[3] ?? '',
'image' => $data['5'] ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : '',
'seo_title' => $data[6] ?? '',
'seo_keywords' => $data[7] ?? '',
'seo_description' => $data[8] ?? '',
'project_id' => $project_id,
'operator_id' => $user_id,
'create_id' => $user_id
]
);
//更新路由
$route = RouteMap::setRoute($data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
$route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
$this->edit(['url' => $route], ['id' => $id]);
return true;
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Services;
use App\Utils\LogUtils;
use Qcloud\Cos\Client;
/**
* @remark :对象存储cos
... ... @@ -64,15 +65,21 @@ class CosService
/**
* 根据远程图片地址上传
* @param $project_id
* @param $image_type
* @param $file_url
* @param $path
* @param $filename
* @return string
* @author Akun
* @date 2023/09/21 9:39
*/
public function uploadRemote($file_url,$path,$filename)
public static function uploadRemote($project_id,$image_type,$file_url)
{
$ext = explode('.',$file_url);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
$uploads = config('upload.default_file');
$path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
'region' => $cos['region'],
... ... @@ -82,11 +89,16 @@ class CosService
],
]);
$key = $path.'/'.$filename;
$cosClient->putObject([
'Bucket' => $cos['bucket'],
'Key' => $key,
'Body' => fopen($file_url, 'r'),
]);
try {
$cosClient->putObject([
'Bucket' => $cos['bucket'],
'Key' => $key,
'Body' => fopen($file_url, 'r'),
]);
}catch (\Exception $e){
LogUtils::error('uploadRemote error', $e->getMessage());
}
return $key;
}
... ...
... ... @@ -363,6 +363,4 @@ Route::group([], function () {
Route::any('/qrcode', [\App\Http\Controllers\Bside\LoginController::class, 'qrcode'])->name('qrcode');
Route::any('/globalSo_v6_login', [\App\Http\Controllers\Bside\LoginController::class, 'globalSo_v6_login'])->name('globalSo_v6_login');
Route::any('/getWechatLoginInfo', [\App\Http\Controllers\Bside\LoginController::class, 'getWechatLoginInfo'])->name('getWechatLoginInfo');
Route::post('/upload_remote', [\App\Http\Controllers\File\FileController::class, 'upRemoteUrl'])->name('remote_file_upload');
});
... ...