作者 zhl

修改获取视频任务数量缓存

... ... @@ -59,12 +59,13 @@ 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('结束视频推广任务');
... ...
... ... @@ -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, 1800);
return $num;
});
return $num;
}
}
... ...