作者 李宇航

合并分支 'master-server' 到 'master'

修改视频模块脚本



查看合并请求 !669
... ... @@ -59,12 +59,12 @@ class VideoTask extends Command
*/
public function handle()
{
$number = $this->getVideoNumber();
Log::info('开始视频推广任务');
$number = KeywordVideoTaskLog::getMonthVideoNum();
if($number >= $this->max_num){
Log::info('当月以达到最大视频生成数,任务执行数:' . $number);
return true;
}
echo '开始:'.PHP_EOL;
Log::info('开始视频推广任务');
$this->createSubTask($number);
$this->sendSubTask();
Log::info('结束视频推广任务');
... ... @@ -72,31 +72,6 @@ class VideoTask extends Command
}
/**
* @remark :获取当月的数据总量
* @name :getVideoNumber
* @author :lyh
* @method :post
* @time :2024/7/12 18:02
*/
public function getVideoNumber()
{
$current_time = date('Y-m-d 00:00:00');
$number = Cache::get('video_keyword_number');
if(empty($number) || ($current_time == date('Y-m-13 00:00:00'))){
if($current_time <= date('Y-m-13 00:00:00')){
$startOfMonth = Carbon::now()->subMonth()->day(13)->format('Y-m-d 00:00:00');
$endOfMonth = Carbon::now()->day(13)->format('Y-m-d 00:00:00');
}else{
$startOfMonth = Carbon::now()->day(13)->format('Y-m-d 00:00:00');
$endOfMonth = Carbon::now()->addMonth()->day(13)->format('Y-m-d 00:00:00');
}
$taskLogModel = new KeywordVideoTaskLog();
$number = $taskLogModel->formatQuery(['created_at' => ['between', [$startOfMonth, $endOfMonth]]])->count();
Cache::put('video_keyword_number',$number);
}
return $number;
}
/**
* 创建子任务
* TODO 获取需要生成子任务的项目,获取项目中未生成视频的关键词,通过关键词生成初始化子任务
* @return bool
... ... @@ -108,6 +83,9 @@ class VideoTask extends Command
if ($sub_task_num <= 0){
break;
}
if($number >= $this->max_num){
break;
}
$task_project = KeywordVideoTask::where(['status' => KeywordVideoTask::STATUS_OPEN])->orderBy('sort', 'desc')->orderBy('id', 'desc')->first();
if (empty($task_project)){
break;
... ... @@ -154,9 +132,9 @@ class VideoTask extends Command
if($rs && ($sub_task_num > 0)){
$sub_task_num--;
}
Cache::put('video_keyword_number',$number++);
}
}
Cache::put('video_keyword_number_month',$number + count($keyword),3600);
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
}
... ...
... ... @@ -10,6 +10,8 @@
namespace App\Models\Com;
use App\Models\Base;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
class KeywordVideoTaskLog extends Base
{
... ... @@ -19,4 +21,26 @@ class KeywordVideoTaskLog extends Base
const STATUS_ERROR = 3;
protected $table = 'gl_keyword_video_task_log';
/**
* 获取当月视频生成数量
* FIXME 混剪视频订阅计划 50000/m
* @return mixed
*/
public static function getMonthVideoNum()
{
$key = 'video_keyword_number_month';
$num = Cache::get($key, function () use ($key) {
$this_day = date('d');
if($this_day >= 13) {
$start_date = Carbon::now()->day(13)->format('Y-m-d 00:00:00');
} else {
$start_date = Carbon::now()->subMonth()->day(13)->format('Y-m-d 00:00:00');
}
$num = self::where('created_at', '>', $start_date)->count();
Cache::put($key, $num, 3600);
return $num;
});
return $num;
}
}
... ...