作者 zhl

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

@@ -59,12 +59,13 @@ class VideoTask extends Command @@ -59,12 +59,13 @@ class VideoTask extends Command
59 */ 59 */
60 public function handle() 60 public function handle()
61 { 61 {
62 - $number = $this->getVideoNumber(); 62 + Log::info('开始视频推广任务');
  63 + $number = KeywordVideoTaskLog::getMonthVideoNum();
63 if($number >= $this->max_num){ 64 if($number >= $this->max_num){
  65 + Log::info('当月以达到最大视频生成数,任务执行数:' . $number);
64 return true; 66 return true;
65 } 67 }
66 - echo '开始:'.PHP_EOL;  
67 - Log::info('开始视频推广任务'); 68 +
68 $this->createSubTask($number); 69 $this->createSubTask($number);
69 $this->sendSubTask(); 70 $this->sendSubTask();
70 Log::info('结束视频推广任务'); 71 Log::info('结束视频推广任务');
@@ -10,6 +10,8 @@ @@ -10,6 +10,8 @@
10 namespace App\Models\Com; 10 namespace App\Models\Com;
11 11
12 use App\Models\Base; 12 use App\Models\Base;
  13 +use Illuminate\Support\Carbon;
  14 +use Illuminate\Support\Facades\Cache;
13 15
14 class KeywordVideoTaskLog extends Base 16 class KeywordVideoTaskLog extends Base
15 { 17 {
@@ -19,4 +21,26 @@ class KeywordVideoTaskLog extends Base @@ -19,4 +21,26 @@ class KeywordVideoTaskLog extends Base
19 const STATUS_ERROR = 3; 21 const STATUS_ERROR = 3;
20 22
21 protected $table = 'gl_keyword_video_task_log'; 23 protected $table = 'gl_keyword_video_task_log';
  24 +
  25 + /**
  26 + * 获取当月视频生成数量
  27 + * FIXME 混剪视频订阅计划 50000/m
  28 + * @return mixed
  29 + */
  30 + public static function getMonthVideoNum()
  31 + {
  32 + $key = 'video_keyword_number_month';
  33 + $num = Cache::get($key, function () use ($key) {
  34 + $this_day = date('d');
  35 + if($this_day >= 13) {
  36 + $start_date = Carbon::now()->day(13)->format('Y-m-d 00:00:00');
  37 + } else {
  38 + $start_date = Carbon::now()->subMonth()->day(13)->format('Y-m-d 00:00:00');
  39 + }
  40 + $num = self::where('created_at', '>', $start_date)->count();
  41 + Cache::put($key, $num, 1800);
  42 + return $num;
  43 + });
  44 + return $num;
  45 + }
22 } 46 }