作者 赵彬吉

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

@@ -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'] = url('/image/' . $v); 161 + $data['image_link'] = url('/b/image/' . $v);
162 break; 162 break;
163 } 163 }
164 } 164 }
@@ -26,11 +26,9 @@ class ComController extends BaseController @@ -26,11 +26,9 @@ class ComController extends BaseController
26 'mobile'=>['required'], 26 'mobile'=>['required'],
27 'password'=>['required'], 27 'password'=>['required'],
28 ],[ 28 ],[
29 - 'mobile.required'=>'标题必须填写',  
30 - 'mobile.string'=>'标题中含有非法文字', 29 + 'mobile.required'=>'电话号码必须填写',
31 'password.required'=>'内容必须填写', 30 'password.required'=>'内容必须填写',
32 - 'password.string'=>'内容中含有非法文字',  
33 - 'mobile.max' => 'account不大于12字符.', 31 + 'mobile.max' => 'mobile不大于12字符.',
34 ]); 32 ]);
35 $userModel = new UserModel(); 33 $userModel = new UserModel();
36 $res = $userModel->login($this->param); 34 $res = $userModel->login($this->param);
@@ -7,6 +7,7 @@ use App\Models\Image as ImageModel; @@ -7,6 +7,7 @@ use App\Models\Image as ImageModel;
7 use Illuminate\Http\Exceptions\HttpResponseException; 7 use Illuminate\Http\Exceptions\HttpResponseException;
8 use Illuminate\Http\JsonResponse; 8 use Illuminate\Http\JsonResponse;
9 use Illuminate\Http\Request; 9 use Illuminate\Http\Request;
  10 +use Illuminate\Support\Facades\Hash;
10 use Intervention\Image\Facades\Image; 11 use Intervention\Image\Facades\Image;
11 12
12 class ImageController 13 class ImageController
@@ -48,7 +49,7 @@ class ImageController @@ -48,7 +49,7 @@ class ImageController
48 $imageModel = new ImageModel(); 49 $imageModel = new ImageModel();
49 $info = $imageModel->read(['hash'=>$hash]); 50 $info = $imageModel->read(['hash'=>$hash]);
50 if ($info === false) { 51 if ($info === false) {
51 - $this->response('指定图片不存在!', 404); 52 + $this->response('指定图片不存在!', Code::USER_ERROR);
52 } 53 }
53 //查看缩略图是否存在 54 //查看缩略图是否存在
54 $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h; 55 $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
@@ -58,23 +59,23 @@ class ImageController @@ -58,23 +59,23 @@ class ImageController
58 [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']); 59 [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
59 $content = file_get_contents($filename); 60 $content = file_get_contents($filename);
60 $header['Content-Length'] = $info['size']; 61 $header['Content-Length'] = $info['size'];
61 - return response($content, 200, $header);  
62 - }  
63 - $path = './../'.$info['path'];  
64 - if (!is_file($path)) {  
65 - $this->response('指定图片已被系统删除!', 404);  
66 - }  
67 - $content = '';  
68 - $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";  
69 - $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],  
70 - [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);  
71 - if ($w > 0 && $h > 0) {  
72 - $path = $this->cacheImage($info, $w, $h);  
73 - $content = file_get_contents($path);  
74 - $header['Content-Length'] = strlen($content);  
75 - } else {  
76 - $content = file_get_contents($path);  
77 - $header['Content-Length'] = $info['size']; 62 + }else{
  63 + $path = $info['path'];
  64 + if (!is_file($path)) {
  65 + $this->response('指定图片已被系统删除!', Code::USER_ERROR);
  66 + }
  67 + $content = '';
  68 + $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
  69 + $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
  70 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
  71 + if ($w > 0 && $h > 0) {
  72 + $path = $this->cacheImage($info, $w, $h);
  73 + $content = file_get_contents($path);
  74 + $header['Content-Length'] = strlen($content);
  75 + } else {
  76 + $content = file_get_contents($path);
  77 + $header['Content-Length'] = $info['size'];
  78 + }
78 } 79 }
79 $img_type = $info['type']; 80 $img_type = $info['type'];
80 $content = base64_encode($content); 81 $content = base64_encode($content);
@@ -117,12 +118,14 @@ class ImageController @@ -117,12 +118,14 @@ class ImageController
117 if ($res === false) { 118 if ($res === false) {
118 return $this->fail($files->getError(), 400); 119 return $this->fail($files->getError(), 400);
119 } 120 }
  121 +
120 $data = [ 122 $data = [
121 'path' => $url.$filename, 123 'path' => $url.$filename,
122 'created_at' => date('Y-m-d H:i:s',time()), 124 'created_at' => date('Y-m-d H:i:s',time()),
123 'size' => $res->getSize(), 125 'size' => $res->getSize(),
124 - 'hash' => $files->hashName(),  
125 - 'mime'=>$files->extension() 126 + 'hash' => hash_file('md5', $res->getPathname()),
  127 + 'type'=>$files->getClientOriginalExtension(),
  128 +// 'mime'=>$files->getMimeType()
126 ]; 129 ];
127 $imageModel = new ImageModel(); 130 $imageModel = new ImageModel();
128 $imageModel->add($data); 131 $imageModel->add($data);
@@ -136,7 +139,7 @@ class ImageController @@ -136,7 +139,7 @@ class ImageController
136 * @return string 139 * @return string
137 */ 140 */
138 private function cacheImage($info, $w, $h) { 141 private function cacheImage($info, $w, $h) {
139 - $path = './../'.$info['path']; 142 + $path = $info['path'];
140 $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h; 143 $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
141 Image::make($path)->resize($w, $h)->save($filename); 144 Image::make($path)->resize($w, $h)->save($filename);
142 return $filename; 145 return $filename;
@@ -154,10 +157,9 @@ class ImageController @@ -154,10 +157,9 @@ class ImageController
154 $result = [ 157 $result = [
155 'msg' => $msg == ' ' ? $code->description : $msg, 158 'msg' => $msg == ' ' ? $code->description : $msg,
156 'code' => $code->value, 159 'code' => $code->value,
157 - 'data' => $this->_extents($data), 160 + 'data' => $data,
158 ]; 161 ];
159 $this->header['Content-Type'] = $type; 162 $this->header['Content-Type'] = $type;
160 - $this->header['token'] = $this->token;  
161 $response = response($result,$result_code,$this->header);; 163 $response = response($result,$result_code,$this->header);;
162 throw new HttpResponseException($response); 164 throw new HttpResponseException($response);
163 } 165 }
@@ -19,12 +19,14 @@ class BaseLogic extends Logic @@ -19,12 +19,14 @@ class BaseLogic extends Logic
19 19
20 protected $param; 20 protected $param;
21 21
  22 + protected $request;
  23 +
22 protected $user; 24 protected $user;
23 25
24 public function __construct() 26 public function __construct()
25 { 27 {
  28 + $this->request = request();
26 $this->requestAll = request()->all(); 29 $this->requestAll = request()->all();
27 -  
28 $this->user = Cache::get(request()->header('token')); 30 $this->user = Cache::get(request()->header('token'));
29 } 31 }
30 32
@@ -93,14 +95,14 @@ class BaseLogic extends Logic @@ -93,14 +95,14 @@ class BaseLogic extends Logic
93 * @author :liyuhang 95 * @author :liyuhang
94 * @method 96 * @method
95 */ 97 */
96 - public function upload(Request $request,ImageModel $imageModel){  
97 - $image = $request->file('image'); 98 + public function upload(){
  99 + $image = $this->request->file('image');
98 if(empty($image)){ 100 if(empty($image)){
99 return $this->fail('没有上传图片',Code::USER_ERROR); 101 return $this->fail('没有上传图片',Code::USER_ERROR);
100 } 102 }
101 $url = './../uploads/images/'; 103 $url = './../uploads/images/';
102 $filename = date('ymdHis').rand(10000,99999); 104 $filename = date('ymdHis').rand(10000,99999);
103 - $res = $request->file('image')->move($url,$filename); 105 + $res = $this->request->file('image')->move($url,$filename);
104 if ($res === false) { 106 if ($res === false) {
105 return $this->fail($image->getError(), Code::USER_ERROR); 107 return $this->fail($image->getError(), Code::USER_ERROR);
106 } 108 }
@@ -108,9 +110,11 @@ class BaseLogic extends Logic @@ -108,9 +110,11 @@ class BaseLogic extends Logic
108 'path' => $url.$filename, 110 'path' => $url.$filename,
109 'created_at' => date('Y-m-d H:i:s',time()), 111 'created_at' => date('Y-m-d H:i:s',time()),
110 'size' => $res->getSize(), 112 'size' => $res->getSize(),
111 - 'hash' => $image->hashName(),  
112 - 'mime'=>$image->extension() 113 + 'hash' => hash_file('md5', $res->getPathname()),
  114 + 'type'=>$image->getClientOriginalExtension(),
  115 +// 'mime'=>$image->getMimeType()
113 ]; 116 ];
  117 + $imageModel = new ImageModel();
114 $rs = $imageModel->add($data); 118 $rs = $imageModel->add($data);
115 if ($rs === false) { 119 if ($rs === false) {
116 return $this->fail('添加失败', Code::USER_ERROR); 120 return $this->fail('添加失败', Code::USER_ERROR);
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Blog\Blog; 7 use App\Models\Blog\Blog;
8 use App\Models\Blog\BlogCategory as BlogCategoryModel; 8 use App\Models\Blog\BlogCategory as BlogCategoryModel;
  9 +use App\Models\Image;
9 use App\Models\RouteMap; 10 use App\Models\RouteMap;
10 use Illuminate\Support\Facades\DB; 11 use Illuminate\Support\Facades\DB;
11 12
@@ -50,12 +51,19 @@ class BlogLogic extends BaseLogic @@ -50,12 +51,19 @@ class BlogLogic extends BaseLogic
50 * @method 51 * @method
51 */ 52 */
52 public function blog_add(){ 53 public function blog_add(){
53 - $this->param['create_id'] = $this->uid;  
54 - $this->param['operator_id'] = $this->uid; 54 + $this->param['create_id'] = $this->user['id'];
  55 + $this->param['operator_id'] = $this->user['id'];
55 $this->param['project_id'] = $this->user['project_id']; 56 $this->param['project_id'] = $this->user['project_id'];
  57 + $this->param['created_at'] = date('Y-m-d H:i:s',time());
  58 + $this->param['updated_at'] = date('Y-m-d H:i:s',time());
  59 + $this->param['category_id'] = ','.$this->param['category_id'].',';
56 DB::beginTransaction(); 60 DB::beginTransaction();
57 try { 61 try {
58 - $rs = $this->model->insertGetId($this->param); 62 + if(isset($this->param['image'])){
  63 + $data = $this->upload();
  64 + $this->param['image'] = $data;
  65 + }
  66 + $this->model->insertGetId($this->param);
59 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']); 67 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
60 DB::commit(); 68 DB::commit();
61 }catch (\Exception $e){ 69 }catch (\Exception $e){
@@ -77,8 +85,19 @@ class BlogLogic extends BaseLogic @@ -77,8 +85,19 @@ class BlogLogic extends BaseLogic
77 $this->param['operator_id'] = $this->uid; 85 $this->param['operator_id'] = $this->uid;
78 DB::beginTransaction(); 86 DB::beginTransaction();
79 try { 87 try {
80 - $this->model->edit($this->param,['id'=>$this->param['id']]); 88 + if(isset($this->param['image']) && is_file($this->param['image'])){
  89 + //查看当前用户是否已有头像
  90 + $info = $this->model->read(['id'=>$this->param['id']],['id','hash']);
  91 + if($info !== false && !empty($info['hash'])){
  92 + //TODO::删除资源
  93 + $imageModel = new Image();
  94 + $image_info = $imageModel->read(['hash'=>$info['hash']],['id','path']);
  95 + shell_exec('rm -rf '.$image_info['path'] .'./../uploads/images/cache_'. $info['hash'] . '*');
  96 + }
  97 + $this->param['image'] = $this->upload();
  98 + }
81 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']); 99 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
  100 + $this->model->edit($this->param,['id'=>$this->param['id']]);
82 DB::commit(); 101 DB::commit();
83 }catch (\Exception $e){ 102 }catch (\Exception $e){
84 DB::rollBack(); 103 DB::rollBack();
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\News; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\News;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Image;
7 use App\Models\News\News; 8 use App\Models\News\News;
8 use App\Models\News\NewsCategory as NewsCategoryModel; 9 use App\Models\News\NewsCategory as NewsCategoryModel;
9 use App\Models\RouteMap; 10 use App\Models\RouteMap;
@@ -52,22 +53,26 @@ class NewsLogic extends BaseLogic @@ -52,22 +53,26 @@ class NewsLogic extends BaseLogic
52 * @method 53 * @method
53 */ 54 */
54 public function news_add(){ 55 public function news_add(){
55 - $this->param['create_id'] = $this->uid;  
56 - $this->param['operator_id'] = $this->uid; 56 + $this->param['create_id'] = $this->user['id'];
  57 + $this->param['operator_id'] = $this->user['id'];
57 $this->param['project_id'] = $this->user['project_id']; 58 $this->param['project_id'] = $this->user['project_id'];
  59 + $this->param['created_at'] = date('Y-m-d H:i:s',time());
  60 + $this->param['updated_at'] = date('Y-m-d H:i:s',time());
  61 + $this->param['category_id'] = ','.$this->param['category_id'].',';
58 DB::beginTransaction(); 62 DB::beginTransaction();
59 try { 63 try {
60 if(isset($this->param['image'])){ 64 if(isset($this->param['image'])){
61 $data = $this->upload(); 65 $data = $this->upload();
62 - $this->param['image'] = $data['path']; 66 + $this->param['image'] = $data;
63 } 67 }
64 $rs = $this->model->insertGetId($this->param); 68 $rs = $this->model->insertGetId($this->param);
65 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); 69 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
66 DB::commit(); 70 DB::commit();
67 }catch (\Exception $e){ 71 }catch (\Exception $e){
68 DB::rollBack(); 72 DB::rollBack();
69 - $this->fail('error',Code::USER_ERROR); 73 + $this->fail('添加失败',Code::USER_ERROR);
70 } 74 }
  75 +
71 //TODO::写入日志 76 //TODO::写入日志
72 $this->success(); 77 $this->success();
73 } 78 }
@@ -83,9 +88,26 @@ class NewsLogic extends BaseLogic @@ -83,9 +88,26 @@ class NewsLogic extends BaseLogic
83 $this->param['operator_id'] = $this->user['id']; 88 $this->param['operator_id'] = $this->user['id'];
84 //多个分类按逗号隔开 89 //多个分类按逗号隔开
85 $this->param['category_id'] = ','.$this->param['category_id'].','; 90 $this->param['category_id'] = ','.$this->param['category_id'].',';
86 - $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);  
87 - if($rs === false){  
88 - $this->fail('error',Code::USER_ERROR); 91 + DB::beginTransaction();
  92 + try {
  93 + //上传图片
  94 + if(isset($this->param['image']) && is_file($this->param['image'])){
  95 + //查看当前用户是否已有头像
  96 + $info = $this->model->read(['id'=>$this->param['id']],['id','hash']);
  97 + if($info !== false && !empty($info['hash'])){
  98 + //TODO::删除资源
  99 + $imageModel = new Image();
  100 + $image_info = $imageModel->read(['hash'=>$info['hash']],['id','path']);
  101 + shell_exec('rm -rf '.$image_info['path'] .'./../uploads/images/cache_'. $info['hash'] . '*');
  102 + }
  103 + $this->param['image'] = $this->upload();
  104 + }
  105 + RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
  106 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  107 + DB::commit();
  108 + }catch (\exception $e){
  109 + DB::rollBack();
  110 + $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
89 } 111 }
90 //TODO::写入日志 112 //TODO::写入日志
91 $this->success(); 113 $this->success();
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Logic\Bside; 3 namespace App\Http\Logic\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
  6 +use App\Models\Image;
6 use App\Models\User; 7 use App\Models\User;
7 use Illuminate\Support\Facades\DB; 8 use Illuminate\Support\Facades\DB;
8 9
@@ -56,17 +57,21 @@ class UserLogic extends BaseLogic @@ -56,17 +57,21 @@ class UserLogic extends BaseLogic
56 $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE); 57 $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
57 } 58 }
58 $this->param['operator_id'] = $this->user['id']; 59 $this->param['operator_id'] = $this->user['id'];
59 - //上传图片  
60 - if(isset($this->param['image'])){  
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(); 60 + try {
  61 + //上传图片
  62 + if(isset($this->param['image'])){
  63 + //查看当前用户是否已有头像
  64 + $info = $this->model->read(['id'=>$this->param['id']],['id','hash']);
  65 + if($info !== false && !empty($info['hash'])){
  66 + //TODO::删除资源
  67 + $imageModel = new Image();
  68 + $image_info = $imageModel->read(['hash'=>$info['hash']],['id','path']);
  69 + shell_exec('rm -rf '.$image_info['path'] .'./../uploads/images/cache_'. $info['hash'] . '*');
  70 + }
  71 + $this->param['image'] = $this->upload();
  72 + $this->model->edits($this->param);
65 } 73 }
66 - $this->param['image'] = $this->upload();  
67 - }  
68 - $rs = $this->model->edits($this->param);  
69 - if($rs === false){ 74 + }catch (\exception $e){
70 $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); 75 $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
71 } 76 }
72 return $this->success(); 77 return $this->success();
@@ -164,5 +164,5 @@ Route::middleware(['bloginauth'])->group(function () { @@ -164,5 +164,5 @@ Route::middleware(['bloginauth'])->group(function () {
164 Route::group([], function () { 164 Route::group([], function () {
165 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');
166 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');
167 - Route::get('/image/{hash}/{w}/{h}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show'); 167 + Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show');
168 }); 168 });