Setting.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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 app\store\model\Setting as SettingModel;
  14. use app\common\library\sms\Driver as SmsDriver;
  15. use think\response\Json;
  16. /**
  17. * 系统设置
  18. * Class Setting
  19. * @package app\store\controller
  20. */
  21. class Setting extends Controller
  22. {
  23. /**
  24. * 获取设置项
  25. * @param string $key
  26. * @return Json
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\DbException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. */
  31. public function detail(string $key): Json
  32. {
  33. $values = SettingModel::getItem($key);
  34. return $this->renderSuccess(compact('values'));
  35. }
  36. /**
  37. * 更新系统设置
  38. * @param string $key
  39. * @return Json
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function update(string $key): Json
  45. {
  46. // 保存商城设置
  47. $model = new SettingModel;
  48. if ($model->edit($key, $this->postForm())) {
  49. return $this->renderSuccess('操作成功');
  50. }
  51. return $this->renderError($model->getError() ?: '操作失败');
  52. }
  53. }