作者 liyuhang

gx

... ... @@ -158,7 +158,7 @@ class BaseController extends Controller
}
switch ((string) $k) {
case 'image':
$v['image_link'] = ($v);
$v['image_link'] = file_get_contents($v);
break;
}
}
... ...
... ... @@ -7,9 +7,8 @@ use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\RouteMap;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use Illuminate\Http\Request;
class BlogController extends BaseController
{
/**
... ... @@ -22,6 +21,20 @@ class BlogController extends BaseController
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$lists = $blogModel->lists($this->map,$this->page,$this->row);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$blogCategoryModel= new BlogCategoryModel();
//获取用户已读还是未读
$category_info = $blogCategoryModel->
list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
$str = '';
foreach ($category_info as $v1){
$str .= $v1['name'].',';
}
$v['category_id'] = trim($str,',');
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
... ...
... ... @@ -24,14 +24,17 @@ class MailController extends BaseController
$this->map['user_list'] = ['like','%,'.$this->uid.',%'];
$this->map['status'] = $this::STATUS_ZERO;
$lists = $mailModel->lists($this->map,$this->page,$this->row);
if(!empty($lists)){
foreach ($lists as $k => $v){
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$mailUserModel = new MailUserModel();
//获取用户已读还是未读
$info = MailUserModel::read(['mail_id'=>$v['id'],'user_id'=>$this->uid]);
$info = $mailUserModel->read(['mail_id'=>$v['id'],'user_id'=>$this->uid]);
if($info !== false){
$v['read_status'] = $this::STATUS_ONE;//
}else{
$v['read_status'] = $this::STATUS_ZERO;
}
$lists[$k] = $v;
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
use Illuminate\Http\Request;
/**
... ... @@ -23,6 +24,20 @@ class NewsController extends BaseController
public function lists(NewsModel $news){
$this->map['project_id'] = $this->user['project_id'];
$lists = $news->lists($this->map,$this->page,$this->row,$this->order);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$newsCategoryModel= new NewsCategoryModel();
//获取用户已读还是未读
$category_info = $newsCategoryModel->
list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
$str = '';
foreach ($category_info as $v1){
$str .= $v1['name'].',';
}
$v['category_id'] = trim($str,',');
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
... ...
... ... @@ -4,33 +4,14 @@ 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;
class ImageController
{
/**
* @name 统一返回参数
* @return JsonResponse
* @author :liyuhang
* @method
*/
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
$code = Code::fromValue($code);
$result = [
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $this->_extents($data),
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
$response = response($result,$result_code,$this->header);;
throw new HttpResponseException($response);
}
public function index($hash){
public function index($hash = '', $w = 0 ,$h = 0){
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
header("HTTP/1.1 304 Not Modified");
exit;
... ... @@ -46,9 +27,54 @@ class ImageController
}
$content = '';
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], [$last_modified_time, $hash, $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->config['header_cache']);
if ($w > 0 && $h > 0) {
$path = $this->cacheImage($info, $w, $h, 2);
$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);
}
/**
* 生成缩略图缓存
* @param type $info
* @param type $w
* @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;
}
/**
* @name 统一返回参数
* @return JsonResponse
* @author :liyuhang
* @method
*/
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
$code = Code::fromValue($code);
$result = [
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $this->_extents($data),
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
$response = response($result,$result_code,$this->header);;
throw new HttpResponseException($response);
}
}
... ...
... ... @@ -31,10 +31,14 @@ class MailLogic extends BaseLogic
'user_id'=>$info['id'],
'mail_id'=>$this->user['id'],
];
//查询当前记录是否存在
$read_info = $mailUserModel->read($data);
if($read_info === false){
$rs = $mailUserModel->add($data);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
$this->success($info);
}
return $this->success($info);
}
}
... ...
... ... @@ -33,7 +33,7 @@ class UserLogic extends BaseLogic
//上传头像
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data['path'];
$this->param['image'] = $data['hash'];
}
$rs = $this->model->add($this->param);
if($rs === false){
... ... @@ -58,7 +58,7 @@ class UserLogic extends BaseLogic
//上传头像
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data['path'];
$this->param['image'] = $data['hash'];
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edits($this->param);
... ...
此 diff 太大无法显示。
... ... @@ -174,6 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Intervention\Image\ImageServiceProvider::class,
],
... ... @@ -229,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,
],
];
... ...
... ... @@ -161,4 +161,5 @@ Route::middleware(['bloginauth'])->group(function () {
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');
});
... ...