123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace App\Console\Commands\Star;
- use App\Models\JxStarVideoTaskList;
- use App\Services\RdsLockService;
- use App\Support\Log;
- use App\Support\RedisModel;
- use Illuminate\Console\Command;
- class VideoTaskDataInDb extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'Star:VideoTaskDataInDb';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '星视频任务数据入库';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $this->info(date('H:i') . ' 开始执行');
- $this->start();
- $this->info(date('H:i') . ' 结束执行');
- return 0;
- }
- public function start()
- {
- $curTime = time();
- while (true) {
- if ((time() - $curTime) >= 60) break;
- $dataJson = RedisModel::rPop(JxStarVideoTaskList::JUXING_STAR_VIDEO_TASK_INDB_LIST);
- if (empty($dataJson)) {
- sleep(2);
- continue;
- }
- $data = json_decode($dataJson, true);
- if (!isset($data['advertiser_id'], $data['data'])) {
- # 输出错误日志
- Log::error('数据参数不合法', $data, 'Star:VideoTaskDataInDb');
- continue;
- }
- $this->taskDataInDb($data);
- }
- }
- public function taskDataInDb($data)
- {
- $advertiserId = $data['advertiser_id'];
- $dataVal = $data['data'];
- $taskId = $dataVal['task_id'] ?? null;
- if (empty($taskId)) {
- # 输出错误日志
- Log::error('taskId 为空', $data, 'Star:VideoTaskDataInDb');
- return false;
- }
- $lockKey = RdsLockService::getRdsLockKey([
- 'starVideo', $advertiserId, $taskId
- ]);
- if (RdsLockService::addRdsLock($lockKey)) {
- $taskInfo = JxStarVideoTaskList::query()
- ->where('advertiser_id', $advertiserId)
- ->where('task_id', $taskId)
- ->where('enable', 1)
- ->first();
- if (empty($taskInfo)) {
- $taskInfo = new JxStarVideoTaskList([
- 'advertiser_id' => $advertiserId,
- 'task_id' => $taskId
- ]);
- }
- $taskInfo->task_name = $dataVal['task_name'] ?? null;
- $taskInfo->task_status = $dataVal['task_status'] ?? null;
- $taskInfo->promotion_days = $dataVal['promotion_days'] ?? null;
- $taskInfo->task_type = $dataVal['task_type'] ?? null;
- $taskInfo->ios_url = $dataVal['ios_url'] ?? null;
- $taskInfo->ios_app_name = $dataVal['ios_app_name'] ?? null;
- $taskInfo->android_url = $dataVal['android_url'] ?? null;
- $taskInfo->android_app_name = $dataVal['android_app_name'] ?? null;
- $taskInfo->package_name = $dataVal['package_name'] ?? null;
- $taskInfo->app_icon_url = $dataVal['app_icon_url'] ?? null;
- $taskInfo->ad_description = $dataVal['ad_description'] ?? null;
- $taskInfo->guide_word = $dataVal['guide_word'] ?? null;
- $taskInfo->url = $dataVal['url'] ?? null;
- $taskInfo->title = $dataVal['title'] ?? null;
- $taskInfo->rel_item_id = $dataVal['rel_item_id'] ?? null;
- $taskInfo->taobao_pid = $dataVal['taobao_pid'] ?? null;
- $taskInfo->suning_pid = $dataVal['suning_pid'] ?? null;
- $taskInfo->auction_id = $dataVal['auction_id'] ?? null;
- $taskInfo->top_type = $dataVal['top_type'] ?? null;
- $taskInfo->app_link = $dataVal['app_link'] ?? null;
- $taskInfo->create_time = $dataVal['create_time'] ?? null;
- $taskInfo->third_cover_click_monitor = isset($dataVal['third_cover_click_monitor'])
- ? json_encode($dataVal['third_cover_click_monitor']) : null;
- $taskInfo->third_behavior_click_monitor = isset($dataVal['third_behavior_click_monitor'])
- ? json_encode($dataVal['third_behavior_click_monitor']) : null;
- $taskInfo->save();
- RdsLockService::delRdsLock($lockKey);
- }
- // Log::info('任务数据入库成功', ['taskId' => $taskId], 'Star:VideoTaskDataInDb');
- return 0;
- }
- }
|