ConfigValue.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. namespace app\controller\admin\system\config;
  12. use app\common\repositories\system\config\ConfigClassifyRepository;
  13. use app\common\repositories\system\config\ConfigValueRepository;
  14. use crmeb\basic\BaseController;
  15. use think\App;
  16. /**
  17. * 系统配置
  18. */
  19. class ConfigValue extends BaseController
  20. {
  21. /**
  22. * @var ConfigClassifyRepository
  23. */
  24. private $repository;
  25. /**
  26. * ConfigValue constructor.
  27. * @param App $app
  28. * @param ConfigValueRepository $repository
  29. */
  30. public function __construct(App $app, ConfigValueRepository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. }
  35. /**
  36. * 保存配置
  37. * @param string $key
  38. * @return mixed
  39. * @author xaboy
  40. * @day 2020-04-22
  41. */
  42. public function save($key)
  43. {
  44. $formData = $this->request->post();
  45. if (!count($formData)) return app('json')->fail('保存失败');
  46. /** @var ConfigClassifyRepository $make */
  47. $make = app()->make(ConfigClassifyRepository::class);
  48. if (!($cid = $make->keyById($key))) return app('json')->fail('保存失败');
  49. $children = array_column($make->children($cid, 'config_classify_id')->toArray(), 'config_classify_id');
  50. $children[] = $cid;
  51. $this->repository->save($children, $formData, $this->request->merId());
  52. return app('json')->success('保存成功');
  53. }
  54. }