作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

<?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\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 DeleteBlogCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_blog_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_BLOG_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;
$blogModel = new Blog();
while (true){
$blogList = $blogModel->lists(['status'=>1],$page,1000,'id',['id','category_id']);
if(empty($blogList) || empty($blogList['list'])){
return false;
}
foreach ($blogList['list'] as $v){
$category_id_arr = Arr::setToArr(trim($v['category_id'],','));
if(empty($category_id_arr)){
continue;
}
$categoryModel = new BlogCategory();
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).',' : '';
$blogModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
<?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\Com\NoticeLog;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
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;
}
}
... ...
<?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\Com\NoticeLog;
use App\Models\News\News;
use App\Models\News\NewsCategory;
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 DeleteNewsCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_news_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_NEWS_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;
$newsModel = new News();
while (true){
$newsList = $newsModel->lists(['status'=>1],$page,1000,'id',['id','category_id']);
if(empty($newsList) || empty($newsList['list'])){
return false;
}
foreach ($newsList['list'] as $v){
$category_id_arr = Arr::setToArr(trim($v['category_id'],','));
if(empty($category_id_arr)){
continue;
}
$categoryModel = new NewsCategory();
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).',' : '';
$newsModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
... ... @@ -9,8 +9,15 @@
namespace App\Console\Commands\DeleteCategory;
use App\Helper\Arr;
use App\Models\Com\NoticeLog;
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 :删除分类
... ... @@ -33,7 +40,7 @@ class DeleteProductCategory extends Command
*
* @var string
*/
protected $description = '删除产品关键字';
protected $description = '删除产品分类';
/**
* Create a new command instance.
... ... @@ -55,13 +62,68 @@ class DeleteProductCategory extends Command
public function handle(){
while (true){
$noticeLogModel = new NoticeLog();
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_PRODUCT_CATEGORY],'id',['*'],'asc','100');
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_PRODUCT_CATEGORY],'id',['*'],'asc',100);
if(empty($list)){
sleep(100);
}
foreach ($list as $v){
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;
while (true){
$productModel = new Product();
$productList = $productModel->lists(['status'=>1],$page,1000,'id',['id','category_id']);
if(empty($productList) || empty($productList['list'])){
return false;
}
foreach ($productList['list'] as $v){
$categoryRelatedModel = new CategoryRelated();
if(empty($v['category_id'])){
$categoryRelatedModel->del(['product_id'=>$v['id']]);
continue;
}
$category_id_arr = $v['category_id'];
$categoryModel = new Category();
foreach ($category_id_arr as $k=>$cate_id){
$cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
if($cateInfo == false){
//删除关联表
$categoryRelatedModel->del(['cate_id'=>$cate_id]);
unset($category_id_arr[$k]);
}
}
$str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
$productModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
... ... @@ -62,7 +62,10 @@ class ReplaceHtml extends Command
while (true){
$replaceHtmlModel = new TemplateReplaceHtml();
$replaceHtmlList = $replaceHtmlModel->list(['status'=>$replaceHtmlModel::STATUS]);
if(!empty($replaceHtmlList)){
if(empty($replaceHtmlList)){
sleep(100);
return true;
}
foreach ($replaceHtmlList as $v){
ProjectServer::useProject($v['project_id']);
echo '开始,任务id:'.$v['id'].PHP_EOL;
... ... @@ -76,8 +79,6 @@ class ReplaceHtml extends Command
echo '结束'.PHP_EOL;
DB::disconnect('custom_mysql');
}
}
sleep(5);
return true;
}
}
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\CustomModule;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\NoticeLog;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\RouteMap\RouteMap;
... ... @@ -190,14 +191,16 @@ class CustomModuleCategoryLogic extends BaseLogic
public function categoryDel(){
$ids = $this->param['id'];
foreach ($ids as $id){
$str = [];
$this->getAllSub($id,$str);
$str[] = $id;
foreach ($str as $value){
//删除路由
$this->delRoute($id);
$this->model->del(['id'=>$id]);
//同步删除产品字段category_id
$contentModel = new CustomModuleContent();
$contentModel->edit(['category_id'=>DB::raw("REPLACE(category_id, ',$id,' , ',')")],['category_id'=>['like','%,'.$id.',%']]);
$contentModel->edit(['category_id'=>null],['category_id'=>',']);
$this->delRoute($value);
$this->model->del(['id'=>$value]);
}
}
NoticeLog::createLog(NoticeLog::DELETE_CUSTOM_CATEGORY, ['project_id' => $this->user['project_id']]);
return $this->success();
}
... ...
... ... @@ -17,6 +17,7 @@ class NoticeLog extends Base
const DELETE_PRODUCT_CATEGORY = 'delete_product_category';
const DELETE_BLOG_CATEGORY = 'delete_blog_category';
const DELETE_NEWS_CATEGORY = 'delete_news_category';
const DELETE_CUSTOM_CATEGORY = 'delete_custom_category';
const STATUS_PENDING = 0;
const STATUS_SUCCESS = 1;
const STATUS_FAIL = 2;
... ...
... ... @@ -21,7 +21,7 @@ class Visit extends Base
//连接数据库
protected $connection = 'custom_mysql';
protected $appends = ['device_text'];
// protected $fillable = ['id','ip','device_port','country','city','url','referrer_url','depth','domain','updated_date', 'created_at'];
protected $fillable = ['id','ip','device_port','country','city','url','referrer_url','depth','domain','updated_date', 'created_at'];
const DEVICE_PC = 1;
const DEVICE_MOBILE = 2;
... ...