作者 liyuhang

gx

... ... @@ -102,13 +102,16 @@ class Common
* @author :liyuhang
* @method
*/
public static function del_user_cache($table,$id = '',$type = 'B'){
public static function del_user_cache($table,$id,$type = 'B'){
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
if (!empty($id)){
$key = 'cache_'.$table.'_'.$id.'_type';
if(is_array($id)){
foreach ($id as $v){
$key = 'cache_'.$table.'_'.$id.'_type';
Cache::store('file')->pull($key);
}
}else{
$key = 'cache_'.$table.'_*';
$key = 'cache_'.$table.'_'.$id.'_type';
}
Cache::store('file')->pull($key);
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Common;
use App\Http\Logic\Logic;
use App\Models\Image as ImageModel;
use Illuminate\Http\Request;
... ... @@ -89,6 +90,7 @@ class BaseLogic extends Logic
$map[] = ['project_id' => $this->user['project_id']];
return parent::delete($ids, $map);
}
/**
* @name :上传图片
* @return void
... ... @@ -121,4 +123,5 @@ class BaseLogic extends Logic
}
return $hash.$filename;
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Http\Logic\Bside\User\UserLogic;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
... ... @@ -101,10 +102,7 @@ class BlogCategoryLogic extends BaseLogic
$this->fail('当前分类名称已存在');
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
$this->edit($this->param,$this->param['id']);
return $this->success();
}
... ... @@ -115,9 +113,15 @@ class BlogCategoryLogic extends BaseLogic
* @method
*/
public function info_blog_category(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
//读取缓存
$info = Common::get_user_cache($this->model->getTable(),$this->param['id']);
if(empty($info)){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
//写入缓存
Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
}
return $this->success($info);
}
... ... @@ -143,7 +147,8 @@ class BlogCategoryLogic extends BaseLogic
* @method
*/
public function del_blog_category(){
foreach ($this->param['id'] as $v){
$ids = $this->param['id'];
foreach ($ids as $v){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$v],['id']);
if($rs !== false){
... ... @@ -157,10 +162,7 @@ class BlogCategoryLogic extends BaseLogic
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->response('error');
}
$this->del($this->param,$ids);
return $this->success();
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogLabel as BlogLabelModel;
... ... @@ -90,7 +91,8 @@ class BlogLabelLogic extends BaseLogic
* @method
*/
public function del_blog_label(){
foreach ($this->param['id'] as $v){
$ids = $this->param['id'];
foreach ($ids as $v){
//查看当前分内下是否有博客
$blogModel = new BlogModel();
$rs = $blogModel->read(['label_id'=>$v],['id']);
... ... @@ -103,6 +105,8 @@ class BlogLabelLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
//清除缓存
Common::del_user_cache($this->model->getTable(),$ids);
return $this->success();
}
}
... ...
... ... @@ -151,21 +151,20 @@ class BlogLogic extends BaseLogic
public function blog_info(){
//读取缓存
$info = Common::get_user_cache($this->model->getTable(),$this->param['id']);
if(!empty($info)){
return $this->success($info);
}
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
if(empty($info)){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
//获取分类名称
$blogCategoryLogic = new BlogCategoryLogic();
$info = $blogCategoryLogic->get_category_name($info);
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info = $blogLabelLogic->get_label_name($info);
//写入缓存
Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
}
//获取分类名称
$blogCategoryLogic = new BlogCategoryLogic();
$info = $blogCategoryLogic->get_category_name($info);
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info = $blogLabelLogic->get_label_name($info);
//写入缓存
Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
return $this->success($info);
}
... ... @@ -192,11 +191,14 @@ class BlogLogic extends BaseLogic
* @method
*/
public function blog_del(){
$ids = $this->param['id'];
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
//清除缓存
Common::del_user_cache($this->model->getTable(),$ids);
return $this->success();
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use \App\Helper\Common as CommonHelper;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
... ... @@ -300,4 +301,53 @@ class Logic
});
return $query;
}
/**
* @name :删除
* @return void
* @author :liyuhang
* @method
*/
public function del($map,$ids){
$rs = $this->model->del($map);
if($rs === false){
$this->fail('error');
}
CommonHelper::del_user_cache($this->model->getTable(),$ids);
$this->success();
}
/**
* @name :编辑
* @return void
* @author :liyuhang
* @method
*/
public function edit($map,$id){
$rs = $this->model->edit($map,['id'=>$id]);
if($rs === false){
$this->fail('error');
}
CommonHelper::del_user_cache($this->model->getTable(),$id);
$this->success();
}
/**
* @param $map
* @name :详情
* @author :liyuhang
* @method
*/
public function info($map){
$info = CommonHelper::get_user_cache($this->model->getTable(),$map['id']);
if(empty($info)){
$info = $this->model->read($map);
if($info === false){
$this->fail('error');
}
CommonHelper::set_user_cache($info,$this->model->getTable(),$map['id']);
}
$this->success($info);
}
}
... ...