SyncDramaInfo.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $dramaIds = null;
  29. if($drama_ids) {
  30. $dramaIds = explode(',', $drama_ids);
  31. }
  32. DB::table('video_wechat_check')
  33. ->when($dramaIds, function ($query, $dramaIds) {
  34. return $query->whereIn('drama_id', $dramaIds);
  35. })
  36. ->where('drama_id', '<>', 0)
  37. ->where([
  38. 'status' => 1,
  39. 'is_enabled' => 1
  40. ])
  41. ->select('drama_id', 'id', 'status', 'appid', 'video_id')
  42. ->orderBy('id')
  43. ->chunk(100, function ($items) {
  44. foreach ($items as $item) {
  45. $accessToken = $this->getAccessToken($item->appid ?: config('wechat.duanju.masterAppid'));
  46. $result = HttpRequestService::simplePost(WechatURL::vod_getdrama. $accessToken, [
  47. 'drama_id' => $item->drama_id
  48. ]);
  49. if(false === $result || (0 != ($result['errcode'] ?? 0))) {
  50. myLog('SyncDramaInfo')->error('获取剧目信息失败', [
  51. 'id' => $item->id, 'drama_id' => $item->drama_id,
  52. 'result' => $result,
  53. ]);
  54. continue;
  55. }
  56. $status = $result['drama_info']['audit_detail']['status'];
  57. $now = date('Y-m-d H:i:s');
  58. if($status != $item->status)
  59. {
  60. DB::table('video_wechat_check')
  61. ->where('id', $item->id)
  62. ->update([
  63. 'check_at' => date('Y-m-d H:i:s', $result['drama_info']['audit_detail']['audit_time']),
  64. 'status' => $status,
  65. 'updated_at' => $now,
  66. ]);
  67. }
  68. if(3 == $status) {
  69. DB::table('videos')
  70. ->where('id', $item->video_id)
  71. ->update([
  72. 'wechat_pass' => 1,
  73. 'updated_at' => $now,
  74. ]);
  75. }
  76. }
  77. });
  78. }
  79. private function getAccessToken($appid) {
  80. return Redis::get(AccessTokenService::getAccessTokenRedisKey($appid));
  81. }
  82. }