Setting.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller;
  13. use think\response\Json;
  14. use app\store\model\Setting as SettingModel;
  15. /**
  16. * 系统设置
  17. * Class Setting
  18. * @package app\store\controller
  19. */
  20. class Setting extends Controller
  21. {
  22. /**
  23. * 获取设置项
  24. * @param string $key
  25. * @return Json
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public function detail(string $key): Json
  31. {
  32. $values = SettingModel::getItem($key);
  33. return $this->renderSuccess(compact('values'));
  34. }
  35. /**
  36. * 更新系统设置
  37. * @param string $key
  38. * @return Json
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function update(string $key): Json
  44. {
  45. // 保存商城设置
  46. $model = new SettingModel;
  47. if ($model->edit($key, $this->postForm())) {
  48. return $this->renderSuccess('操作成功');
  49. }
  50. return $this->renderError($model->getError() ?: '操作失败');
  51. }
  52. }