WechatCheckGetTask.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Console\Commands\Video;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Modules\Video\Services\WechatCheckSyncService;
  6. class WechatCheckGetTask extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'Video:WechatCheckGetTask {--task_ids= : 英文逗号分割的任务id}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '查询短剧同步到微信的任务状态';
  20. /**
  21. * Execute the console command.
  22. */
  23. public function handle(): void
  24. {
  25. $task_ids = $this->option('task_ids');
  26. $taskIdArr = null;
  27. if($task_ids) {
  28. $taskIdArr = explode(',', trim($task_ids, ','));
  29. }
  30. DB::table('video_series_wechat_check')
  31. ->whereIn('sync_status', [1,2])
  32. ->where('sync_task_id', '<>', '')
  33. ->where('is_enabled', 1)
  34. ->when($taskIdArr, function ($query, $taskIdArr) {
  35. return $query->whereIn('task_id', $taskIdArr);
  36. })->orderBy('id', 'asc')
  37. ->chunk(100, function ($items) {
  38. $now = date('Y-m-d H:i:s');
  39. foreach ($items as $item) {
  40. $taskInfo = WechatCheckSyncService::getTask($item);
  41. if($taskInfo && 1 == $taskInfo['task_type']) {
  42. if(in_array($taskInfo['status'], [3,4])) {
  43. DB::table('video_series_wechat_check')
  44. ->where(['id' => $item->id])
  45. ->update([
  46. 'status' => $taskInfo['status'],
  47. 'remark' => $taskInfo['errmsg'] ?? '',
  48. 'media_id' => $taskInfo['media_id'] ?? '',
  49. 'updated_at' => $now,
  50. 'sync_task_info' => \json_encode($taskInfo),
  51. ]);
  52. }
  53. }
  54. }
  55. });
  56. }
  57. }