ConfigValue.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. * Class ConfigValue
  18. * @package app\controller\admin\system\config
  19. * @author xaboy
  20. * @day 2020-03-27
  21. */
  22. class ConfigValue extends BaseController
  23. {
  24. /**
  25. * @var ConfigClassifyRepository
  26. */
  27. private $repository;
  28. /**
  29. * ConfigValue constructor.
  30. * @param App $app
  31. * @param ConfigValueRepository $repository
  32. */
  33. public function __construct(App $app, ConfigValueRepository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * @param string $key
  40. * @return mixed
  41. * @author xaboy
  42. * @day 2020-04-22
  43. */
  44. public function save($key)
  45. {
  46. $formData = $this->request->post();
  47. if (!count($formData)) return app('json')->fail('保存失败');
  48. /** @var ConfigClassifyRepository $make */
  49. $make = app()->make(ConfigClassifyRepository::class);
  50. if (!($cid = $make->keyById($key))) return app('json')->fail('保存失败');
  51. $children = array_column($make->children($cid, 'config_classify_id')->toArray(), 'config_classify_id');
  52. $children[] = $cid;
  53. $this->repository->save($children, $formData, $this->request->merId());
  54. return app('json')->success('保存成功');
  55. }
  56. }