UpdateConfigTab.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Elton
  5. * Date: 2020/2/29
  6. * Time: 20:20
  7. */
  8. namespace app\admin\command;
  9. use app\common\library\Redis;
  10. use app\common\model\Config as ConfigModel;
  11. use think\console\Command;
  12. use think\console\Input;
  13. use think\console\Output;
  14. use think\Request;
  15. class UpdateConfigTab extends Command
  16. {
  17. /**
  18. * 配置指令
  19. */
  20. protected function configure()
  21. {
  22. $this->setName('UpdateConfigTab')
  23. ->setDescription('CPS测试功能配置,如果系统配置中没有CPS测试功能配置则添加一个Tab');
  24. }
  25. /**
  26. * 执行指令
  27. * @param Input $input
  28. * @param Output $output
  29. * @return null|int
  30. * @throws \LogicException
  31. * @see setCode()
  32. */
  33. protected function execute(Input $input, Output $output)
  34. {
  35. //cli模式下无法获取到当前的项目模块,手动指定一下
  36. Request::instance()->module('admin');
  37. $model = new ConfigModel();
  38. $obj = $model->where('name', 'eq', 'configgroup')->find();
  39. if(!in_array('cpstest', json_decode($obj->value, true))){
  40. $config_arr = json_decode($obj->value, true);
  41. $config_arr['cpstest'] = 'CPS测试功能配置';
  42. $rst = $model->update(['value'=>json_encode($config_arr)], ['name'=>'configgroup']);
  43. // is_open_share share_channels share_domain share_content share_book_id share_chapter_num
  44. Redis::instance()->del('site');
  45. $output->writeln('Test'.json_encode($rst));
  46. }
  47. }
  48. }