作者 Your Name
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -18,7 +18,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeCount extends Command
class CountAll extends Command
{
/**
... ... @@ -26,7 +26,7 @@ class UpgradeCount extends Command
*
* @var string
*/
protected $signature = 'upgrade_counts';
protected $signature = 'count_all';
/**
* The console command description.
... ... @@ -37,7 +37,7 @@ class UpgradeCount extends Command
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
$list = $projectModel->list(['delete_status'=>0]);
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -20,7 +20,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeProjectCount extends Command
class CountProject extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
... ... @@ -29,7 +29,7 @@ class UpgradeProjectCount extends Command
*
* @var string
*/
protected $signature = 'upgrade_count {project_id}';
protected $signature = 'count_project {project_id}';
/**
* The console command description.
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -21,14 +21,14 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeCount extends Command
class MonthAllCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_month_counts';
protected $signature = 'month_all';
/**
* The console command description.
... ... @@ -88,7 +88,7 @@ class UpgradeCount extends Command
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = $project_id;
$res = $this->inquiry($url,$v['month']);
// $arr['month_total'] = 0;
$arr['total'] = 0;
if(isset($res['data']['count'])){
echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
$arr['month_total'] = $res['data']['count'];
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -21,14 +21,14 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeProjectCount extends Command
class MonthProjectCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_month_count {project_id}';
protected $signature = 'month_project {project_id}';
/**
* The console command description.
... ...
... ... @@ -28,23 +28,15 @@ class SyncSubmitTask extends Command
public function handle()
{
$backup = false;
while (true) {
$task_id = $this->getTaskId();
if ($task_id > 2000000) {
$backup = true;
}
if (empty($task_id)) {
if ($backup) {
$this->backup();
$backup = false;
}
sleep(5);
$task_id = Redis::rpop('sync_submit_task');
if(!$task_id){
sleep(3);
continue;
}
$this->output('任务' . $task_id . '开始');
$task_info = SyncSubmitTaskModel::find($task_id);
if (empty($task_info) || $task_info->status !=2) {
if (empty($task_info) || $task_info->status !=3) {
$this->output('任务不存在或者已执行');
continue;
}
... ... @@ -79,31 +71,6 @@ class SyncSubmitTask extends Command
}
}
public function getTaskId()
{
$task_id = Redis::rpop('sync_submit_task');
$lockKey = 'lock_sync_submit_task';
if (empty($task_id)) {
// 获取锁
if (Redis::setnx($lockKey, 1)) {
// 设置锁的过期时间,防止死锁
Redis::expire($lockKey, 10);
$tasks = SyncSubmitTaskModel::where('status', 0)->limit(100)->get();
foreach ($tasks as $task) {
$task->status = 2;
$task->save();
Redis::lpush('sync_submit_task', $task->id);
}
$task_id = Redis::rpop('sync_submit_task');
Redis::del($lockKey);
} else {
// 未获取到锁
return '';
}
}
return $task_id;
}
/**
* 输出处理日志
*/
... ... @@ -112,31 +79,4 @@ class SyncSubmitTask extends Command
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
/**
* 备份数据
* @author zbj
* @date 2024/1/23
*/
public function backup()
{
DB::beginTransaction();
try {
$table = (new SyncSubmitTaskModel())->getTable();
$new_table = $table . '_backup_' . date('Ymd');
//重命名当前表
Schema::rename($table, $new_table);
//克隆表数据
DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table);
DB::commit();
$this->output('数据备份成功');
} catch (\Exception $e) {
$this->output('数据备份失败' . $e->getMessage());
DB::rollBack();
}
return true;
}
}
... ...
<?php
namespace App\Console\Commands\Sync;
use App\Exceptions\InquiryFilterException;
use App\Models\Project\Project;
use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel;
use App\Services\SyncSubmitTaskService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
/**
*
* Class SyncSubmitTask
* @package App\Console\Commands
* @author zbj
* @date 2023/11/28
*/
class SyncSubmitTaskDistribution extends Command
{
protected $signature = 'sync_submit_task_distribution';
protected $description = '询盘、访问异步任务分发';
public function handle()
{
while (true) {
$len = Redis::llen('sync_submit_task');
if (!$len) {
$max_id = SyncSubmitTaskModel::orderBy('id', 'desc')->value('id');
if ($max_id > 2000000) {
$this->backup();
} else {
$tasks = SyncSubmitTaskModel::where('status', 0)->limit(100)->get();
foreach ($tasks as $task) {
$task->status = 3;
$task->save();
Redis::lpush('sync_submit_task', $task->id);
}
}
}
sleep(3);
}
}
/**
* 输出处理日志
*/
public function output($message): bool
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
/**
* 备份数据
* @author zbj
* @date 2024/1/23
*/
public function backup()
{
DB::beginTransaction();
try {
$table = (new SyncSubmitTaskModel())->getTable();
$new_table = $table . '_backup_' . date('Ymd');
//重命名当前表
Schema::rename($table, $new_table);
//克隆表数据
DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table);
//未入队的写到新表
$list = DB::table($new_table)->where('status', 0)->get();
$data = [];
foreach ($list as $task) {
$data[] = [
'type' => $task->type,
'data' => json_encode($task->data),
'created_at' => $task['created_at'],
'updated_at' => $task['updated_at'],
];
}
$data && SyncSubmitTaskModel::insert($data);
DB::commit();
$this->output('数据备份成功');
} catch (\Exception $e) {
$this->output('数据备份失败' . $e->getMessage());
DB::rollBack();
}
return $new_table ?? '';
}
}
... ...
... ... @@ -9,6 +9,7 @@ use App\Http\Logic\Bside\Product\KeywordLogic;
use App\Http\Requests\Bside\Product\KeywordRequest;
use App\Models\Com\NoticeLog;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordPage;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
... ... @@ -242,6 +243,20 @@ class KeywordController extends BaseController
* @time :2024/7/2 10:14
*/
public function batchUpdateKeyword(){
$noticeLogModel = new NoticeLog();
$this->request->validate([
'text'=>'required|array',
'update_object'=>'required|array',
'update_method'=>'required'
],[
'text.required' => '文件内容不能为空',
'update_object.required' => '更新对象不为空',
'update_object.array' => '更新对象为数组',
'update_method.required' => '请求方式不为空'
]);
$keywordPageModel = new KeywordPage();
$this->param['text'] = json_encode($this->param['text']);
$this->param['update_object'] = json_encode($this->param['update_object']);
$id = $keywordPageModel->addReturnId($this->param);
$this->response('success',Code::SUCCESS,['id'=>$id]);
}
}
... ...
<?php
/**
* @remark :
* @name :KeywordPage.php
* @author :lyh
* @method :post
* @time :2024/7/2 15:26
*/
namespace App\Models\Product;
use App\Models\Base;
class KeywordPage extends Base
{
protected $table = 'gl_product_keyword_page';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -271,6 +271,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd');
Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel');
Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
Route::any('keyword/batchUpdateKeyword', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchUpdateKeyword'])->name('product_keyword_batchUpdateKeyword');
Route::any('keyword/batchKeywordIsVideo', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordIsVideo'])->name('product_keyword_batchKeywordIsVideo');
Route::any('keyword/batchKeywordFiled', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordFiled'])->name('product_keyword_batchKeywordFiled');
//产品参数
... ...