TestCommand.php 1.4 KB

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