SyncDramaInfo.php 3.1 KB

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