SyncOss.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Storage;
  5. class SyncOss extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'sync:oss';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '图片同步到腾讯云OSS';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. // 同步头像
  36. // $this->syncAvatar();
  37. // $this->syncAttires();
  38. // $this->syncGift();
  39. // $this->syncPack();
  40. // $this->syncLiveRoom();
  41. // $this->syncResource();
  42. return 0;
  43. }
  44. public function syncAvatar() {
  45. $avatars = \App\Models\Account::all();
  46. $avatars->each(function ($item, $key) {
  47. $v = Storage::disk("cosv5")->put($item->avatar, Storage::disk('admin')->get($item->avatar));
  48. if(!$v) {
  49. dump("出错了".$item->avatar);
  50. } else {
  51. dump("ok".$item->avatar);
  52. }
  53. });
  54. }
  55. public function syncAttires() {
  56. $avatars = \App\Models\Attire::all();
  57. $avatars->each(function ($item, $key) {
  58. $v = Storage::disk("cosv5")->put($item->img_1, Storage::disk('admin')->get($item->img_1));
  59. if(!$v) {
  60. dump("出错了".$item->img_1);
  61. } else {
  62. dump("ok".$item->img_1);
  63. }
  64. $v = Storage::disk("cosv5")->put($item->img_2, Storage::disk('admin')->get($item->img_2));
  65. if(!$v) {
  66. dump("出错了".$item->img_2);
  67. } else {
  68. dump("ok".$item->img_2);
  69. }
  70. });
  71. }
  72. public function syncGift() {
  73. $avatars = \App\Models\Gift::all();
  74. $avatars->each(function ($item, $key) {
  75. $v = Storage::disk("cosv5")->put($item->img, Storage::disk('admin')->get($item->img));
  76. if(!$v) {
  77. dump("出错了".$item->img);
  78. } else {
  79. dump("ok".$item->img);
  80. }
  81. });
  82. }
  83. public function syncPack() {
  84. $avatars = \App\Models\GiftPack::all();
  85. $avatars->each(function ($item, $key) {
  86. $v = Storage::disk("cosv5")->put($item->img, Storage::disk('admin')->get($item->img));
  87. if(!$v) {
  88. dump("出错了-".$item->img);
  89. } else {
  90. dump("ok-".$item->img);
  91. }
  92. });
  93. }
  94. public function syncLiveRoom() {
  95. $avatars = \App\Models\LiveRoom::all();
  96. $avatars->each(function ($item, $key) {
  97. $v = Storage::disk("cosv5")->put($item->img, Storage::disk('admin')->get($item->img));
  98. if(!$v) {
  99. dump("出错了-".$item->img);
  100. } else {
  101. dump("ok-".$item->img);
  102. }
  103. });
  104. }
  105. public function syncResource() {
  106. $avatars = \App\Models\Resource::all();
  107. $avatars->each(function ($item, $key) {
  108. $v = Storage::disk("cosv5")->put($item->src, Storage::disk('admin')->get($item->src));
  109. if(!$v) {
  110. dump("出错了-".$item->src);
  111. } else {
  112. dump("ok-".$item->src);
  113. }
  114. });
  115. }
  116. }