作者 liyuhang

gx

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 }
@@ -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,15 +50,26 @@ class ImageController @@ -21,15 +50,26 @@ 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 {
@@ -38,7 +78,51 @@ class ImageController @@ -38,7 +78,51 @@ class ImageController
38 } 78 }
39 return response($content, 200, $header); 79 return response($content, 200, $header);
40 } 80 }
41 - 81 + /**
  82 + * 图片上传
  83 + */
  84 + public function upload() {
  85 + $files = $this->request->file('image');
  86 + if (empty($files)) {
  87 + $this->response('没有上传的文件!', 400);
  88 + }
  89 + $type = $this->request->post('type', 'single');
  90 + if ($type == 'multi') {
  91 + return $this->multi($files);
  92 + } else {
  93 + return $this->single($files);
  94 + }
  95 + }
  96 + /**
  97 + * @name :上传图片
  98 + * @return void
  99 + * @author :liyuhang
  100 + * @method
  101 + */
  102 + public function single($files){
  103 + if (is_array($files)) {
  104 + $file = current($files);
  105 + }
  106 + $image = $this->request->file('image');
  107 + if(empty($image)){
  108 + return $this->fail('没有上传图片',Code::USER_ERROR);
  109 + }
  110 + $url = './../uploads/images/';
  111 + $filename = date('ymdHis').rand(10000,99999);
  112 + $res = $this->request->file('image')->move($url,$filename);
  113 + if ($res === false) {
  114 + return $this->fail($image->getError(), 400);
  115 + }
  116 + $data = [
  117 + 'path' => $url.$filename,
  118 + 'created_at' => date('Y-m-d H:i:s',time()),
  119 + 'size' => $res->getSize(),
  120 + 'hash' => hash(),
  121 + ];
  122 + $imageModel = new ImageModel();
  123 + $imageModel->add($data);
  124 + return $data;
  125 + }
42 /** 126 /**
43 * 生成缩略图缓存 127 * 生成缩略图缓存
44 * @param type $info 128 * @param type $info
@@ -46,16 +130,11 @@ class ImageController @@ -46,16 +130,11 @@ class ImageController
46 * @param type $h 130 * @param type $h
47 * @return string 131 * @return string
48 */ 132 */
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; 133 + private function cacheImage($info, $w, $h) {
  134 + $path = './../'.$info['path'];
  135 + $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
  136 + Image::make($path)->resize($w, $h)->save($filename);
  137 + return $filename;
59 } 138 }
60 139
61 /** 140 /**
  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 +}
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 ];