updateSpu.php 1.9 KB

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