updateCityArea.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\CityAreaRepository;
  14. use app\common\repositories\store\product\SpuRepository;
  15. use think\console\Command;
  16. use think\console\Input;
  17. use think\console\Output;
  18. use think\console\input\Option;
  19. class updateCityArea extends Command
  20. {
  21. protected function configure()
  22. {
  23. // 指令配置
  24. $this->setName('update:city')
  25. ->setDescription('更新数据地址信息,城市数据');
  26. }
  27. /**
  28. * 执行城市数据更新
  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. $output->writeln('开始执行');
  38. $this->updateData();
  39. $this->changSnum();
  40. $output->writeln('执行完成');
  41. }
  42. /**
  43. * 如果需要重新导入数据,将需要导入的文件 addres.txt 文件放到项目目录下 和 public平级
  44. * @return bool
  45. * @author Qinii
  46. * @day 2024/1/19
  47. */
  48. public function updateData()
  49. {
  50. $fiel = root_path().'addres.txt';
  51. if (file_exists($fiel)) {
  52. app()->make(CityAreaRepository::class)->updateCityForTxt($fiel);
  53. }
  54. return true;
  55. }
  56. /**
  57. * 统计每个地址的子集数量
  58. * @author Qinii
  59. * @day 2024/1/19
  60. */
  61. public function changSnum()
  62. {
  63. app()->make(CityAreaRepository::class)->sumChildren();
  64. }
  65. }