作者 赵彬吉

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

... ... @@ -10,11 +10,23 @@ class WebSettingHtmlController extends BaseController
{
/**
* @name :(获取并设置第三方代码)read
* @param :(head_html,body_html,footer_html)
* @author :lyh
* @method :post
* @time :2023/4/28 14:45
*/
public function save(WebSettingHtmlLogic $webSettingHtmlLogic){
if(isset($this->param) && !empty($this->param)){
$this->request->validate([
'head_html'=>'required',
'body_html'=>'required',
'footer_html'=>'required'
],[
'head_html.required' => 'head_html不能为空',
'body_html.required' => 'body_html不能为空',
'footer_html.required' => 'footer_html不能为空'
]);
}
$info = $webSettingHtmlLogic->setting_html_save();
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -26,6 +26,8 @@ class ImageController
];
public $path = '';
public $config = '';
public $thr_path = '';
public $request = '';
... ... @@ -33,7 +35,8 @@ class ImageController
public function __construct(Request $request)
{
$this->request = $request;
$this->path = config('filesystems.disks')['upload']['root'].config('upload');
$this->config = config('filesystems.disks.upload');
$this->path = $this->config['root'];
}
public function index($hash = '', $w = 0 ,$h = 0){
... ... @@ -105,25 +108,30 @@ class ImageController
*/
public function single($files){
$hash = hash_file('md5', $files->getPathname());
//查看文件是否存在
$imageModel = new ImageModel();
$image_hash = $imageModel->read(['hash'=>$hash]);
if($image_hash !== false){
return $hash;
}
$url = $this->path;
$filename = date('ymdHis').rand(10000,99999);
$res = $this->request->file('image')->move($url,$filename);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
$imageModel = new ImageModel();
$data = [
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $hash.$filename,
'hash' => $hash,
'type'=>$files->getClientOriginalExtension(),
];
$rs = $imageModel->add($data);
if ($rs === false) {
return $this->response('添加失败', Code::USER_ERROR);
}
return $hash.$filename;
return $hash;
}
/**
* 生成缩略图缓存
... ... @@ -151,7 +159,13 @@ class ImageController
$save_data = [];
$data = [];
foreach ($files as $file) {
$imageModel = new ImageModel();
$hash = hash_file('md5', $file->getPathname());
$image_hash = $imageModel->read(['hash'=>$hash]);
if($image_hash !== false){
$data[] = $hash;
continue;
}
$url = $this->path;
$filename = date('ymdHis').rand(10000,99999);
$res = $file->move($url,$filename);
... ... @@ -162,12 +176,11 @@ class ImageController
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $hash.$filename,
'hash' => $hash,
'type'=>$files->getClientOriginalExtension(),
];
$data[] = $hash.$filename;
$data[] = $hash;
}
$imageModel = new ImageModel();
$imageModel->insert($save_data);
return $data;
}
... ...
... ... @@ -5,7 +5,7 @@ namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Common;
use App\Http\Controllers\ImageLogic;
use App\Http\Controllers\ImageController;
use App\Http\Logic\Logic;
use App\Models\Image as ImageModel;
use Illuminate\Http\Request;
... ... @@ -99,8 +99,9 @@ class BaseLogic extends Logic
* @method
*/
public function upload(){
$imageLogic = new ImageLogic();
return $imageLogic->upload();
$image = new ImageController();
$hash = $image->upload();
return $hash;
}
/**
... ...
... ... @@ -37,6 +37,9 @@ class WebSettingHtmlLogic extends BaseLogic
$info = $this->param;
}else{
$info = $this->model->read(['project_id'=>$this->user['project_id']]);
if($info === false){
$info = [];
}
}
return $this->success($info);
}
... ...
... ... @@ -24,7 +24,7 @@ class WebSettingServiceLogic extends BaseLogic
* @time :2023/5/4 11:23
*/
public function setting_service_list(){
$list = $this->model->list(['project_id'=>$this->param['project_id']]);
$list = $this->model->list(['project_id'=>$this->user['project_id']],'created_at');
return $this->success($list);
}
... ... @@ -37,10 +37,9 @@ class WebSettingServiceLogic extends BaseLogic
public function setting_service_save(){
try {
//删除以前的数据
$param['project_id'] = ['in',$this->user['project_id']];
$param['project_id'] = $this->user['project_id'];
$this->model->del($param);
//新增
$this->model->add($this->param);
$this->model->add($this->param['data']);
}catch (\Exception $e){
$this->fail('error');
}
... ... @@ -62,8 +61,6 @@ class WebSettingServiceLogic extends BaseLogic
$info = $image->read(['hash'=>$this->param['hash']]);
if($info !== false){
$image->del(['id'=>$info['id']]);
//删除资源文件
shell_exec('rm -rf '.$info['path']);
}
DB::commit();
}catch (\Exception $e){
... ...
<?php
namespace App\Http\Controllers;
use App\Enums\Common\Code;
use App\Models\Image as ImageModel;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
class ImageLogic
{
public $path = '';
public $request = '';
public function __construct(Request $request)
{
$this->request = $request;
$this->path = config('filesystems.disks')['upload']['root'].config('upload');
}
/**
* 图片上传
*/
public function upload() {
$this->request->validate([
'image'=>['required'],
],[
'image.required'=>'图片必须填写',
]);
$files = $this->request->file('image');
if (empty($files)) {
$this->response('没有上传的文件!', 400);
}
$type = $this->request->post('type', 'single');
if ($type == 'multi') {
return $this->multi($files);
} else {
return $this->single($files);
}
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function single($files){
$hash = hash_file('md5', $files->getPathname());
$url = $this->path;
$filename = date('ymdHis').rand(10000,99999);
$res = $this->request->file('image')->move($url,$filename);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
$imageModel = new ImageModel();
$data = [
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $hash.$filename,
'type'=>$files->getClientOriginalExtension(),
];
$rs = $imageModel->add($data);
if ($rs === false) {
return $this->response('添加失败', Code::USER_ERROR);
}
return $hash.$filename;
}
/**
* @name :(删除资源及对应表数据)del
* @author :lyh
* @method :post
* @time :2023/5/4 14:57
*/
public function del($hash){
DB::beginTransaction();
$imageModel = new ImageModel();
try {
if(is_array($hash)){
foreach ($hash as $k => $v){
$this->del($v);
}
}else{
$info = $imageModel->read(['hash'=>$hash]);
if($info !== false){
shell_exec('sudo rm -rf '.$info['path']. ' '.$this->path . $info['hash'] .'*');
}
}
$imageModel->del(['hash'=>['in',$hash]]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->response('error',Code::USER_ERROR);
}
}
/**
* 生成缩略图缓存
* @param type $info
* @param type $w
* @param type $h
* @return string
*/
private function cacheImage($info, $w, $h) {
$path = $info['path'];
$filename = $this->path . $info['hash'] . $w . '_' . $h;
Image::make($path)->resize($w, $h)->save($filename);
return $filename;
}
/**
* 多图片上传
* @param type $files file对象集合
* @return type
*/
private function multi($files) {
if (!is_array($files)) {
$files = [$files];
}
$save_data = [];
$data = [];
foreach ($files as $file) {
$hash = hash_file('md5', $file->getPathname());
$url = $this->path;
$filename = date('ymdHis').rand(10000,99999);
$res = $file->move($url,$filename);
if ($res === false) {
return $this->response($file->getError(), Code::USER_ERROR);
}
$save_data[] = [
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $hash.$filename,
'type'=>$files->getClientOriginalExtension(),
];
$data[] = $hash.$filename;
}
$imageModel = new ImageModel();
$imageModel->insert($save_data);
return $data;
}
//下载
public function download($filename){
$path = Storage::path($filename);
return response()->download($path,time().rand(1,100000));
}
/**
* @name 统一返回参数
* @return JsonResponse
* @author :liyuhang
* @method
*/
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
$code = Code::fromValue($code);
$result = [
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $data,
];
$this->header['Content-Type'] = $type;
$response = response($result,$result_code,$this->header);
throw new HttpResponseException($response);
}
}
... ... @@ -85,7 +85,7 @@ class Base extends Model
* @author :liyuhang
* @method
*/
public function list($map,$order = 'id',$fields = ['*']): array
public function list($map,$order = 'sort',$fields = ['*']): array
{
$query = $this->formatQuery($map);
$lists = $query->select($fields)->orderBy($order)->get();
... ...