NoticeUserCommand.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Console\Commands\Exports;
  3. use App\Models\User\UserModel;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Http\File;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Storage;
  8. class NoticeUserCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'export:notice_user';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '导出通知用户';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. //
  39. $uuid = uuid();
  40. $path = sprintf("media/%s", date('Y-m-d'));
  41. $local_file = sprintf("storage/app/public/%s.csv", $uuid);
  42. $fp = fopen($local_file, 'w');
  43. fputcsv($fp, [
  44. 'to_user',
  45. ]);
  46. //
  47. // $users = DB::connection("mysql_datalog")
  48. // ->table("datalog.app_user_visit_list")
  49. // ->where("version","1.1.1")
  50. // ->where("appid","wx3e6bb0f55902391b")
  51. // ->distinct()
  52. // ->pluck('user_id');
  53. // $users = DB::connection("mysql_datalog")
  54. // ->table('datalog.app_visit_user')
  55. // ->whereIn('user_id',$users)
  56. // ->pluck('uid');
  57. $users = DB::table('ta_users')->pluck('uid');
  58. foreach ($users as $uid) {
  59. $user = UserModel::find($uid);
  60. fputcsv($fp, [
  61. json_encode($user->getAuth()),
  62. ]);
  63. }
  64. fclose($fp);
  65. $file = new File($local_file);
  66. $file = Storage::disk('oss')->putFileAs($path, $file, $uuid . '.' . $file->getExtension());
  67. $fileUrl = Storage::disk('oss')->url($file);
  68. dd($fileUrl);
  69. return $fileUrl;
  70. }
  71. }