作者 赵彬吉

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

1 -APP_NAME=Laravel  
2 -APP_ENV=test  
3 -APP_KEY=base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow=  
4 -APP_DEBUG=false  
5 -APP_URL=http://localhost  
6 -  
7 -LOG_CHANNEL=stack  
8 -LOG_DEPRECATIONS_CHANNEL=null  
9 -LOG_LEVEL=debug  
10 -  
11 -DB_CONNECTION=mysql  
12 -DB_HOST=127.0.0.1  
13 -DB_PORT=3306  
14 -DB_DATABASE=globalso  
15 -DB_USERNAME=debian-sys-maint  
16 -DB_PASSWORD=WtujxV73XIclQet0  
17 -  
18 -BROADCAST_DRIVER=log  
19 -CACHE_DRIVER=file  
20 -FILESYSTEM_DRIVER=local  
21 -QUEUE_CONNECTION=sync  
22 -SESSION_DRIVER=file  
23 -SESSION_LIFETIME=120  
24 -  
25 -MEMCACHED_HOST=127.0.0.1  
26 -  
27 -REDIS_HOST=127.0.0.1  
28 -REDIS_PASSWORD=null  
29 -REDIS_PORT=6379  
30 -  
31 -MAIL_MAILER=smtp  
32 -MAIL_HOST=mailhog  
33 -MAIL_PORT=1025  
34 -MAIL_USERNAME=null  
35 -MAIL_PASSWORD=null  
36 -MAIL_ENCRYPTION=null  
37 -MAIL_FROM_ADDRESS=null  
38 -MAIL_FROM_NAME="${APP_NAME}"  
39 -  
40 -AWS_ACCESS_KEY_ID=  
41 -AWS_SECRET_ACCESS_KEY=  
42 -AWS_DEFAULT_REGION=us-east-1  
43 -AWS_BUCKET=  
44 -AWS_USE_PATH_STYLE_ENDPOINT=false  
45 -  
46 -PUSHER_APP_ID=  
47 -PUSHER_APP_KEY=  
48 -PUSHER_APP_SECRET=  
49 -PUSHER_APP_CLUSTER=mt1  
50 -  
51 -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"  
52 -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"  
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Http\Controllers\Aside; 3 namespace App\Http\Controllers\Aside;
4 4
  5 +use App\Enums\Common\Code;
5 use App\Http\Controllers\Bside\BaseController; 6 use App\Http\Controllers\Bside\BaseController;
6 7
7 use App\Models\Project as ProjectModel; 8 use App\Models\Project as ProjectModel;
@@ -20,6 +21,16 @@ class ProjectController extends BaseController @@ -20,6 +21,16 @@ class ProjectController extends BaseController
20 public function lists(){ 21 public function lists(){
21 $projectModel = new ProjectModel(); 22 $projectModel = new ProjectModel();
22 $lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order); 23 $lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order);
23 - $this->result($lists); 24 + $this->response('success',Code::SUCCESS,$lists);
  25 + }
  26 +
  27 + /**
  28 + * @name :添加项目
  29 + * @return void
  30 + * @author :liyuhang
  31 + * @method
  32 + */
  33 + public function add(){
  34 + $projectModel = new ProjectModel();
24 } 35 }
25 } 36 }
@@ -158,7 +158,7 @@ class BaseController extends Controller @@ -158,7 +158,7 @@ class BaseController extends Controller
158 } 158 }
159 switch ((string) $k) { 159 switch ((string) $k) {
160 case 'image': 160 case 'image':
161 - $v['image_link'] = file_get_contents($v); 161 + $v['image_link'] = url('/image/' . $v);
162 break; 162 break;
163 } 163 }
164 } 164 }
@@ -4,12 +4,41 @@ namespace App\Http\Controllers; @@ -4,12 +4,41 @@ namespace App\Http\Controllers;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Models\Image as ImageModel; 6 use App\Models\Image as ImageModel;
7 -use Faker\Provider\Image;  
8 use Illuminate\Http\Exceptions\HttpResponseException; 7 use Illuminate\Http\Exceptions\HttpResponseException;
9 use Illuminate\Http\JsonResponse; 8 use Illuminate\Http\JsonResponse;
  9 +use Illuminate\Http\Request;
  10 +use Intervention\Image\Facades\Image;
10 11
11 class ImageController 12 class ImageController
12 { 13 {
  14 + public $upload_img = [
  15 + //验证
  16 + 'rule' => [
  17 + 'size' => 3 * 1024 * 1024, //大小限制
  18 + 'ext' => 'jpeg,jpg,png,gif', //文件类型限制
  19 + ],
  20 + //生成文件规则
  21 + 'savename' => 'uniqid',
  22 + //设置静态缓存参数(304)
  23 + 'header' => [
  24 + 'Cache-Control' => 'max-age=2592000',
  25 + 'Pragma' => 'cache',
  26 + 'Expires' => "%Expires%", // cache 1 month
  27 + 'etag' => "%etag%",
  28 + 'Last-Modified' => "%Last-Modified%",
  29 + 'Content-Description' => 'File Transfer',
  30 + ],
  31 + //图片保存根路径
  32 + 'path' => './uploads/images/',
  33 + //图片上传变量名
  34 + 'name' => 'image',
  35 + ];
  36 + public $request = '';
  37 +
  38 + public function __construct(Request $request)
  39 + {
  40 + $this->request = $request;
  41 + }
13 42
14 public function index($hash = '', $w = 0 ,$h = 0){ 43 public function index($hash = '', $w = 0 ,$h = 0){
15 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { 44 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
@@ -21,24 +50,84 @@ class ImageController @@ -21,24 +50,84 @@ class ImageController
21 if ($info === false) { 50 if ($info === false) {
22 $this->response('指定图片不存在!', 404); 51 $this->response('指定图片不存在!', 404);
23 } 52 }
  53 + //查看缩略图是否存在
  54 + $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
  55 + if(is_file($filename)){
  56 + $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
  57 + $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
  58 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
  59 + $content = file_get_contents($filename);
  60 + $header['Content-Length'] = $info['size'];
  61 + return response($content, 200, $header);
  62 + }
24 $path = './../'.$info['path']; 63 $path = './../'.$info['path'];
25 if (!is_file($path)) { 64 if (!is_file($path)) {
26 - $this->response('指定图片已被系统删除!', 404,$path); 65 + $this->response('指定图片已被系统删除!', 404);
27 } 66 }
28 $content = ''; 67 $content = '';
29 $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; 68 $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
30 - $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->config['header_cache']); 69 + $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
  70 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
31 if ($w > 0 && $h > 0) { 71 if ($w > 0 && $h > 0) {
32 - $path = $this->cacheImage($info, $w, $h, 2); 72 + $path = $this->cacheImage($info, $w, $h);
33 $content = file_get_contents($path); 73 $content = file_get_contents($path);
34 $header['Content-Length'] = strlen($content); 74 $header['Content-Length'] = strlen($content);
35 } else { 75 } else {
36 $content = file_get_contents($path); 76 $content = file_get_contents($path);
37 $header['Content-Length'] = $info['size']; 77 $header['Content-Length'] = $info['size'];
38 } 78 }
39 - return response($content, 200, $header); 79 + $img_type = $info['type'];
  80 + $content = base64_encode($content);
  81 + $img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
  82 + return response($img_base64, 200, $header);
  83 + }
  84 + /**
  85 + * 图片上传
  86 + */
  87 + public function upload() {
  88 + $this->request->validate([
  89 + 'image'=>['required'],
  90 + ],[
  91 + 'image.required'=>'图片必须填写',
  92 + ]);
  93 + $files = $this->request->file('image');
  94 + if (empty($files)) {
  95 + $this->response('没有上传的文件!', 400);
  96 + }
  97 + $type = $this->request->post('type', 'single');
  98 + if ($type == 'multi') {
  99 + return $this->multi($files);
  100 + } else {
  101 + return $this->single($files);
  102 + }
  103 + }
  104 + /**
  105 + * @name :上传图片
  106 + * @return void
  107 + * @author :liyuhang
  108 + * @method
  109 + */
  110 + public function single($files){
  111 + if (is_array($files)) {
  112 + $file = current($files);
  113 + }
  114 + $url = './../uploads/images/';
  115 + $filename = date('ymdHis').rand(10000,99999);
  116 + $res = $files->move($url,$filename);
  117 + if ($res === false) {
  118 + return $this->fail($files->getError(), 400);
  119 + }
  120 + $data = [
  121 + 'path' => $url.$filename,
  122 + 'created_at' => date('Y-m-d H:i:s',time()),
  123 + 'size' => $res->getSize(),
  124 + 'hash' => $files->hashName(),
  125 + 'mime'=>$files->extension()
  126 + ];
  127 + $imageModel = new ImageModel();
  128 + $imageModel->add($data);
  129 + return $data['hash'];
40 } 130 }
41 -  
42 /** 131 /**
43 * 生成缩略图缓存 132 * 生成缩略图缓存
44 * @param type $info 133 * @param type $info
@@ -46,16 +135,11 @@ class ImageController @@ -46,16 +135,11 @@ class ImageController
46 * @param type $h 135 * @param type $h
47 * @return string 136 * @return string
48 */ 137 */
49 - private function cacheImage($info, $w, $h, $type = 2) {  
50 - $thumbnailPath = './../uploads/image/';  
51 - $thumbnailImage = Image::make($info)  
52 - ->fit($w, $h, function ($constraint) {  
53 - $constraint->upsize();  
54 - });  
55 -  
56 - $thumbnailImage->save($thumbnailPath);  
57 - return $thumbnailPath;  
58 - return; 138 + private function cacheImage($info, $w, $h) {
  139 + $path = './../'.$info['path'];
  140 + $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
  141 + Image::make($path)->resize($w, $h)->save($filename);
  142 + return $filename;
59 } 143 }
60 144
61 /** 145 /**
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +
  6 +use App\Models\Project;
  7 +
  8 +class ProjectLogic extends BaseLogic
  9 +{
  10 + public function __construct()
  11 + {
  12 + parent::__construct();
  13 + $this->model = new Project();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Models\ProjectRole;
  6 +
  7 +class ProjectRoleLogic extends BaseLogic
  8 +{
  9 + public function __construct()
  10 + {
  11 + parent::__construct();
  12 +
  13 + $this->model = new ProjectRole();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Models\User;
  6 +
  7 +class UserLogic extends BaseLogic
  8 +{
  9 + public function __construct()
  10 + {
  11 + parent::__construct();
  12 +
  13 + $this->model = new User();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +
  17 +}
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Http\Logic\Bside; 3 namespace App\Http\Logic\Bside;
4 4
  5 +use App\Enums\Common\Code;
5 use App\Exceptions\BsideGlobalException; 6 use App\Exceptions\BsideGlobalException;
6 use App\Http\Logic\Logic; 7 use App\Http\Logic\Logic;
7 use App\Models\Image as ImageModel; 8 use App\Models\Image as ImageModel;
@@ -101,15 +102,19 @@ class BaseLogic extends Logic @@ -101,15 +102,19 @@ class BaseLogic extends Logic
101 $filename = date('ymdHis').rand(10000,99999); 102 $filename = date('ymdHis').rand(10000,99999);
102 $res = $request->file('image')->move($url,$filename); 103 $res = $request->file('image')->move($url,$filename);
103 if ($res === false) { 104 if ($res === false) {
104 - return $this->fail($image->getError(), 400); 105 + return $this->fail($image->getError(), Code::USER_ERROR);
105 } 106 }
106 $data = [ 107 $data = [
107 'path' => $url.$filename, 108 'path' => $url.$filename,
108 'created_at' => date('Y-m-d H:i:s',time()), 109 'created_at' => date('Y-m-d H:i:s',time()),
109 'size' => $res->getSize(), 110 'size' => $res->getSize(),
110 - 'hash' => $res->hash(), 111 + 'hash' => $image->hashName(),
  112 + 'mime'=>$image->extension()
111 ]; 113 ];
112 - $imageModel->add($data);  
113 - return $data; 114 + $rs = $imageModel->add($data);
  115 + if ($rs === false) {
  116 + return $this->fail('添加失败', Code::USER_ERROR);
  117 + }
  118 + return $data['hash'];
114 } 119 }
115 } 120 }
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Models\User; 6 use App\Models\User;
  7 +use Illuminate\Support\Facades\DB;
7 8
8 class UserLogic extends BaseLogic 9 class UserLogic extends BaseLogic
9 { 10 {
@@ -28,13 +29,12 @@ class UserLogic extends BaseLogic @@ -28,13 +29,12 @@ class UserLogic extends BaseLogic
28 if($info !== false){ 29 if($info !== false){
29 $this->fail('error',Code::USER_ERROR); 30 $this->fail('error',Code::USER_ERROR);
30 } 31 }
31 - //密码加密  
32 - $this->param['password'] = base64_encode(md5($this->param['password']));  
33 - //上传头像 32 + //上传图片
34 if(isset($this->param['image'])){ 33 if(isset($this->param['image'])){
35 - $data = $this->upload();  
36 - $this->param['image'] = $data['hash']; 34 + $this->param['image'] = $this->upload();
37 } 35 }
  36 + //密码加密
  37 + $this->param['password'] = base64_encode(md5($this->param['password']));
38 $rs = $this->model->add($this->param); 38 $rs = $this->model->add($this->param);
39 if($rs === false){ 39 if($rs === false){
40 $this->fail('error',Code::USER_ERROR); 40 $this->fail('error',Code::USER_ERROR);
@@ -55,12 +55,16 @@ class UserLogic extends BaseLogic @@ -55,12 +55,16 @@ class UserLogic extends BaseLogic
55 if($info !== false){ 55 if($info !== false){
56 $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE); 56 $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
57 } 57 }
58 - //上传头像 58 + $this->param['operator_id'] = $this->user['id'];
  59 + //上传图片
59 if(isset($this->param['image'])){ 60 if(isset($this->param['image'])){
60 - $data = $this->upload();  
61 - $this->param['image'] = $data['hash']; 61 + //查看当前用户是否已有头像
  62 + $info = $this->model->read(['id'=>$this->param['id']],'hash');
  63 + if($info !== false){
  64 + DB::table('gl_image')->where(['hash'=>$info['hash']])->first();
  65 + }
  66 + $this->param['image'] = $this->upload();
62 } 67 }
63 - $this->param['operator_id'] = $this->user['id'];  
64 $rs = $this->model->edits($this->param); 68 $rs = $this->model->edits($this->param);
65 if($rs === false){ 69 if($rs === false){
66 $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); 70 $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
@@ -4,7 +4,7 @@ namespace App\Models; @@ -4,7 +4,7 @@ namespace App\Models;
4 4
5 class Image extends Base 5 class Image extends Base
6 { 6 {
7 - protected $table = 'gl_group'; 7 + protected $table = 'gl_image';
8 8
9 public $timestamps = true; 9 public $timestamps = true;
10 } 10 }
1 -#!/usr/bin/env php  
2 -<?php  
3 -  
4 -define('LARAVEL_START', microtime(true));  
5 -  
6 -/*  
7 -|--------------------------------------------------------------------------  
8 -| Register The Auto Loader  
9 -|--------------------------------------------------------------------------  
10 -|  
11 -| Composer provides a convenient, automatically generated class loader  
12 -| for our application. We just need to utilize it! We'll require it  
13 -| into the script here so that we do not have to worry about the  
14 -| loading of any of our classes manually. It's great to relax.  
15 -|  
16 -*/  
17 -  
18 -require __DIR__.'/vendor/autoload.php';  
19 -  
20 -$app = require_once __DIR__.'/bootstrap/app.php';  
21 -  
22 -/*  
23 -|--------------------------------------------------------------------------  
24 -| Run The Artisan Application  
25 -|--------------------------------------------------------------------------  
26 -|  
27 -| When we run the console application, the current CLI command will be  
28 -| executed in this console and the response sent back to a terminal  
29 -| or another output device for the developers. Here goes nothing!  
30 -|  
31 -*/  
32 -  
33 -$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);  
34 -  
35 -$status = $kernel->handle(  
36 - $input = new Symfony\Component\Console\Input\ArgvInput,  
37 - new Symfony\Component\Console\Output\ConsoleOutput  
38 -);  
39 -  
40 -/*  
41 -|--------------------------------------------------------------------------  
42 -| Shutdown The Application  
43 -|--------------------------------------------------------------------------  
44 -|  
45 -| Once Artisan has finished running, we will fire off the shutdown events  
46 -| so that any final work may be done by the application before we shut  
47 -| down the process. This is the last thing to happen to the request.  
48 -|  
49 -*/  
50 -  
51 -$kernel->terminate($input, $status);  
52 -  
53 -exit($status);  
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 "doctrine/dbal": "^3.6", 10 "doctrine/dbal": "^3.6",
11 "fruitcake/laravel-cors": "^2.0", 11 "fruitcake/laravel-cors": "^2.0",
12 "guzzlehttp/guzzle": "^7.0.1", 12 "guzzlehttp/guzzle": "^7.0.1",
  13 + "intervention/image": "^2.7",
13 "laravel/framework": "^8.75", 14 "laravel/framework": "^8.75",
14 "laravel/sanctum": "^2.11", 15 "laravel/sanctum": "^2.11",
15 "laravel/tinker": "^2.5" 16 "laravel/tinker": "^2.5"
@@ -174,7 +174,7 @@ return [ @@ -174,7 +174,7 @@ return [
174 // App\Providers\BroadcastServiceProvider::class, 174 // App\Providers\BroadcastServiceProvider::class,
175 App\Providers\EventServiceProvider::class, 175 App\Providers\EventServiceProvider::class,
176 App\Providers\RouteServiceProvider::class, 176 App\Providers\RouteServiceProvider::class,
177 - Intervention\Image\ImageServiceProvider::class, 177 +// Intervention\Image\ImageServiceProvider::class,
178 178
179 ], 179 ],
180 180
@@ -230,7 +230,7 @@ return [ @@ -230,7 +230,7 @@ return [
230 'URL' => Illuminate\Support\Facades\URL::class, 230 'URL' => Illuminate\Support\Facades\URL::class,
231 'Validator' => Illuminate\Support\Facades\Validator::class, 231 'Validator' => Illuminate\Support\Facades\Validator::class,
232 'View' => Illuminate\Support\Facades\View::class, 232 'View' => Illuminate\Support\Facades\View::class,
233 - 'Image'=>Intervention\Image\ImageManagerStatic::class, 233 +// 'Image'=>Intervention\Image\ImageManagerStatic::class,
234 ], 234 ],
235 235
236 ]; 236 ];
@@ -155,11 +155,14 @@ Route::middleware(['bloginauth'])->group(function () { @@ -155,11 +155,14 @@ Route::middleware(['bloginauth'])->group(function () {
155 Route::prefix('file')->group(function () { 155 Route::prefix('file')->group(function () {
156 Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload'); 156 Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
157 }); 157 });
  158 + Route::prefix('images')->group(function () {
  159 + Route::post('/upload', [\App\Http\Controllers\ImageController::class, 'upload'])->name('image_upload');
  160 + });
158 }); 161 });
159 162
160 //无需登录验证的路由组 163 //无需登录验证的路由组
161 Route::group([], function () { 164 Route::group([], function () {
162 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 165 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
163 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); 166 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
164 - Route::get('/image/{hash}/{w}/', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show'); 167 + Route::get('/image/{hash}/{w}/{h}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show');
165 }); 168 });