作者 liyuhang

gx

@@ -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'] = ($v); 161 + $v['image_link'] = file_get_contents($v);
162 break; 162 break;
163 } 163 }
164 } 164 }
@@ -7,9 +7,8 @@ use App\Http\Controllers\Bside\BaseController; @@ -7,9 +7,8 @@ use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\Blog\BlogLogic; 7 use App\Http\Logic\Bside\Blog\BlogLogic;
8 use App\Http\Requests\Bside\Blog\BlogRequest; 8 use App\Http\Requests\Bside\Blog\BlogRequest;
9 use App\Models\Blog\Blog as BlogModel; 9 use App\Models\Blog\Blog as BlogModel;
10 -use App\Models\RouteMap; 10 +use App\Models\Blog\BlogCategory as BlogCategoryModel;
11 use Illuminate\Http\Request; 11 use Illuminate\Http\Request;
12 -  
13 class BlogController extends BaseController 12 class BlogController extends BaseController
14 { 13 {
15 /** 14 /**
@@ -22,6 +21,20 @@ class BlogController extends BaseController @@ -22,6 +21,20 @@ class BlogController extends BaseController
22 //搜索条件 21 //搜索条件
23 $this->map['project_id'] = $this->user['project_id']; 22 $this->map['project_id'] = $this->user['project_id'];
24 $lists = $blogModel->lists($this->map,$this->page,$this->row); 23 $lists = $blogModel->lists($this->map,$this->page,$this->row);
  24 + if(!empty($lists['list'])){
  25 + foreach ($lists['list'] as $k => $v){
  26 + $blogCategoryModel= new BlogCategoryModel();
  27 + //获取用户已读还是未读
  28 + $category_info = $blogCategoryModel->
  29 + list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
  30 + $str = '';
  31 + foreach ($category_info as $v1){
  32 + $str .= $v1['name'].',';
  33 + }
  34 + $v['category_id'] = trim($str,',');
  35 + $lists['list'][$k] = $v;
  36 + }
  37 + }
25 $this->response('success',Code::SUCCESS,$lists); 38 $this->response('success',Code::SUCCESS,$lists);
26 } 39 }
27 40
@@ -24,14 +24,17 @@ class MailController extends BaseController @@ -24,14 +24,17 @@ class MailController extends BaseController
24 $this->map['user_list'] = ['like','%,'.$this->uid.',%']; 24 $this->map['user_list'] = ['like','%,'.$this->uid.',%'];
25 $this->map['status'] = $this::STATUS_ZERO; 25 $this->map['status'] = $this::STATUS_ZERO;
26 $lists = $mailModel->lists($this->map,$this->page,$this->row); 26 $lists = $mailModel->lists($this->map,$this->page,$this->row);
27 - if(!empty($lists)){  
28 - foreach ($lists as $k => $v){ 27 + if(!empty($lists['list'])){
  28 + foreach ($lists['list'] as $k => $v){
  29 + $mailUserModel = new MailUserModel();
29 //获取用户已读还是未读 30 //获取用户已读还是未读
30 - $info = MailUserModel::read(['mail_id'=>$v['id'],'user_id'=>$this->uid]); 31 + $info = $mailUserModel->read(['mail_id'=>$v['id'],'user_id'=>$this->uid]);
31 if($info !== false){ 32 if($info !== false){
32 $v['read_status'] = $this::STATUS_ONE;// 33 $v['read_status'] = $this::STATUS_ONE;//
  34 + }else{
  35 + $v['read_status'] = $this::STATUS_ZERO;
33 } 36 }
34 - $lists[$k] = $v; 37 + $lists['list'][$k] = $v;
35 } 38 }
36 } 39 }
37 $this->response('success',Code::SUCCESS,$lists); 40 $this->response('success',Code::SUCCESS,$lists);
@@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController; @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\News\NewsLogic; 7 use App\Http\Logic\Bside\News\NewsLogic;
8 use App\Http\Requests\Bside\News\NewsRequest; 8 use App\Http\Requests\Bside\News\NewsRequest;
9 use App\Models\News\News as NewsModel; 9 use App\Models\News\News as NewsModel;
  10 +use App\Models\News\NewsCategory as NewsCategoryModel;
10 use Illuminate\Http\Request; 11 use Illuminate\Http\Request;
11 12
12 /** 13 /**
@@ -23,6 +24,20 @@ class NewsController extends BaseController @@ -23,6 +24,20 @@ class NewsController extends BaseController
23 public function lists(NewsModel $news){ 24 public function lists(NewsModel $news){
24 $this->map['project_id'] = $this->user['project_id']; 25 $this->map['project_id'] = $this->user['project_id'];
25 $lists = $news->lists($this->map,$this->page,$this->row,$this->order); 26 $lists = $news->lists($this->map,$this->page,$this->row,$this->order);
  27 + if(!empty($lists['list'])){
  28 + foreach ($lists['list'] as $k => $v){
  29 + $newsCategoryModel= new NewsCategoryModel();
  30 + //获取用户已读还是未读
  31 + $category_info = $newsCategoryModel->
  32 + list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
  33 + $str = '';
  34 + foreach ($category_info as $v1){
  35 + $str .= $v1['name'].',';
  36 + }
  37 + $v['category_id'] = trim($str,',');
  38 + $lists['list'][$k] = $v;
  39 + }
  40 + }
26 $this->response('success',Code::SUCCESS,$lists); 41 $this->response('success',Code::SUCCESS,$lists);
27 } 42 }
28 43
@@ -4,11 +4,60 @@ namespace App\Http\Controllers; @@ -4,11 +4,60 @@ 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;
7 use Illuminate\Http\Exceptions\HttpResponseException; 8 use Illuminate\Http\Exceptions\HttpResponseException;
8 use Illuminate\Http\JsonResponse; 9 use Illuminate\Http\JsonResponse;
9 10
10 class ImageController 11 class ImageController
11 { 12 {
  13 +
  14 + public function index($hash = '', $w = 0 ,$h = 0){
  15 + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
  16 + header("HTTP/1.1 304 Not Modified");
  17 + exit;
  18 + }
  19 + $imageModel = new ImageModel();
  20 + $info = $imageModel->read(['hash'=>$hash]);
  21 + if ($info === false) {
  22 + $this->response('指定图片不存在!', 404);
  23 + }
  24 + $path = './../'.$info['path'];
  25 + if (!is_file($path)) {
  26 + $this->response('指定图片已被系统删除!', 404,$path);
  27 + }
  28 + $content = '';
  29 + $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']);
  31 + if ($w > 0 && $h > 0) {
  32 + $path = $this->cacheImage($info, $w, $h, 2);
  33 + $content = file_get_contents($path);
  34 + $header['Content-Length'] = strlen($content);
  35 + } else {
  36 + $content = file_get_contents($path);
  37 + $header['Content-Length'] = $info['size'];
  38 + }
  39 + return response($content, 200, $header);
  40 + }
  41 +
  42 + /**
  43 + * 生成缩略图缓存
  44 + * @param type $info
  45 + * @param type $w
  46 + * @param type $h
  47 + * @return string
  48 + */
  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;
  59 + }
  60 +
12 /** 61 /**
13 * @name 统一返回参数 62 * @name 统一返回参数
14 * @return JsonResponse 63 * @return JsonResponse
@@ -28,27 +77,4 @@ class ImageController @@ -28,27 +77,4 @@ class ImageController
28 $response = response($result,$result_code,$this->header);; 77 $response = response($result,$result_code,$this->header);;
29 throw new HttpResponseException($response); 78 throw new HttpResponseException($response);
30 } 79 }
31 -  
32 -  
33 - public function index($hash){  
34 - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {  
35 - header("HTTP/1.1 304 Not Modified");  
36 - exit;  
37 - }  
38 - $imageModel = new ImageModel();  
39 - $info = $imageModel->read(['hash'=>$hash]);  
40 - if ($info === false) {  
41 - $this->response('指定图片不存在!', 404);  
42 - }  
43 - $path = './../'.$info['path'];  
44 - if (!is_file($path)) {  
45 - $this->response('指定图片已被系统删除!', 404,$path);  
46 - }  
47 - $content = '';  
48 - $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";  
49 - $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], [$last_modified_time, $hash, $last_modified_time], $this->config['header_cache']);  
50 - $content = file_get_contents($path);  
51 - $header['Content-Length'] = $info['size'];  
52 - return response($content, 200, $header);  
53 - }  
54 } 80 }
@@ -31,10 +31,14 @@ class MailLogic extends BaseLogic @@ -31,10 +31,14 @@ class MailLogic extends BaseLogic
31 'user_id'=>$info['id'], 31 'user_id'=>$info['id'],
32 'mail_id'=>$this->user['id'], 32 'mail_id'=>$this->user['id'],
33 ]; 33 ];
34 - $rs = $mailUserModel->add($data);  
35 - if($rs === false){  
36 - $this->fail('error',Code::USER_ERROR); 34 + //查询当前记录是否存在
  35 + $read_info = $mailUserModel->read($data);
  36 + if($read_info === false){
  37 + $rs = $mailUserModel->add($data);
  38 + if($rs === false){
  39 + $this->fail('error',Code::USER_ERROR);
  40 + }
37 } 41 }
38 - $this->success($info); 42 + return $this->success($info);
39 } 43 }
40 } 44 }
@@ -33,7 +33,7 @@ class UserLogic extends BaseLogic @@ -33,7 +33,7 @@ class UserLogic extends BaseLogic
33 //上传头像 33 //上传头像
34 if(isset($this->param['image'])){ 34 if(isset($this->param['image'])){
35 $data = $this->upload(); 35 $data = $this->upload();
36 - $this->param['image'] = $data['path']; 36 + $this->param['image'] = $data['hash'];
37 } 37 }
38 $rs = $this->model->add($this->param); 38 $rs = $this->model->add($this->param);
39 if($rs === false){ 39 if($rs === false){
@@ -58,7 +58,7 @@ class UserLogic extends BaseLogic @@ -58,7 +58,7 @@ class UserLogic extends BaseLogic
58 //上传头像 58 //上传头像
59 if(isset($this->param['image'])){ 59 if(isset($this->param['image'])){
60 $data = $this->upload(); 60 $data = $this->upload();
61 - $this->param['image'] = $data['path']; 61 + $this->param['image'] = $data['hash'];
62 } 62 }
63 $this->param['operator_id'] = $this->user['id']; 63 $this->param['operator_id'] = $this->user['id'];
64 $rs = $this->model->edits($this->param); 64 $rs = $this->model->edits($this->param);
此 diff 太大无法显示。
@@ -174,6 +174,7 @@ return [ @@ -174,6 +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 178
178 ], 179 ],
179 180
@@ -229,7 +230,7 @@ return [ @@ -229,7 +230,7 @@ return [
229 'URL' => Illuminate\Support\Facades\URL::class, 230 'URL' => Illuminate\Support\Facades\URL::class,
230 'Validator' => Illuminate\Support\Facades\Validator::class, 231 'Validator' => Illuminate\Support\Facades\Validator::class,
231 'View' => Illuminate\Support\Facades\View::class, 232 'View' => Illuminate\Support\Facades\View::class,
232 - 233 + 'Image'=>Intervention\Image\ImageManagerStatic::class,
233 ], 234 ],
234 235
235 ]; 236 ];
@@ -161,4 +161,5 @@ Route::middleware(['bloginauth'])->group(function () { @@ -161,4 +161,5 @@ Route::middleware(['bloginauth'])->group(function () {
161 Route::group([], function () { 161 Route::group([], function () {
162 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 162 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'); 163 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');
164 }); 165 });