updateSpu.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  13. // +----------------------------------------------------------------------
  14. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  15. // +----------------------------------------------------------------------
  16. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  17. // +----------------------------------------------------------------------
  18. // | Author: CRMEB Team <admin@crmeb.com>
  19. // +----------------------------------------------------------------------
  20. declare (strict_types=1);
  21. namespace app\command;
  22. use app\common\repositories\store\product\SpuRepository;
  23. use think\console\Command;
  24. use think\console\Input;
  25. use think\console\Output;
  26. use think\console\input\Option;
  27. class updateSpu extends Command
  28. {
  29. protected function configure()
  30. {
  31. // 指令配置
  32. $this->setName('spu')
  33. ->addOption('productType', null, Option::VALUE_REQUIRED, 'product type :0,1,2,3')
  34. ->setDescription('the update spu command');
  35. }
  36. /**
  37. * @Author:Qinii
  38. * @Date: 2020/5/15
  39. * @param Input $input
  40. * @param Output $output
  41. * @return int|void|null
  42. */
  43. protected function execute(Input $input, Output $output)
  44. {
  45. $prodcutType = [];
  46. if ($input->hasOption('productType')){
  47. $tyep = $input->getOption('productType');
  48. if(in_array($tyep,[0,1,2,3,4])) $prodcutType = [$tyep];
  49. }
  50. $output->writeln('开始执行');
  51. $this->checkAndUpdateSpu($prodcutType);
  52. $output->writeln('执行完成');
  53. }
  54. public function checkAndUpdateSpu($prodcutType)
  55. {
  56. app()->make(SpuRepository::class)->updateSpu($prodcutType);
  57. }
  58. }