Config.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\data\controller\base;
  3. use think\admin\Controller;
  4. /**
  5. * 应用参数配置
  6. * Class Config
  7. * @package app\data\controller\base
  8. */
  9. class Config extends Controller
  10. {
  11. /**
  12. * 微信小程序配置
  13. * @auth true
  14. * @menu true
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function wxapp()
  20. {
  21. $this->skey = 'wxapp';
  22. $this->title = '微信小程序配置';
  23. $this->__sysdata('wxapp');
  24. }
  25. /**
  26. * 邀请二维码设置
  27. * @auth true
  28. * @menu true
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function cropper()
  34. {
  35. $this->skey = 'cropper';
  36. $this->title = '邀请二维码设置';
  37. $this->__sysdata('cropper');
  38. }
  39. /**
  40. * 显示并保存数据
  41. * @param string $template 模板文件
  42. * @param string $history 跳转处理
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. private function __sysdata(string $template, string $history = '')
  48. {
  49. if ($this->request->isGet()) {
  50. $this->data = sysdata($this->skey);
  51. $this->fetch($template);
  52. }
  53. if ($this->request->isPost()) {
  54. if (is_string(input('data'))) {
  55. $data = json_decode(input('data'), true) ?: [];
  56. } else {
  57. $data = $this->request->post();
  58. }
  59. if (sysdata($this->skey, $data) !== false) {
  60. $this->success('内容保存成功!', $history);
  61. } else {
  62. $this->error('内容保存失败,请稍候再试!');
  63. }
  64. }
  65. }
  66. }