GetTaskInfo.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\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. use Modules\Common\Support\Http\HttpRequest;
  10. use Modules\Manage\Services\WechatMiniprogramService;
  11. use Modules\Video\Services\WechatCheckSyncService;
  12. class GetTaskInfo extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'WechatCheck:GetTaskInfo {--task_ids= : 英文逗号分割的任务id}';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '查询短剧同步到微信的任务状态';
  26. /**
  27. * Execute the console command.
  28. */
  29. public function handle(): void
  30. {
  31. $task_ids = $this->option('task_ids');
  32. $taskIdArr = null;
  33. if($task_ids) {
  34. $taskIdArr = explode(',', trim($task_ids, ','));
  35. }
  36. DB::table('video_series_wechat_check')
  37. ->whereIn('sync_status', [1,2])
  38. ->where('sync_task_id', '<>', '')
  39. ->where('is_enabled', 1)
  40. ->when($taskIdArr, function ($query, $taskIdArr) {
  41. return $query->whereIn('task_id', $taskIdArr);
  42. })->orderBy('id', 'asc')
  43. ->chunk(100, function ($items) {
  44. $now = date('Y-m-d H:i:s');
  45. foreach ($items as $item) {
  46. $taskInfo = $this->getTask($item);
  47. if($taskInfo && 1 == $taskInfo['task_type']) {
  48. if(in_array($taskInfo['status'], [3,4])) {
  49. DB::table('video_series_wechat_check')
  50. ->where(['id' => $item->id])
  51. ->update([
  52. 'status' => $taskInfo['status'],
  53. 'remark' => $taskInfo['errmsg'] ?? '',
  54. 'media_id' => $taskInfo['media_id'] ?? '',
  55. 'updated_at' => $now,
  56. 'sync_task_info' => \json_encode($taskInfo),
  57. ]);
  58. }
  59. }
  60. }
  61. });
  62. }
  63. private function getTask($syncInfo) {
  64. $appid = $syncInfo->appid ?: config('wechat.duanju.masterAppid');
  65. $accessToken = Redis::get(AccessTokenService::getAccessTokenRedisKey($appid));
  66. $parsedContent = HttpRequestService::simplePost(WechatURL::vod_gettask . $accessToken, [
  67. 'task_id' => $syncInfo->sync_task_id
  68. ]);
  69. if(false === $parsedContent || (0 != $parsedContent['errcode'] ?? 0)) {
  70. return $parsedContent['task_info'];
  71. } else {
  72. myLog('GetTaskInfo')->error('拉取上传短剧任务查询失败', [
  73. 'task_id' => $syncInfo->sync_task_id,
  74. 'appid' => $appid,
  75. 'result' => $parsedContent,
  76. ]);
  77. return [];
  78. }
  79. }
  80. }