作者 赵彬吉

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

@@ -10,11 +10,23 @@ class WebSettingHtmlController extends BaseController @@ -10,11 +10,23 @@ class WebSettingHtmlController extends BaseController
10 { 10 {
11 /** 11 /**
12 * @name :(获取并设置第三方代码)read 12 * @name :(获取并设置第三方代码)read
  13 + * @param :(head_html,body_html,footer_html)
13 * @author :lyh 14 * @author :lyh
14 * @method :post 15 * @method :post
15 * @time :2023/4/28 14:45 16 * @time :2023/4/28 14:45
16 */ 17 */
17 public function save(WebSettingHtmlLogic $webSettingHtmlLogic){ 18 public function save(WebSettingHtmlLogic $webSettingHtmlLogic){
  19 + if(isset($this->param) && !empty($this->param)){
  20 + $this->request->validate([
  21 + 'head_html'=>'required',
  22 + 'body_html'=>'required',
  23 + 'footer_html'=>'required'
  24 + ],[
  25 + 'head_html.required' => 'head_html不能为空',
  26 + 'body_html.required' => 'body_html不能为空',
  27 + 'footer_html.required' => 'footer_html不能为空'
  28 + ]);
  29 + }
18 $info = $webSettingHtmlLogic->setting_html_save(); 30 $info = $webSettingHtmlLogic->setting_html_save();
19 $this->response('success',Code::SUCCESS,$info); 31 $this->response('success',Code::SUCCESS,$info);
20 } 32 }
@@ -26,6 +26,8 @@ class ImageController @@ -26,6 +26,8 @@ class ImageController
26 ]; 26 ];
27 public $path = ''; 27 public $path = '';
28 28
  29 + public $config = '';
  30 +
29 public $thr_path = ''; 31 public $thr_path = '';
30 32
31 public $request = ''; 33 public $request = '';
@@ -33,7 +35,8 @@ class ImageController @@ -33,7 +35,8 @@ class ImageController
33 public function __construct(Request $request) 35 public function __construct(Request $request)
34 { 36 {
35 $this->request = $request; 37 $this->request = $request;
36 - $this->path = config('filesystems.disks')['upload']['root'].config('upload'); 38 + $this->config = config('filesystems.disks.upload');
  39 + $this->path = $this->config['root'];
37 } 40 }
38 41
39 public function index($hash = '', $w = 0 ,$h = 0){ 42 public function index($hash = '', $w = 0 ,$h = 0){
@@ -105,25 +108,30 @@ class ImageController @@ -105,25 +108,30 @@ class ImageController
105 */ 108 */
106 public function single($files){ 109 public function single($files){
107 $hash = hash_file('md5', $files->getPathname()); 110 $hash = hash_file('md5', $files->getPathname());
  111 + //查看文件是否存在
  112 + $imageModel = new ImageModel();
  113 + $image_hash = $imageModel->read(['hash'=>$hash]);
  114 + if($image_hash !== false){
  115 + return $hash;
  116 + }
108 $url = $this->path; 117 $url = $this->path;
109 $filename = date('ymdHis').rand(10000,99999); 118 $filename = date('ymdHis').rand(10000,99999);
110 $res = $this->request->file('image')->move($url,$filename); 119 $res = $this->request->file('image')->move($url,$filename);
111 if ($res === false) { 120 if ($res === false) {
112 return $this->response($files->getError(), Code::USER_ERROR); 121 return $this->response($files->getError(), Code::USER_ERROR);
113 } 122 }
114 - $imageModel = new ImageModel();  
115 $data = [ 123 $data = [
116 'path' => $url.$filename, 124 'path' => $url.$filename,
117 'created_at' => date('Y-m-d H:i:s',time()), 125 'created_at' => date('Y-m-d H:i:s',time()),
118 'size' => $res->getSize(), 126 'size' => $res->getSize(),
119 - 'hash' => $hash.$filename, 127 + 'hash' => $hash,
120 'type'=>$files->getClientOriginalExtension(), 128 'type'=>$files->getClientOriginalExtension(),
121 ]; 129 ];
122 $rs = $imageModel->add($data); 130 $rs = $imageModel->add($data);
123 if ($rs === false) { 131 if ($rs === false) {
124 return $this->response('添加失败', Code::USER_ERROR); 132 return $this->response('添加失败', Code::USER_ERROR);
125 } 133 }
126 - return $hash.$filename; 134 + return $hash;
127 } 135 }
128 /** 136 /**
129 * 生成缩略图缓存 137 * 生成缩略图缓存
@@ -151,7 +159,13 @@ class ImageController @@ -151,7 +159,13 @@ class ImageController
151 $save_data = []; 159 $save_data = [];
152 $data = []; 160 $data = [];
153 foreach ($files as $file) { 161 foreach ($files as $file) {
  162 + $imageModel = new ImageModel();
154 $hash = hash_file('md5', $file->getPathname()); 163 $hash = hash_file('md5', $file->getPathname());
  164 + $image_hash = $imageModel->read(['hash'=>$hash]);
  165 + if($image_hash !== false){
  166 + $data[] = $hash;
  167 + continue;
  168 + }
155 $url = $this->path; 169 $url = $this->path;
156 $filename = date('ymdHis').rand(10000,99999); 170 $filename = date('ymdHis').rand(10000,99999);
157 $res = $file->move($url,$filename); 171 $res = $file->move($url,$filename);
@@ -162,12 +176,11 @@ class ImageController @@ -162,12 +176,11 @@ class ImageController
162 'path' => $url.$filename, 176 'path' => $url.$filename,
163 'created_at' => date('Y-m-d H:i:s',time()), 177 'created_at' => date('Y-m-d H:i:s',time()),
164 'size' => $res->getSize(), 178 'size' => $res->getSize(),
165 - 'hash' => $hash.$filename, 179 + 'hash' => $hash,
166 'type'=>$files->getClientOriginalExtension(), 180 'type'=>$files->getClientOriginalExtension(),
167 ]; 181 ];
168 - $data[] = $hash.$filename; 182 + $data[] = $hash;
169 } 183 }
170 - $imageModel = new ImageModel();  
171 $imageModel->insert($save_data); 184 $imageModel->insert($save_data);
172 return $data; 185 return $data;
173 } 186 }
@@ -5,7 +5,7 @@ namespace App\Http\Logic\Bside; @@ -5,7 +5,7 @@ namespace App\Http\Logic\Bside;
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Exceptions\BsideGlobalException; 6 use App\Exceptions\BsideGlobalException;
7 use App\Helper\Common; 7 use App\Helper\Common;
8 -use App\Http\Controllers\ImageLogic; 8 +use App\Http\Controllers\ImageController;
9 use App\Http\Logic\Logic; 9 use App\Http\Logic\Logic;
10 use App\Models\Image as ImageModel; 10 use App\Models\Image as ImageModel;
11 use Illuminate\Http\Request; 11 use Illuminate\Http\Request;
@@ -99,8 +99,9 @@ class BaseLogic extends Logic @@ -99,8 +99,9 @@ class BaseLogic extends Logic
99 * @method 99 * @method
100 */ 100 */
101 public function upload(){ 101 public function upload(){
102 - $imageLogic = new ImageLogic();  
103 - return $imageLogic->upload(); 102 + $image = new ImageController();
  103 + $hash = $image->upload();
  104 + return $hash;
104 } 105 }
105 106
106 /** 107 /**
@@ -37,6 +37,9 @@ class WebSettingHtmlLogic extends BaseLogic @@ -37,6 +37,9 @@ class WebSettingHtmlLogic extends BaseLogic
37 $info = $this->param; 37 $info = $this->param;
38 }else{ 38 }else{
39 $info = $this->model->read(['project_id'=>$this->user['project_id']]); 39 $info = $this->model->read(['project_id'=>$this->user['project_id']]);
  40 + if($info === false){
  41 + $info = [];
  42 + }
40 } 43 }
41 return $this->success($info); 44 return $this->success($info);
42 } 45 }
@@ -24,7 +24,7 @@ class WebSettingServiceLogic extends BaseLogic @@ -24,7 +24,7 @@ class WebSettingServiceLogic extends BaseLogic
24 * @time :2023/5/4 11:23 24 * @time :2023/5/4 11:23
25 */ 25 */
26 public function setting_service_list(){ 26 public function setting_service_list(){
27 - $list = $this->model->list(['project_id'=>$this->param['project_id']]); 27 + $list = $this->model->list(['project_id'=>$this->user['project_id']],'created_at');
28 return $this->success($list); 28 return $this->success($list);
29 } 29 }
30 30
@@ -37,10 +37,9 @@ class WebSettingServiceLogic extends BaseLogic @@ -37,10 +37,9 @@ class WebSettingServiceLogic extends BaseLogic
37 public function setting_service_save(){ 37 public function setting_service_save(){
38 try { 38 try {
39 //删除以前的数据 39 //删除以前的数据
40 - $param['project_id'] = ['in',$this->user['project_id']]; 40 + $param['project_id'] = $this->user['project_id'];
41 $this->model->del($param); 41 $this->model->del($param);
42 - //新增  
43 - $this->model->add($this->param); 42 + $this->model->add($this->param['data']);
44 }catch (\Exception $e){ 43 }catch (\Exception $e){
45 $this->fail('error'); 44 $this->fail('error');
46 } 45 }
@@ -62,8 +61,6 @@ class WebSettingServiceLogic extends BaseLogic @@ -62,8 +61,6 @@ class WebSettingServiceLogic extends BaseLogic
62 $info = $image->read(['hash'=>$this->param['hash']]); 61 $info = $image->read(['hash'=>$this->param['hash']]);
63 if($info !== false){ 62 if($info !== false){
64 $image->del(['id'=>$info['id']]); 63 $image->del(['id'=>$info['id']]);
65 - //删除资源文件  
66 - shell_exec('rm -rf '.$info['path']);  
67 } 64 }
68 DB::commit(); 65 DB::commit();
69 }catch (\Exception $e){ 66 }catch (\Exception $e){
1 -<?php  
2 -  
3 -namespace App\Http\Controllers;  
4 -  
5 -use App\Enums\Common\Code;  
6 -use App\Models\Image as ImageModel;  
7 -use Illuminate\Http\Exceptions\HttpResponseException;  
8 -use Illuminate\Http\JsonResponse;  
9 -use Illuminate\Http\Request;  
10 -use Illuminate\Support\Facades\DB;  
11 -use Illuminate\Support\Facades\Storage;  
12 -use Intervention\Image\Facades\Image;  
13 -  
14 -class ImageLogic  
15 -{  
16 - public $path = '';  
17 -  
18 - public $request = '';  
19 -  
20 - public function __construct(Request $request)  
21 - {  
22 - $this->request = $request;  
23 - $this->path = config('filesystems.disks')['upload']['root'].config('upload');  
24 - }  
25 -  
26 - /**  
27 - * 图片上传  
28 - */  
29 - public function upload() {  
30 - $this->request->validate([  
31 - 'image'=>['required'],  
32 - ],[  
33 - 'image.required'=>'图片必须填写',  
34 - ]);  
35 - $files = $this->request->file('image');  
36 - if (empty($files)) {  
37 - $this->response('没有上传的文件!', 400);  
38 - }  
39 - $type = $this->request->post('type', 'single');  
40 - if ($type == 'multi') {  
41 - return $this->multi($files);  
42 - } else {  
43 - return $this->single($files);  
44 - }  
45 - }  
46 - /**  
47 - * @name :上传图片  
48 - * @return void  
49 - * @author :liyuhang  
50 - * @method  
51 - */  
52 - public function single($files){  
53 - $hash = hash_file('md5', $files->getPathname());  
54 - $url = $this->path;  
55 - $filename = date('ymdHis').rand(10000,99999);  
56 - $res = $this->request->file('image')->move($url,$filename);  
57 - if ($res === false) {  
58 - return $this->response($files->getError(), Code::USER_ERROR);  
59 - }  
60 - $imageModel = new ImageModel();  
61 - $data = [  
62 - 'path' => $url.$filename,  
63 - 'created_at' => date('Y-m-d H:i:s',time()),  
64 - 'size' => $res->getSize(),  
65 - 'hash' => $hash.$filename,  
66 - 'type'=>$files->getClientOriginalExtension(),  
67 - ];  
68 - $rs = $imageModel->add($data);  
69 - if ($rs === false) {  
70 - return $this->response('添加失败', Code::USER_ERROR);  
71 - }  
72 - return $hash.$filename;  
73 - }  
74 -  
75 - /**  
76 - * @name :(删除资源及对应表数据)del  
77 - * @author :lyh  
78 - * @method :post  
79 - * @time :2023/5/4 14:57  
80 - */  
81 - public function del($hash){  
82 - DB::beginTransaction();  
83 - $imageModel = new ImageModel();  
84 - try {  
85 - if(is_array($hash)){  
86 - foreach ($hash as $k => $v){  
87 - $this->del($v);  
88 - }  
89 - }else{  
90 - $info = $imageModel->read(['hash'=>$hash]);  
91 - if($info !== false){  
92 - shell_exec('sudo rm -rf '.$info['path']. ' '.$this->path . $info['hash'] .'*');  
93 - }  
94 - }  
95 - $imageModel->del(['hash'=>['in',$hash]]);  
96 - DB::commit();  
97 - }catch (\Exception $e){  
98 - DB::rollBack();  
99 - $this->response('error',Code::USER_ERROR);  
100 - }  
101 - }  
102 - /**  
103 - * 生成缩略图缓存  
104 - * @param type $info  
105 - * @param type $w  
106 - * @param type $h  
107 - * @return string  
108 - */  
109 - private function cacheImage($info, $w, $h) {  
110 - $path = $info['path'];  
111 - $filename = $this->path . $info['hash'] . $w . '_' . $h;  
112 - Image::make($path)->resize($w, $h)->save($filename);  
113 - return $filename;  
114 - }  
115 -  
116 - /**  
117 - * 多图片上传  
118 - * @param type $files file对象集合  
119 - * @return type  
120 - */  
121 - private function multi($files) {  
122 - if (!is_array($files)) {  
123 - $files = [$files];  
124 - }  
125 - $save_data = [];  
126 - $data = [];  
127 - foreach ($files as $file) {  
128 - $hash = hash_file('md5', $file->getPathname());  
129 - $url = $this->path;  
130 - $filename = date('ymdHis').rand(10000,99999);  
131 - $res = $file->move($url,$filename);  
132 - if ($res === false) {  
133 - return $this->response($file->getError(), Code::USER_ERROR);  
134 - }  
135 - $save_data[] = [  
136 - 'path' => $url.$filename,  
137 - 'created_at' => date('Y-m-d H:i:s',time()),  
138 - 'size' => $res->getSize(),  
139 - 'hash' => $hash.$filename,  
140 - 'type'=>$files->getClientOriginalExtension(),  
141 - ];  
142 - $data[] = $hash.$filename;  
143 - }  
144 - $imageModel = new ImageModel();  
145 - $imageModel->insert($save_data);  
146 - return $data;  
147 - }  
148 -  
149 - //下载  
150 - public function download($filename){  
151 - $path = Storage::path($filename);  
152 - return response()->download($path,time().rand(1,100000));  
153 - }  
154 - /**  
155 - * @name 统一返回参数  
156 - * @return JsonResponse  
157 - * @author :liyuhang  
158 - * @method  
159 - */  
160 - public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse  
161 - {  
162 - $code = Code::fromValue($code);  
163 - $result = [  
164 - 'msg' => $msg == ' ' ? $code->description : $msg,  
165 - 'code' => $code->value,  
166 - 'data' => $data,  
167 - ];  
168 - $this->header['Content-Type'] = $type;  
169 - $response = response($result,$result_code,$this->header);  
170 - throw new HttpResponseException($response);  
171 - }  
172 -}  
@@ -85,7 +85,7 @@ class Base extends Model @@ -85,7 +85,7 @@ class Base extends Model
85 * @author :liyuhang 85 * @author :liyuhang
86 * @method 86 * @method
87 */ 87 */
88 - public function list($map,$order = 'id',$fields = ['*']): array 88 + public function list($map,$order = 'sort',$fields = ['*']): array
89 { 89 {
90 $query = $this->formatQuery($map); 90 $query = $this->formatQuery($map);
91 $lists = $query->select($fields)->orderBy($order)->get(); 91 $lists = $query->select($fields)->orderBy($order)->get();