作者 lyh

gx

... ... @@ -5,8 +5,12 @@
* Date: 2024/02/26
* Time: 10:13
*/
namespace App\Console\Commands;
namespace App\Console\Commands\KeywordInVideo;
use App\Console\Commands\Model;
use App\Console\Commands\TaskSub;
use App\Models\Com\KeywordVideoTask;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Product\Keyword;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
... ... @@ -20,7 +24,7 @@ class VideoTask extends Command
*
* @var string
*/
protected $signature = 'VideoTask';
protected $signature = 'video_task';
/**
* The console command description.
... ... @@ -65,40 +69,39 @@ class VideoTask extends Command
{
$sub_task_num = $this->max_sub_task;
while (true) {
if ($sub_task_num <= 0)
if ($sub_task_num <= 0){
break;
$task_project = Model::where(['status' => Model::STATUS_OPEN])->orderBy('sort', 'desc')->first();
if (empty($task_project))
}
$task_project = KeywordVideoTask::where(['status' => KeywordVideoTask::STATUS_OPEN])->orderBy('sort', 'desc')->first();
if (empty($task_project)){
break;
$project = ProjectServer::useProject($task_project->project_id);
}
ProjectServer::useProject($task_project->project_id);
$keyword = $this->getProjectKeyword();
// 已经没有需要生成视频的关键词
if (FALSE == $keyword->isEmpty()) {
$task_project->status = Model::STATUS_CLOSE;
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
continue;
}
foreach ($keyword as $val) {
$log = TaskSub::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first();
if ($log)
$log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first();
if ($log){
continue;
}
$array = [
'project_id' => $task_project->project_id,
'keyword_id' => $val->id,
'keyword' => $val->title,
'data' => json_encode(['url' => '', 'description' => '', 'images' => [], 'keywords' => []]),
'status' => TaskSub::STATUS_INIT,
'status' => KeywordVideoTaskLog::STATUS_INIT,
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
];
TaskSub::insert($array);
KeywordVideoTaskLog::insert($array);
$sub_task_num--;
}
$task_project->status = Model::STATUS_CLOSE;
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
}
return true;
... ... @@ -110,7 +113,7 @@ class VideoTask extends Command
*/
public function sendSubTask()
{
$subTask = TaskSub::where(['status' => TaskSub::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get();
$subTask = KeywordVideoTaskLog::where(['status' => TaskSub::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get();
if ($subTask->isEmpty())
return true;
foreach ($subTask as $val) {
... ... @@ -129,7 +132,7 @@ class VideoTask extends Command
$result = Http::post('http://216.250.255.116:7866/create_task', $data);
$val->task_id = $task_id;
$val->status = TaskSub::STATUS_RUNING;
$val->status = STATUS_RUNING::STATUS_RUNING;
$val->request_result = $result;
$val->save();
}
... ...
<?php
/**
* @remark :
* @name :KeywordController.php
* @name :KeywordVideoController.php
* @author :lyh
* @method :post
* @time :2024/2/26 9:23
... ... @@ -11,9 +11,9 @@ namespace App\Http\Controllers\Aside\Com;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Com\PromotionKeyword;
use App\Models\Com\KeywordVideoTask;
class KeywordController extends BaseController
class KeywordVideoController extends BaseController
{
/**
* @remark :任务列表
... ... @@ -23,7 +23,7 @@ class KeywordController extends BaseController
* @time :2024/2/26 11:36
*/
public function lists(){
$keywordModel = new PromotionKeyword();
$keywordModel = new KeywordVideoTask();
$lists = $keywordModel->lists($this->map,$this->page,$this->row);
$this->response('success',Code::SUCCESS,$lists);
}
... ... @@ -43,7 +43,7 @@ class KeywordController extends BaseController
'project_id.required' => '项目唯一标识不为空',
'number.required' => 'number不为空',
]);
$keywordModel = new PromotionKeyword();
$keywordModel = new KeywordVideoTask();
$rs = $keywordModel->add($this->param);
if($rs === false){
$this->response('添加失败',Code::SYSTEM_ERROR);
... ... @@ -64,7 +64,7 @@ class KeywordController extends BaseController
], [
'id.required' => '主键标识不为空',
]);
$keywordModel = new PromotionKeyword();
$keywordModel = new KeywordVideoTask();
$rs = $keywordModel->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::SYSTEM_ERROR);
... ...
... ... @@ -15,7 +15,7 @@ use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* Class KeywordController
* Class KeywordVideoController
* @package App\Http\Controllers\Bside
* @author zbj
* @date 2023/4/15
... ...
<?php
/**
* @remark :
* @name :PromotionKeyword.php
* @name :KeywordVideoTask.php
* @author :lyh
* @method :post
* @time :2024/2/26 9:33
... ... @@ -11,7 +11,10 @@ namespace App\Models\Com;
use App\Models\Base;
class PromotionKeyword extends Base
class KeywordVideoTask extends Base
{
protected $table = 'gl_promotion_keyword';
const STATUS_OPEN = 0;
const STATUS_CLOSE = 1;//停止
protected $table = 'gl_promotion_keyword_task';
}
... ...
<?php
/**
* @remark :
* @name :KeywordVideoTask.php
* @author :lyh
* @method :post
* @time :2024/2/26 9:33
*/
namespace App\Models\Com;
use App\Models\Base;
class KeywordVideoTaskLog extends Base
{
const STATUS_INIT = 0;
const STATUS_RUNING = 0;
protected $table = 'gl_keyword_video_task_log';
}
... ...
... ... @@ -329,10 +329,10 @@ Route::middleware(['aloginauth'])->group(function () {
/**
* 生成视频的项目
*/
Route::prefix('promotion_keyword')->group(function () {
Route::any('/', [Aside\Com\KeywordController::class, 'lists'])->name('promotion_keyword_lists');
Route::any('/createKeywordTask', [Aside\Com\KeywordController::class, 'createKeywordTask'])->name('promotion_keyword_createKeywordTask');
Route::any('/edit', [Aside\Com\KeywordController::class, 'edit'])->name('promotion_keyword_edit');
Route::prefix('keyword_video')->group(function () {
Route::any('/', [Aside\Com\KeywordVideoController::class, 'lists'])->name('promotion_keyword_lists');
Route::any('/createKeywordTask', [Aside\Com\KeywordVideoController::class, 'createKeywordTask'])->name('promotion_keyword_createKeywordTask');
Route::any('/edit', [Aside\Com\KeywordVideoController::class, 'edit'])->name('promotion_keyword_edit');
});
// 公共主题模版
... ...