作者 lyh

Merge branch 'dev' into develop

... ... @@ -41,6 +41,15 @@ class ImageController
$this->path = $this->config['root'].$this->uploads['path'].'/';
}
/**
* @param $hash
* @param $w
* @param $h
* @name :index
* @author :lyh
* @method :post
* @time :2023/5/11 17:19
*/
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");
... ... @@ -58,7 +67,7 @@ class ImageController
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
$content = file_get_contents($filename);
$header['Content-Length'] = $info['size'];
$header['Content-Length'] = strlen($content);
}else{
$path = $info['path'];
if (!is_file($path)) {
... ... @@ -78,10 +87,7 @@ class ImageController
}
}
$header['Content-Type'] = 'image/'.$info['type'];
$img_type = $info['type'];
$content = base64_encode($content);
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
return response($img_base64,200,$header);
return response($content,200,$header);
}
/**
... ...
... ... @@ -59,19 +59,19 @@ class NewsLogic extends BaseLogic
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s',time());
$this->param['updated_at'] = date('Y-m-d H:i:s',time());
// DB::beginTransaction();
// try {
DB::beginTransaction();
try {
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data;
}
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('添加失败');
// }
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加失败');
}
return $this->success();
}
... ...