作者 刘锟

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

<?php
/**
* @remark :
* @name :GenerateVideo.php
* @author :lyh
* @method :post
* @time :2024/2/26 11:47
*/
namespace App\Console\Commands\KeywordInVideo;
use Illuminate\Console\Command;
class GenerateVideo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'generate_video';
/**
* The console command description.
*
* @var string
*/
protected $description = '根据关键词生成视频';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle()
{
}
}
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/02/26
* Time: 10:13
*/
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;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class VideoTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'video_task';
/**
* The console command description.
*
* @var string
*/
protected $description = '视频推广任务';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @var int 最大子任务
*/
public $max_sub_task = 800;
/**
* @return bool
*/
public function handle()
{
Log::info('开始视频推广任务');
$this->createSubTask();
$this->sendSubTask();
Log::info('结束视频推广任务');
return true;
}
/**
* 创建子任务
* TODO 获取需要生成子任务的项目,获取项目中未生成视频的关键词,通过关键词生成初始化子任务
* @return bool
*/
public function createSubTask()
{
$sub_task_num = $this->max_sub_task;
while (true) {
if ($sub_task_num <= 0){
break;
}
$task_project = KeywordVideoTask::where(['status' => KeywordVideoTask::STATUS_OPEN])->orderBy('sort', 'desc')->first();
if (empty($task_project)){
break;
}
ProjectServer::useProject($task_project->project_id);
$keyword = $this->getProjectKeyword();
// 已经没有需要生成视频的关键词
if (FALSE == $keyword->isEmpty()) {
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
continue;
}
foreach ($keyword as $val) {
$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' => KeywordVideoTaskLog::STATUS_INIT,
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
];
KeywordVideoTaskLog::insert($array);
$sub_task_num--;
}
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
}
return true;
}
/**
* 发送子任务
* @return bool
*/
public function sendSubTask()
{
$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) {
$task_id = 'v6-' . uniqid();
$data = [
'project_data' => [
'tag_url' => '',
'title' => '',
'keywords' => [],
'description' => '',
'images' => ''
],
'task_id' => $task_id,
'callback_url' => '',
];
$result = Http::post('http://216.250.255.116:7866/create_task', $data);
$val->task_id = $task_id;
$val->status = STATUS_RUNING::STATUS_RUNING;
$val->request_result = $result;
$val->save();
}
return true;
}
/**
* 获取未生成页面的关键词
* @return mixed
*/
public function getProjectKeyword()
{
$keyword = Keyword::where('video', null)->whereNotNull('keyword_content')->inRandomOrder()->take(100)->get();
return $keyword;
}
/**
* 获取需要处理的任务
* @return int
*/
public function getTaskProject()
{
// $task_project = Model::where(['status' => Model::STATUS_OPEN])->orderBy('sort', 'desc')->first();
$project_id = 110;
return $project_id;
}
}
... ...
<?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
... ...
... ... @@ -153,6 +153,7 @@ class MonthCountLogic extends BaseLogic
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->where('referrer_url','!=','')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = $source;
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Logic\Bside\Scoring;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Scoring\RatingQuestion;
use App\Models\Scoring\ScoringSystem;
use AWS\CRT\Log;
class RatingLogic extends BaseLogic
{
... ... @@ -77,6 +78,9 @@ class RatingLogic extends BaseLogic
}
$str = trim($str,'&');
$url = "http://www.quanqiusou.cn/extend_api/api/service_score.php?postid=$postId&token=$token&ftype=$fType&$str";
return http_get($url,['charset=utf-8']);
$rs = http_get($url,['charset=utf-8']);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($url, true) . PHP_EOL, FILE_APPEND);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($rs, true) . PHP_EOL, FILE_APPEND);
return $rs;
}
}
... ...
... ... @@ -228,11 +228,13 @@ class TranslateLogic extends BaseLogic
*/
public function translateSave(){
$data = [];
//处理传递的data
foreach ($this->param['data'] as $k => $v){
if(!empty($v) && is_array($v)){
foreach ($v as $text => $translate){
$data[$text] = $translate;
if(!empty($this->param['data'])){
//处理传递的data
foreach ($this->param['data'] as $k => $v){
if(!empty($v) && is_array($v)){
foreach ($v as $text => $translate){
$data[$text] = $translate;
}
}
}
}
... ...
<?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');
});
// 公共主题模版
... ...