SocialSync.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Logics\Admin\SocialLogic;
  4. use App\Http\Models\Article;
  5. use App\Http\Models\Site;
  6. use App\Http\Models\SocialPublish;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Support\Facades\Log;
  9. class SocialSync extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'social:sync {type=0}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'Command description';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $type = $this->argument('type');
  40. $social = new SocialLogic();
  41. $sitesMap = Site::query()->select(['id', 'facebook_page', 'facebook_page_token'])->get()->keyBy('id')->toArray();
  42. if ($type == 2) {
  43. $records = SocialPublish::query()->where([
  44. ['publish_at', '<', date('Y-m-d H:i:s')],
  45. ['social_sync_at', '=', null]
  46. ])->get();
  47. foreach ($records as $record) {
  48. list($err, $resultStatus) = $social->publish($record, $sitesMap);
  49. // $article->social_result = $result;
  50. $record->err = $err;
  51. $record->result_status = $resultStatus;
  52. $record->social_sync_at = date('Y-m-d H:i:s');
  53. $record->save();
  54. }
  55. }
  56. $this->info('success');
  57. return;
  58. }
  59. }