Setting.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /**
  16. * 系统设置
  17. * Class Setting
  18. * @package app\store\controller
  19. */
  20. class Setting extends Controller
  21. {
  22. /**
  23. * 获取设置项
  24. * @param string $key
  25. * @return array
  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)
  31. {
  32. $values = SettingModel::getItem($key);
  33. return $this->renderSuccess(compact('values'));
  34. }
  35. /**
  36. * 更新系统设置
  37. * @param string $key
  38. * @return array
  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)
  44. {
  45. // 保存商城设置
  46. if ($key == 'withdrawal' && isset($this->postForm()['withdraw_min']) && floatval($this->postForm()['withdraw_min']) < 0.01){
  47. return $this->renderError('最小可提现金额不能小于0.01元');
  48. }
  49. $model = new SettingModel;
  50. if ($model->edit($key, $this->postForm())) {
  51. return $this->renderSuccess('操作成功');
  52. }
  53. return $this->renderError($model->getError() ?: '操作失败');
  54. }
  55. }