|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :DeleteProductCategory.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/16 14:59
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands\DeleteCategory;
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Models\Blog\Blog;
|
|
|
|
use App\Models\Blog\BlogCategory;
|
|
|
|
use App\Models\Com\NoticeLog;
|
|
|
|
use App\Models\CustomModule\CustomModuleCategory;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\News\News;
|
|
|
|
use App\Models\News\NewsCategory;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除分类
|
|
|
|
* @name :DeleteProductCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/16 15:00
|
|
|
|
*/
|
|
|
|
class DeleteCustomCategory extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'delete_custom_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(){
|
|
|
|
while (true){
|
|
|
|
$noticeLogModel = new NoticeLog();
|
|
|
|
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_CUSTOM_CATEGORY],'id',['*'],'asc',100);
|
|
|
|
if(empty($list)){
|
|
|
|
sleep(100);
|
|
|
|
}
|
|
|
|
foreach ($list as $item){
|
|
|
|
echo 'start:' . $item['id'] . PHP_EOL;
|
|
|
|
try {
|
|
|
|
$projectModel = new Project();
|
|
|
|
$projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]);
|
|
|
|
if($projectInfo === false){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ProjectServer::useProject($projectInfo['id']);
|
|
|
|
$this->updateCategory();
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
$noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]);
|
|
|
|
echo 'success:' . $item['id'] . PHP_EOL;
|
|
|
|
}catch (\Exception $e){
|
|
|
|
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
|
|
|
|
errorLog('项目初始化失败', $item, $e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :更新分类
|
|
|
|
* @name :updateProductCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/16 15:38
|
|
|
|
*/
|
|
|
|
public function updateCategory(){
|
|
|
|
$page = 1;
|
|
|
|
$customModel = new CustomModuleContent();
|
|
|
|
while (true){
|
|
|
|
$customList = $customModel->lists(['status'=>0],$page,1000,'id',['id','category_id']);
|
|
|
|
if(empty($customList) || empty($customList['list'])){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach ($customList['list'] as $v){
|
|
|
|
$category_id_arr = Arr::setToArr(trim($v['category_id'],','));
|
|
|
|
if(empty($category_id_arr)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$categoryModel = new CustomModuleCategory();
|
|
|
|
foreach ($category_id_arr as $k=>$cate_id){
|
|
|
|
$cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
|
|
|
|
if($cateInfo == false){
|
|
|
|
//删除关联表
|
|
|
|
unset($category_id_arr[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
|
|
|
|
$customModel->edit(['category_id'=>$str],['id'=>$v['id']]);
|
|
|
|
}
|
|
|
|
$page++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|