updateSpu.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use app\common\repositories\store\product\SpuRepository;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. use think\console\input\Option;
  9. class updateSpu extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('spu')
  15. ->addOption('productType', null, Option::VALUE_REQUIRED, 'product type :0,1,2,3')
  16. ->setDescription('the update spu command');
  17. }
  18. /**
  19. * @Author:Qinii
  20. * @Date: 2020/5/15
  21. * @param Input $input
  22. * @param Output $output
  23. * @return int|void|null
  24. */
  25. protected function execute(Input $input, Output $output)
  26. {
  27. $prodcutType = [];
  28. if ($input->hasOption('productType')){
  29. $tyep = $input->getOption('productType');
  30. if(in_array($tyep,[0,1,2,3,4])) $prodcutType = [$tyep];
  31. }
  32. $output->writeln('开始执行');
  33. $this->checkAndUpdateSpu($prodcutType);
  34. $output->writeln('执行完成');
  35. }
  36. public function checkAndUpdateSpu($prodcutType)
  37. {
  38. app()->make(SpuRepository::class)->updateSpu($prodcutType);
  39. }
  40. }