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\client\wxapp;
  13. use app\store\controller\Controller;
  14. use app\store\model\wxapp\Setting as SettingModel;
  15. use think\response\Json;
  16. /**
  17. * 微信小程序设置
  18. * Class Setting
  19. * @package app\store\controller\apps\wxapp
  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. // 获取微信小程序设置
  34. $detail = SettingModel::getItem($key);
  35. // 服务端域名
  36. $domain = $this->request->host(true);
  37. return $this->renderSuccess(compact('detail', 'domain'));
  38. }
  39. /**
  40. * 更新设置项
  41. * @param string $key
  42. * @return Json
  43. */
  44. public function update(string $key): Json
  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. }