作者 lyh

gx

<?php
/**
* @remark :
* @name :DeleteProductCategory.php
* @author :lyh
* @method :post
* @time :2024/5/16 14:59
*/
namespace App\Console\Commands\DeleteCategory;
use Illuminate\Console\Command;
/**
* @remark :删除分类
* @name :DeleteProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:00
*/
class DeleteProductCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_product_category';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除产品关键字';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @remark :批量处理
* @name :handle
* @author :lyh
* @method :post
* @time :2024/5/16 15:02
*/
public function handle(){
}
}
... ...
... ... @@ -148,7 +148,6 @@ class BlogCategoryController extends BaseController
'id.array' => 'ID为数组',
]);
$blogCategoryLogic->delBlogCategory();
//TODO::写入操作日志
$this->response('success');
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Models\Blog\Blog;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\Com\NoticeLog;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
... ... @@ -94,15 +95,18 @@ class BlogCategoryLogic extends BaseLogic
* @method
*/
public function delBlogCategory(){
foreach ($this->param['id'] as $id){
//删除路由
$this->delRoute($id);
$this->model->del(['id'=>$id]);
//同步删除产品字段category_id
$blogModel = new Blog();
$blogModel->edit(['category_id'=>DB::raw("REPLACE(category_id, ',$id,' , ',')")],['category_id'=>['like','%,'.$id.',%']]);
$blogModel->edit(['category_id'=>null],['category_id'=>',']);
$ids = $this->param['id'];
foreach ($ids as $id){
$str = [];
$this->getAllSub($id,$str);
$str[] = $id;
foreach ($str as $value){
//删除路由
$this->delRoute($value);
$this->model->del(['id'=>$value]);
}
}
NoticeLog::createLog(NoticeLog::DELETE_BLOG_CATEGORY, ['project_id' => $this->user['project_id']]);
return $this->success();
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\News;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\NoticeLog;
use App\Models\News\News;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
... ... @@ -83,22 +84,27 @@ class NewsCategoryLogic extends BaseLogic
$this->edit($this->param,['id'=>$this->param['id']]);
return $this->success();
}
/**
* @name :删除新闻分类
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
* @remark :删除分类
* @name :del_news_category
* @author :lyh
* @method :post
* @time :2024/5/16 14:58
*/
public function del_news_category(){
foreach ($this->param['id'] as $id){
$this->delRoute($id);
$this->model->del(['id'=>$id]);
//同步删除产品字段category_id
$newsModel = new NewsModel();
$newsModel->edit(['category_id'=>DB::raw("REPLACE(category_id, ',$id,' , ',')")],['category_id'=>['like','%,'.$id.',%']]);
$newsModel->edit(['category_id'=>null],['category_id'=>',']);
$ids = $this->param['id'];
foreach ($ids as $id){
$str = [];
$this->getAllSub($id,$str);
$str[] = $id;
foreach ($str as $value){
//删除路由
$this->delRoute($value);
$this->model->del(['id'=>$value]);
}
}
NoticeLog::createLog(NoticeLog::DELETE_NEWS_CATEGORY, ['project_id' => $this->user['project_id']]);
return $this->success();
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Product;
use App\Helper\Arr;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\NoticeLog;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
... ... @@ -163,17 +164,16 @@ class CategoryLogic extends BaseLogic
public function categoryDelete(){
$ids = $this->param['ids'];
foreach ($ids as $id){
//删除路由
$this->delRoute($id);
$this->model->del(['id'=>$id]);
//同步删除关联表
$categoryRelatedModel = new CategoryRelated();
$categoryRelatedModel->del(['cate_id'=>$id]);
//同步删除产品字段category_id
$productModel = new Product();
$productModel->edit(['category_id'=>DB::raw("REPLACE(category_id, ',$id,' , ',')")],['category_id'=>['like','%,'.$id.',%']]);
$productModel->edit(['category_id'=>null],['category_id'=>',']);
$str = [];
$this->getAllSub($id,$str);
$str[] = $id;
foreach ($str as $value){
//删除路由
$this->delRoute($value);
$this->model->del(['id'=>$value]);
}
}
NoticeLog::createLog(NoticeLog::DELETE_PRODUCT_CATEGORY, ['project_id' => $this->user['project_id']]);
//清除缓存
Common::del_user_cache('product_category',$this->user['project_id']);
return $this->success();
... ...
... ... @@ -13,6 +13,9 @@ class NoticeLog extends Model
const TYPE_RANK_DATA = 'rank_data';
const TYPE_INIT_PROJECT = 'init_project';
const TYPE_INIT_KEYWORD = 'init_keyword';
const DELETE_PRODUCT_CATEGORY = 'delete_product_category';
const DELETE_BLOG_CATEGORY = 'delete_blog_category';
const DELETE_NEWS_CATEGORY = 'delete_news_category';
const STATUS_PENDING = 0;
const STATUS_SUCCESS = 1;
const STATUS_FAIL = 2;
... ...