TestCommand.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Goods\GoodsSku;
  4. use Illuminate\Console\Command;
  5. use Nerd\CartesianProduct\CartesianProduct;
  6. class TestCommand extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'test {cmd?}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. public function handle()
  21. {
  22. $cmd = $this->argument('cmd');
  23. $args = $this->arguments();
  24. unset($args['command'], $args['cmd']);
  25. $params = array_values($args);
  26. if (empty($cmd)) {
  27. echo 'Nothing to do...';
  28. } else {
  29. if (method_exists($this, $cmd)) {
  30. call_user_func_array([$this, $cmd], $params);
  31. } else {
  32. echo 'cmd not exists';
  33. }
  34. }
  35. return;
  36. }
  37. public function time()
  38. {
  39. $cartesianProduct = new CartesianProduct();
  40. $cartesianProduct->appendSet(["红色", "白色"]);
  41. dump($cartesianProduct->compute());
  42. }
  43. public function fixSku()
  44. {
  45. GoodsSku::chunkById(10, function ($s) {
  46. $s->each(function (GoodsSku $sku) {
  47. $sku->spec_attr_list;
  48. });
  49. });
  50. }
  51. }