作者 赵彬吉

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

APP_NAME=Laravel
APP_ENV=test
APP_KEY=base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow=
APP_DEBUG=false
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=globalso
DB_USERNAME=debian-sys-maint
DB_PASSWORD=WtujxV73XIclQet0
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
... ... @@ -2,6 +2,7 @@
namespace App\Http\Controllers\Aside;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Project as ProjectModel;
... ... @@ -20,6 +21,16 @@ class ProjectController extends BaseController
public function lists(){
$projectModel = new ProjectModel();
$lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order);
$this->result($lists);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :添加项目
* @return void
* @author :liyuhang
* @method
*/
public function add(){
$projectModel = new ProjectModel();
}
}
... ...
... ... @@ -158,7 +158,7 @@ class BaseController extends Controller
}
switch ((string) $k) {
case 'image':
$v['image_link'] = file_get_contents($v);
$v['image_link'] = url('/image/' . $v);
break;
}
}
... ...
... ... @@ -4,12 +4,41 @@ namespace App\Http\Controllers;
use App\Enums\Common\Code;
use App\Models\Image as ImageModel;
use Faker\Provider\Image;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
class ImageController
{
public $upload_img = [
//验证
'rule' => [
'size' => 3 * 1024 * 1024, //大小限制
'ext' => 'jpeg,jpg,png,gif', //文件类型限制
],
//生成文件规则
'savename' => 'uniqid',
//设置静态缓存参数(304)
'header' => [
'Cache-Control' => 'max-age=2592000',
'Pragma' => 'cache',
'Expires' => "%Expires%", // cache 1 month
'etag' => "%etag%",
'Last-Modified' => "%Last-Modified%",
'Content-Description' => 'File Transfer',
],
//图片保存根路径
'path' => './uploads/images/',
//图片上传变量名
'name' => 'image',
];
public $request = '';
public function __construct(Request $request)
{
$this->request = $request;
}
public function index($hash = '', $w = 0 ,$h = 0){
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
... ... @@ -21,24 +50,84 @@ class ImageController
if ($info === false) {
$this->response('指定图片不存在!', 404);
}
//查看缩略图是否存在
$filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
if(is_file($filename)){
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
$content = file_get_contents($filename);
$header['Content-Length'] = $info['size'];
return response($content, 200, $header);
}
$path = './../'.$info['path'];
if (!is_file($path)) {
$this->response('指定图片已被系统删除!', 404,$path);
$this->response('指定图片已被系统删除!', 404);
}
$content = '';
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->config['header_cache']);
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
if ($w > 0 && $h > 0) {
$path = $this->cacheImage($info, $w, $h, 2);
$path = $this->cacheImage($info, $w, $h);
$content = file_get_contents($path);
$header['Content-Length'] = strlen($content);
} else {
$content = file_get_contents($path);
$header['Content-Length'] = $info['size'];
}
return response($content, 200, $header);
$img_type = $info['type'];
$content = base64_encode($content);
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
return response($img_base64, 200, $header);
}
/**
* 图片上传
*/
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){
if (is_array($files)) {
$file = current($files);
}
$url = './../uploads/images/';
$filename = date('ymdHis').rand(10000,99999);
$res = $files->move($url,$filename);
if ($res === false) {
return $this->fail($files->getError(), 400);
}
$data = [
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $files->hashName(),
'mime'=>$files->extension()
];
$imageModel = new ImageModel();
$imageModel->add($data);
return $data['hash'];
}
/**
* 生成缩略图缓存
* @param type $info
... ... @@ -46,16 +135,11 @@ class ImageController
* @param type $h
* @return string
*/
private function cacheImage($info, $w, $h, $type = 2) {
$thumbnailPath = './../uploads/image/';
$thumbnailImage = Image::make($info)
->fit($w, $h, function ($constraint) {
$constraint->upsize();
});
$thumbnailImage->save($thumbnailPath);
return $thumbnailPath;
return;
private function cacheImage($info, $w, $h) {
$path = './../'.$info['path'];
$filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
Image::make($path)->resize($w, $h)->save($filename);
return $filename;
}
/**
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\Project;
class ProjectLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Project();
$this->param = $this->requestAll;
}
}
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\ProjectRole;
class ProjectRoleLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new ProjectRole();
$this->param = $this->requestAll;
}
}
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\User;
class UserLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new User();
$this->param = $this->requestAll;
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Http\Logic\Logic;
use App\Models\Image as ImageModel;
... ... @@ -101,15 +102,19 @@ class BaseLogic extends Logic
$filename = date('ymdHis').rand(10000,99999);
$res = $request->file('image')->move($url,$filename);
if ($res === false) {
return $this->fail($image->getError(), 400);
return $this->fail($image->getError(), Code::USER_ERROR);
}
$data = [
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => $res->hash(),
'hash' => $image->hashName(),
'mime'=>$image->extension()
];
$imageModel->add($data);
return $data;
$rs = $imageModel->add($data);
if ($rs === false) {
return $this->fail('添加失败', Code::USER_ERROR);
}
return $data['hash'];
}
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Models\User;
use Illuminate\Support\Facades\DB;
class UserLogic extends BaseLogic
{
... ... @@ -28,13 +29,12 @@ class UserLogic extends BaseLogic
if($info !== false){
$this->fail('error',Code::USER_ERROR);
}
//密码加密
$this->param['password'] = base64_encode(md5($this->param['password']));
//上传头像
//上传图片
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data['hash'];
$this->param['image'] = $this->upload();
}
//密码加密
$this->param['password'] = base64_encode(md5($this->param['password']));
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
... ... @@ -55,12 +55,16 @@ class UserLogic extends BaseLogic
if($info !== false){
$this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
}
//上传头像
$this->param['operator_id'] = $this->user['id'];
//上传图片
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data['hash'];
//查看当前用户是否已有头像
$info = $this->model->read(['id'=>$this->param['id']],'hash');
if($info !== false){
DB::table('gl_image')->where(['hash'=>$info['hash']])->first();
}
$this->param['image'] = $this->upload();
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edits($this->param);
if($rs === false){
$this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
... ...
... ... @@ -4,7 +4,7 @@ namespace App\Models;
class Image extends Base
{
protected $table = 'gl_group';
protected $table = 'gl_image';
public $timestamps = true;
}
... ...
#!/usr/bin/env php
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);
... ... @@ -10,6 +10,7 @@
"doctrine/dbal": "^3.6",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.7",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
... ...
... ... @@ -174,7 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Intervention\Image\ImageServiceProvider::class,
// Intervention\Image\ImageServiceProvider::class,
],
... ... @@ -230,7 +230,7 @@ return [
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Image'=>Intervention\Image\ImageManagerStatic::class,
// 'Image'=>Intervention\Image\ImageManagerStatic::class,
],
];
... ...
... ... @@ -155,11 +155,14 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('file')->group(function () {
Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
});
Route::prefix('images')->group(function () {
Route::post('/upload', [\App\Http\Controllers\ImageController::class, 'upload'])->name('image_upload');
});
});
//无需登录验证的路由组
Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
Route::get('/image/{hash}/{w}/', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show');
Route::get('/image/{hash}/{w}/{h}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show');
});
... ...