Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev
正在显示
11 个修改的文件
包含
171 行增加
和
148 行删除
| @@ -144,3 +144,68 @@ if (!function_exists('checkDomain')) { | @@ -144,3 +144,68 @@ if (!function_exists('checkDomain')) { | ||
| 144 | } | 144 | } |
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| 147 | + | ||
| 148 | + | ||
| 149 | + | ||
| 150 | +/** | ||
| 151 | + * 把返回的数据集转换成Tree | ||
| 152 | + * @param $list array 数据列表 | ||
| 153 | + * @param string|int $pk 主键|root | ||
| 154 | + * @param string $pid 父id | ||
| 155 | + * @param string $child 子键 | ||
| 156 | + * @param int $root 获取哪个id下面 | ||
| 157 | + * @param bool $empty_child 当子数据不存在,是否要返回空子数据 | ||
| 158 | + * @return array | ||
| 159 | + */ | ||
| 160 | +function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$empty_child=true) { | ||
| 161 | + // 如果是数字,则是root | ||
| 162 | + if(is_numeric($pk)){ | ||
| 163 | + $root = $pk; | ||
| 164 | + $pk = 'id'; | ||
| 165 | + } | ||
| 166 | + // 创建Tree | ||
| 167 | + $tree = array(); | ||
| 168 | + if(is_array($list)) { | ||
| 169 | + // 创建基于主键的数组引用 | ||
| 170 | + $refer = array(); | ||
| 171 | + foreach ($list as $key => $data) { | ||
| 172 | + if($empty_child){ | ||
| 173 | + $list[$key][$child] = []; | ||
| 174 | + } | ||
| 175 | + $refer[$data[$pk]] =& $list[$key]; | ||
| 176 | + } | ||
| 177 | + foreach ($list as $key => $data) { | ||
| 178 | + // 判断是否存在parent | ||
| 179 | + $parentId = $data[$pid]; | ||
| 180 | + if ($root == $parentId) { | ||
| 181 | + $tree[] =& $list[$key]; | ||
| 182 | + }else{ | ||
| 183 | + if (isset($refer[$parentId])) { | ||
| 184 | + $refer[$parentId][$child][] = & $list[$key]; | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + return $tree; | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | +/** | ||
| 193 | + * tree数据转list | ||
| 194 | + * @param $tree | ||
| 195 | + * @param string $child | ||
| 196 | + * @return array | ||
| 197 | + * @author:dc | ||
| 198 | + * @time 2022/1/11 10:13 | ||
| 199 | + */ | ||
| 200 | +function tree_to_list($tree, $child='_child'){ | ||
| 201 | + $lists = []; | ||
| 202 | + foreach ($tree as $item){ | ||
| 203 | + $c = $item[$child]??[]; | ||
| 204 | + unset($item[$child]); | ||
| 205 | + $lists[] = $item; | ||
| 206 | + if ($c){ | ||
| 207 | + $lists = array_merge($lists,tree_to_list($c, $child)); | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + return $lists; | ||
| 211 | +} |
| @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Aside; | @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Aside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | +use App\Http\Requests\Aside\Template\TemplateRequest; | ||
| 8 | +use App\Http\Requests\Scene; | ||
| 7 | use Illuminate\Http\JsonResponse; | 9 | use Illuminate\Http\JsonResponse; |
| 8 | use Illuminate\Http\Request; | 10 | use Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Exceptions\HttpResponseException; | 11 | use Illuminate\Http\Exceptions\HttpResponseException; |
| @@ -155,4 +157,21 @@ class BaseController extends Controller | @@ -155,4 +157,21 @@ class BaseController extends Controller | ||
| 155 | } | 157 | } |
| 156 | return $data; | 158 | return $data; |
| 157 | } | 159 | } |
| 160 | + | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * 验证 | ||
| 164 | + * @param $c | ||
| 165 | + * @param $scene | ||
| 166 | + * @return array | ||
| 167 | + * @author:dc | ||
| 168 | + * @time 2023/5/11 14:56 | ||
| 169 | + */ | ||
| 170 | + protected final function verify($c,$scene=null){ | ||
| 171 | + return (new $c())->setScene($scene?:Scene::$CREATE)->validated(); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + | ||
| 175 | + | ||
| 176 | + | ||
| 158 | } | 177 | } |
| @@ -3,6 +3,9 @@ | @@ -3,6 +3,9 @@ | ||
| 3 | namespace App\Http\Controllers\Aside; | 3 | namespace App\Http\Controllers\Aside; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Http\Logic\Aside\Template\TemplateLogic; | ||
| 7 | +use App\Http\Requests\Aside\Template\TemplateRequest; | ||
| 8 | +use App\Http\Requests\Scene; | ||
| 6 | use App\Models\Template\ATemplate; | 9 | use App\Models\Template\ATemplate; |
| 7 | use App\Models\Template\ATemplateHtml; | 10 | use App\Models\Template\ATemplateHtml; |
| 8 | use Illuminate\Validation\Rule; | 11 | use Illuminate\Validation\Rule; |
| @@ -25,22 +28,9 @@ class TemplateController extends BaseController | @@ -25,22 +28,9 @@ class TemplateController extends BaseController | ||
| 25 | */ | 28 | */ |
| 26 | public function index(){ | 29 | public function index(){ |
| 27 | 30 | ||
| 28 | - $limit = $this->param['limit']??20; | 31 | + $lists = (new ATemplate)->lists($this->map,$this->page,$this->row,$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); |
| 32 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 29 | 33 | ||
| 30 | - | ||
| 31 | - $lists = ATemplate::where(function ($query){ | ||
| 32 | - | ||
| 33 | - !empty($this->param['status']) && $query->where('status',$this->param['status']); | ||
| 34 | - !empty($this->param['name']) && $query->where('status',$this->param['name']); | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - }) | ||
| 38 | - ->select(['id','name','status','is_default','sort','thumb','url','created_at','updated_at']) | ||
| 39 | - ->orderBy('sort') | ||
| 40 | - ->paginate($limit); | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - return $this->success($lists->toArray()); | ||
| 44 | } | 34 | } |
| 45 | 35 | ||
| 46 | 36 | ||
| @@ -50,7 +40,7 @@ class TemplateController extends BaseController | @@ -50,7 +40,7 @@ class TemplateController extends BaseController | ||
| 50 | * @time 2023/5/4 16:19 | 40 | * @time 2023/5/4 16:19 |
| 51 | */ | 41 | */ |
| 52 | public function edit(){ | 42 | public function edit(){ |
| 53 | - $this->save(true); | 43 | + $this->save(Scene::$UPDATE); |
| 54 | } | 44 | } |
| 55 | 45 | ||
| 56 | /** | 46 | /** |
| @@ -59,7 +49,7 @@ class TemplateController extends BaseController | @@ -59,7 +49,7 @@ class TemplateController extends BaseController | ||
| 59 | * @time 2023/5/5 9:30 | 49 | * @time 2023/5/5 9:30 |
| 60 | */ | 50 | */ |
| 61 | public function insert(){ | 51 | public function insert(){ |
| 62 | - $this->save(); | 52 | + $this->save(Scene::$CREATE); |
| 63 | } | 53 | } |
| 64 | 54 | ||
| 65 | 55 | ||
| @@ -72,47 +62,15 @@ class TemplateController extends BaseController | @@ -72,47 +62,15 @@ class TemplateController extends BaseController | ||
| 72 | * @author:dc | 62 | * @author:dc |
| 73 | * @time 2023/5/11 10:13 | 63 | * @time 2023/5/11 10:13 |
| 74 | */ | 64 | */ |
| 75 | - private function save($is_edit=false){ | 65 | + private function save($scene){ |
| 76 | 66 | ||
| 77 | - $verify = [ | ||
| 78 | - 'role' => [ | ||
| 79 | - 'id' => ['required','integer'], | ||
| 80 | - 'name' => ['required'], | ||
| 81 | - 'status' => ['required',Rule::in(0,1)], | ||
| 82 | - 'is_default' => ['required',Rule::in(0,1)], | ||
| 83 | - 'sort' => ['required','integer'], | ||
| 84 | - 'thumb' => ['required'], | ||
| 85 | - 'url' => ['required'], | ||
| 86 | - ], | ||
| 87 | - 'message' => [ | ||
| 88 | - 'id.required' => 'id必须', | ||
| 89 | - 'id.integer' => 'id必须', | ||
| 90 | 67 | ||
| 91 | - 'name.required' => '名称必须', | ||
| 92 | - 'status.integer' => '状态错误', | ||
| 93 | - 'status.in' => '状态错误', | ||
| 94 | - 'is_default.integer' => '是否默认', | ||
| 95 | - 'is_default.in' => '是否默认', | ||
| 96 | - 'sort.required' => '排序必须', | ||
| 97 | - 'sort.integer' => '排序必须', | ||
| 98 | - 'thumb.required' => '缩略图必须', | ||
| 99 | - 'url.required' => '预览链接必须', | ||
| 100 | - ] | ||
| 101 | - ]; | ||
| 102 | - if(!$is_edit) unset($verify['role']['id']); | ||
| 103 | - | ||
| 104 | - $data = $this->validate(request() ,$verify['role'],$verify['message']); | 68 | + $data = $this->verify(TemplateRequest::class,$scene); |
| 105 | 69 | ||
| 106 | 70 | ||
| 71 | + TemplateLogic::instance()->save($data); | ||
| 107 | 72 | ||
| 108 | - // 保存 | ||
| 109 | - $id = ATemplate::_save($data,$data['id']??0); | ||
| 110 | 73 | ||
| 111 | - if(!$id){ | ||
| 112 | - return $this->response('保存失败',Code::SYSTEM_ERROR); | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - return $this->success(ATemplate::_find($id)); | ||
| 116 | } | 74 | } |
| 117 | 75 | ||
| 118 | 76 | ||
| @@ -142,11 +100,9 @@ class TemplateController extends BaseController | @@ -142,11 +100,9 @@ class TemplateController extends BaseController | ||
| 142 | */ | 100 | */ |
| 143 | public function html_index($template_id){ | 101 | public function html_index($template_id){ |
| 144 | 102 | ||
| 103 | + $lists = (new ATemplate)->list($this->map,$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); | ||
| 104 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 145 | 105 | ||
| 146 | - $lists = ATemplateHtml::where('template_id',$template_id)->get(); | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - return $this->success($lists->toArray()); | ||
| 150 | } | 106 | } |
| 151 | 107 | ||
| 152 | 108 |
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside; | @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Helper\Common; | 6 | use App\Helper\Common; |
| 7 | use App\Http\Controllers\Controller; | 7 | use App\Http\Controllers\Controller; |
| 8 | +use App\Http\Requests\Scene; | ||
| 8 | use App\Models\User\User as UserModel; | 9 | use App\Models\User\User as UserModel; |
| 9 | use Illuminate\Http\JsonResponse; | 10 | use Illuminate\Http\JsonResponse; |
| 10 | use Illuminate\Http\Request; | 11 | use Illuminate\Http\Request; |
| @@ -101,21 +102,12 @@ class BaseController extends Controller | @@ -101,21 +102,12 @@ class BaseController extends Controller | ||
| 101 | */ | 102 | */ |
| 102 | public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse | 103 | public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse |
| 103 | { | 104 | { |
| 104 | - try { | ||
| 105 | $code = Code::fromValue($code); | 105 | $code = Code::fromValue($code); |
| 106 | $result = [ | 106 | $result = [ |
| 107 | 'msg' => $msg == ' ' ? $code->description : $msg, | 107 | 'msg' => $msg == ' ' ? $code->description : $msg, |
| 108 | 'code' => $code->value, | 108 | 'code' => $code->value, |
| 109 | 'data' => $this->_extents($data), | 109 | 'data' => $this->_extents($data), |
| 110 | ]; | 110 | ]; |
| 111 | - }catch (\Throwable $e){ | ||
| 112 | - $result = [ | ||
| 113 | - 'msg' => $msg, | ||
| 114 | - 'code' => $code, | ||
| 115 | - 'data' => $this->_extents($data), | ||
| 116 | - ]; | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | $this->header['Content-Type'] = $type; | 111 | $this->header['Content-Type'] = $type; |
| 120 | $this->header['token'] = $this->token; | 112 | $this->header['token'] = $this->token; |
| 121 | $response = response($result,$result_code,$this->header);; | 113 | $response = response($result,$result_code,$this->header);; |
| @@ -216,4 +208,18 @@ class BaseController extends Controller | @@ -216,4 +208,18 @@ class BaseController extends Controller | ||
| 216 | } | 208 | } |
| 217 | 209 | ||
| 218 | 210 | ||
| 211 | + /** | ||
| 212 | + * 验证 | ||
| 213 | + * @param $c | ||
| 214 | + * @param $scene | ||
| 215 | + * @return array | ||
| 216 | + * @author:dc | ||
| 217 | + * @time 2023/5/11 14:56 | ||
| 218 | + */ | ||
| 219 | + protected final function verify($c,$scene=null){ | ||
| 220 | + return (new $c())->setScene($scene?:Scene::$CREATE)->validated(); | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + | ||
| 224 | + | ||
| 219 | } | 225 | } |
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | use App\Enums\Common\Code; | 6 | use App\Enums\Common\Code; |
| 7 | +use App\Http\Requests\Bside\Nav\NavRequest; | ||
| 7 | use App\Models\BNav; | 8 | use App\Models\BNav; |
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| @@ -16,42 +17,6 @@ use App\Models\BNav; | @@ -16,42 +17,6 @@ use App\Models\BNav; | ||
| 16 | class NavController extends BaseController | 17 | class NavController extends BaseController |
| 17 | { | 18 | { |
| 18 | 19 | ||
| 19 | - /** | ||
| 20 | - * 验证规则 | ||
| 21 | - * @var array[] | ||
| 22 | - */ | ||
| 23 | - private $verify = [ | ||
| 24 | - 'role' => [ | ||
| 25 | - 'pid' => ['required','integer','gte:0'], | ||
| 26 | - 'name' => ['required','max:100'], | ||
| 27 | - 'location' => ['required','in:header,footer'], | ||
| 28 | - 'url' => ['required','max:200'], | ||
| 29 | - 'status' => ['required','in:0,1'], | ||
| 30 | - 'target' => ['required','in:0,1'], | ||
| 31 | - 'sort' => ['required','integer','gte:0'] | ||
| 32 | - ], | ||
| 33 | - 'message' => [ | ||
| 34 | - 'pid.required' => '上级选择错误', | ||
| 35 | - 'pid.gte' => '上级选择错误', | ||
| 36 | - 'pid.integer' => '上级选择错误', | ||
| 37 | - 'name.required' => '名称必须', | ||
| 38 | - 'name.max' => '名称不能超过100个字符', | ||
| 39 | - 'location.required' => '位置选择错误', | ||
| 40 | - 'location.in' => '位置选择错误', | ||
| 41 | - 'url.required' => '链接必须', | ||
| 42 | - 'url.max' => '链接不能超过200个字符', | ||
| 43 | - 'status.required' => '状态选择错误', | ||
| 44 | - 'status.in' => '状态必须是显示/隐藏', | ||
| 45 | - 'target.required' => '打开方式必须', | ||
| 46 | - 'target.in' => '打开方式选择错误', | ||
| 47 | - 'sort.required' => '排序必须', | ||
| 48 | - 'sort.integer' => '排序必须是一个数字', | ||
| 49 | - 'sort.gte' => '排序必须大于等于0', | ||
| 50 | - ], | ||
| 51 | - 'attr' => [ | ||
| 52 | - | ||
| 53 | - ] | ||
| 54 | - ]; | ||
| 55 | 20 | ||
| 56 | /** | 21 | /** |
| 57 | * 列表数据 | 22 | * 列表数据 |
| @@ -98,9 +63,7 @@ class NavController extends BaseController | @@ -98,9 +63,7 @@ class NavController extends BaseController | ||
| 98 | * @time 2023/5/8 17:06 | 63 | * @time 2023/5/8 17:06 |
| 99 | */ | 64 | */ |
| 100 | public function update(){ | 65 | public function update(){ |
| 101 | - $this->verify['role']['id'] = ['required','integer','gt:0']; | ||
| 102 | - $this->verify['message']['id.gt'] = $this->verify['message']['id.integer'] = $this->verify['message']['id.required'] = '编辑导航数据不存在'; | ||
| 103 | - return $this->save(); | 66 | + return $this->save(true); |
| 104 | } | 67 | } |
| 105 | 68 | ||
| 106 | /** | 69 | /** |
| @@ -112,8 +75,9 @@ class NavController extends BaseController | @@ -112,8 +75,9 @@ class NavController extends BaseController | ||
| 112 | * @author:dc | 75 | * @author:dc |
| 113 | * @time 2023/5/8 17:06 | 76 | * @time 2023/5/8 17:06 |
| 114 | */ | 77 | */ |
| 115 | - private function save(){ | ||
| 116 | - $data = $this->validate(request() ,$this->verify['role'],$this->verify['message']); | 78 | + private function save($edit=false){ |
| 79 | + | ||
| 80 | + $data = $this->verify(NavRequest::class,$edit?NavRequest::$UPDATE:null); | ||
| 117 | 81 | ||
| 118 | if($data['pid']){ | 82 | if($data['pid']){ |
| 119 | // 验证是否存在上级 | 83 | // 验证是否存在上级 |
| @@ -4,9 +4,7 @@ namespace App\Http\Controllers\file; | @@ -4,9 +4,7 @@ namespace App\Http\Controllers\file; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\type; | 6 | use App\Http\Controllers\type; |
| 7 | -use App\Http\Controllers\统一返回参数; | ||
| 8 | use App\Models\File\Image as ImageModel; | 7 | use App\Models\File\Image as ImageModel; |
| 9 | -use App\Models\User\User as UserModel; | ||
| 10 | use Illuminate\Http\Exceptions\HttpResponseException; | 8 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 11 | use Illuminate\Http\JsonResponse; | 9 | use Illuminate\Http\JsonResponse; |
| 12 | use Illuminate\Support\Facades\Storage; | 10 | use Illuminate\Support\Facades\Storage; |
| @@ -43,7 +41,16 @@ class ImageController | @@ -43,7 +41,16 @@ class ImageController | ||
| 43 | $this->path = $this->config['root'].$this->uploads['path'].'/'; | 41 | $this->path = $this->config['root'].$this->uploads['path'].'/'; |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | - public function index($hash = '',$type = self::TYPE, $w = 0 ,$h = 0 ){ | 44 | + /** |
| 45 | + * @param $hash | ||
| 46 | + * @param $w | ||
| 47 | + * @param $h | ||
| 48 | + * @name :index | ||
| 49 | + * @author :lyh | ||
| 50 | + * @method :post | ||
| 51 | + * @time :2023/5/11 17:19 | ||
| 52 | + */ | ||
| 53 | + public function index($hash = '', $w = 0 ,$h = 0 ){ | ||
| 47 | if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { | 54 | if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { |
| 48 | header("HTTP/1.1 304 Not Modified"); | 55 | header("HTTP/1.1 304 Not Modified"); |
| 49 | exit; | 56 | exit; |
| @@ -54,14 +61,13 @@ class ImageController | @@ -54,14 +61,13 @@ class ImageController | ||
| 54 | $this->response('指定图片不存在!', Code::USER_ERROR); | 61 | $this->response('指定图片不存在!', Code::USER_ERROR); |
| 55 | } | 62 | } |
| 56 | //查看缩略图是否存在 | 63 | //查看缩略图是否存在 |
| 57 | - $header['Content-Type'] = 'image/'.$info['type']; | ||
| 58 | $filename = $this->path . $info['hash'] . $w . '_' . $h; | 64 | $filename = $this->path . $info['hash'] . $w . '_' . $h; |
| 59 | if(is_file($filename)){ | 65 | if(is_file($filename)){ |
| 60 | $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; | 66 | $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; |
| 61 | $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], | 67 | $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], |
| 62 | - [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']); | 68 | + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']); |
| 63 | $content = file_get_contents($filename); | 69 | $content = file_get_contents($filename); |
| 64 | - $header['Content-Length'] = $info['size']; | 70 | + $header['Content-Length'] = strlen($content); |
| 65 | }else{ | 71 | }else{ |
| 66 | $path = $info['path']; | 72 | $path = $info['path']; |
| 67 | if (!is_file($path)) { | 73 | if (!is_file($path)) { |
| @@ -70,25 +76,18 @@ class ImageController | @@ -70,25 +76,18 @@ class ImageController | ||
| 70 | $content = ''; | 76 | $content = ''; |
| 71 | $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; | 77 | $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; |
| 72 | $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], | 78 | $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], |
| 73 | - [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']); | 79 | + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']); |
| 74 | if ($w > 0 && $h > 0) { | 80 | if ($w > 0 && $h > 0) { |
| 75 | $path = $this->cacheImage($info, $w, $h); | 81 | $path = $this->cacheImage($info, $w, $h); |
| 76 | $content = file_get_contents($path); | 82 | $content = file_get_contents($path); |
| 77 | $header['Content-Length'] = strlen($content); | 83 | $header['Content-Length'] = strlen($content); |
| 78 | } else { | 84 | } else { |
| 79 | $content = file_get_contents($path); | 85 | $content = file_get_contents($path); |
| 80 | - $header['Content-Length'] = $info['size']; | ||
| 81 | - } | 86 | + $header['Content-Length'] = strlen($content); |
| 82 | } | 87 | } |
| 83 | - $img_type = $info['type']; | ||
| 84 | - $content = base64_encode($content); | ||
| 85 | - $img_base64 = 'data:image/' . $img_type . ';base64,' . $content; | ||
| 86 | - if($type != self::TYPE){ | ||
| 87 | - header('Content-Type: image/' . $img_type); | ||
| 88 | - echo base64_decode($content); | ||
| 89 | - exit; | ||
| 90 | } | 88 | } |
| 91 | - return response($img_base64,200,$header); | 89 | + $header['Content-Type'] = 'image/'.$info['type']; |
| 90 | + return response($content,200,$header); | ||
| 92 | } | 91 | } |
| 93 | 92 | ||
| 94 | /** | 93 | /** |
| @@ -26,4 +26,15 @@ class BaseLogic extends Logic | @@ -26,4 +26,15 @@ class BaseLogic extends Logic | ||
| 26 | $this->user = Session::get('manage'); | 26 | $this->user = Session::get('manage'); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 获取实例 | ||
| 32 | + * @param mixed ...$params | ||
| 33 | + * @return static | ||
| 34 | + * @author:dc | ||
| 35 | + * @time 2023/5/11 15:23 | ||
| 36 | + */ | ||
| 37 | + public static function instance(...$params){ | ||
| 38 | + return new static(...$params); | ||
| 39 | + } | ||
| 29 | } | 40 | } |
| @@ -109,6 +109,9 @@ class BaseLogic extends Logic | @@ -109,6 +109,9 @@ class BaseLogic extends Logic | ||
| 109 | if($image_hash !== false){ | 109 | if($image_hash !== false){ |
| 110 | return $hash; | 110 | return $hash; |
| 111 | } | 111 | } |
| 112 | + $this->config = config('filesystems.disks.upload'); | ||
| 113 | + $this->uploads = config('upload.default_image'); | ||
| 114 | + $this->path = $this->config['root'].$this->uploads['path'].'/'; | ||
| 112 | $url = $this->path; | 115 | $url = $this->path; |
| 113 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 116 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); |
| 114 | $res = $files->move($url,$fileName); | 117 | $res = $files->move($url,$fileName); |
| @@ -99,7 +99,7 @@ class NewsLogic extends BaseLogic | @@ -99,7 +99,7 @@ class NewsLogic extends BaseLogic | ||
| 99 | } | 99 | } |
| 100 | //设置路由 | 100 | //设置路由 |
| 101 | RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); | 101 | RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); |
| 102 | - $this->model->edit($this->param,['id'=>$this->param['id']]); | 102 | + $this->edit($this->param,['id'=>$this->param['id']]); |
| 103 | DB::commit(); | 103 | DB::commit(); |
| 104 | }catch (\exception $e){ | 104 | }catch (\exception $e){ |
| 105 | DB::rollBack(); | 105 | DB::rollBack(); |
| @@ -94,29 +94,29 @@ class ATemplate extends \App\Models\Base{ | @@ -94,29 +94,29 @@ class ATemplate extends \App\Models\Base{ | ||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | 96 | ||
| 97 | - /** | ||
| 98 | - * @param array $data | ||
| 99 | - * @param int $id | ||
| 100 | - * @author:dc | ||
| 101 | - * @time 2023/5/11 10:08 | ||
| 102 | - */ | ||
| 103 | - public static function _save(array $data,int $id=0){ | ||
| 104 | - if($id){ | ||
| 105 | - $model = static::where('id',$id)->first(); | ||
| 106 | - } | ||
| 107 | - if(empty($model)) $model = new static(); | ||
| 108 | - | ||
| 109 | - $model->name = $data['name']; | ||
| 110 | - $model->status = $data['status']; | ||
| 111 | - $model->is_default = $data['is_default']; | ||
| 112 | - $model->sort = $data['sort']; | ||
| 113 | - $model->thumb = $data['thumb']; | ||
| 114 | - $model->url = $data['url']; | ||
| 115 | - | ||
| 116 | - $model->save(); | ||
| 117 | - | ||
| 118 | - return $model->id; | ||
| 119 | - } | 97 | +// /** |
| 98 | +// * @param array $data | ||
| 99 | +// * @param int $id | ||
| 100 | +// * @author:dc | ||
| 101 | +// * @time 2023/5/11 10:08 | ||
| 102 | +// */ | ||
| 103 | +// public static function _save(array $data,int $id=0){ | ||
| 104 | +// if($id){ | ||
| 105 | +// $model = static::where('id',$id)->first(); | ||
| 106 | +// } | ||
| 107 | +// if(empty($model)) $model = new static(); | ||
| 108 | +// | ||
| 109 | +// $model->name = $data['name']; | ||
| 110 | +// $model->status = $data['status']; | ||
| 111 | +// $model->is_default = $data['is_default']; | ||
| 112 | +// $model->sort = $data['sort']; | ||
| 113 | +// $model->thumb = $data['thumb']; | ||
| 114 | +// $model->url = $data['url']; | ||
| 115 | +// | ||
| 116 | +// $model->save(); | ||
| 117 | +// | ||
| 118 | +// return $model->id; | ||
| 119 | +// } | ||
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | 122 |
| @@ -260,6 +260,6 @@ Route::group([], function () { | @@ -260,6 +260,6 @@ Route::group([], function () { | ||
| 260 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); | 260 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); |
| 261 | // Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country'); | 261 | // Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country'); |
| 262 | Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); | 262 | Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); |
| 263 | - Route::any('/image/{hash}/{type?}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show'); | 263 | + Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show'); |
| 264 | Route::any('/file_hash/{hash}/', [\App\Http\Controllers\file\FileController::class,'index'])->name('file_show'); | 264 | Route::any('/file_hash/{hash}/', [\App\Http\Controllers\file\FileController::class,'index'])->name('file_show'); |
| 265 | }); | 265 | }); |
-
请 注册 或 登录 后发表评论