SyncMediaInfo.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Console\Commands\Video\WechatCheck;
  3. use App\Service\Miniprogram\Wechat\AccessTokenService;
  4. use App\Service\Util\Support\Http\HttpRequestService;
  5. use App\Service\Util\Support\Http\WechatURL;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Redis;
  9. class SyncMediaInfo extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'WechatCheck:SyncMediaInfo {--video_ids= : videos.id}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '获取短剧分集详细信息';
  23. /**
  24. * Execute the console command.
  25. */
  26. public function handle()
  27. {
  28. $video_ids = $this->option('video_ids');
  29. $videoIds = [];
  30. if($video_ids) {
  31. $videoIds = explode(',', $video_ids);
  32. }
  33. DB::table('video_wechat_check')
  34. ->where('status', '<>', 0)
  35. ->where('is_enabled', 1)
  36. ->where('drama_id', '<>', 0)
  37. ->when($videoIds, function ($query, $videoIds) {
  38. return $query->whereIn('video_id', $videoIds);
  39. })->select('video_id', 'id', 'drama_id', 'appid')
  40. ->orderBy('id')
  41. ->chunk(10, function ($items) {
  42. foreach ($items as $item) {
  43. $this->syncInfo($item);
  44. }
  45. });
  46. }
  47. public function syncInfo($item) {
  48. $appid = $item->appid ?: config('wechat.duanju.masterAppid');
  49. $accessToken = Redis::get(AccessTokenService::getAccessTokenRedisKey($appid));
  50. $offset = 0;
  51. while (true) {
  52. $parsedContent = HttpRequestService::simplePost(WechatURL::vod_listmedia . $accessToken, [
  53. 'drama_id' => $item->drama_id,
  54. 'limit' => 100,
  55. 'offset' => $offset
  56. ]);
  57. $offset += 100;
  58. if(false === $parsedContent || (0 != $parsedContent['errcode'] ?? 0)) {
  59. myLog('SyncMediaInfo')->error('拉取短剧分集信息失败', [
  60. 'appid' => $appid,
  61. 'video_id' => $item->video_id, 'drama_id' => $item->drama_id,
  62. ]);
  63. break;
  64. }
  65. $media_info_list = $parsedContent['media_info_list'];
  66. $now = date('Y-m-d H:i:s');
  67. foreach ($media_info_list as $media_info) {
  68. $audit_detail = $media_info['audit_detail'];
  69. $media_id = $media_info['media_id'];
  70. DB::table('video_series_wechat_check')
  71. ->where(['video_id' => $item->video_id, 'is_enabled' => 1, 'media_id' => $media_id])
  72. ->update([
  73. 'check_status' => $audit_detail['status'],
  74. 'check_at' => date('Y-m-d H:i:s', $audit_detail['audit_time']),
  75. 'check_reason' => $audit_detail['check_reason'],
  76. 'evidence_material_id_list' => \json_encode($audit_detail['evidence_material_id_list']),
  77. 'updated_at' => $now,
  78. ]);
  79. }
  80. }
  81. }
  82. }