SystemConfigContent.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\setting;
  12. use app\admin\controller\AuthController;
  13. use app\admin\model\system\SystemConfigContent as SystemConfigContentModel;
  14. use service\JsonService;
  15. /**
  16. * 配置文章
  17. * Class SystemConfigContent
  18. * @package app\admin\controller\setting
  19. */
  20. class SystemConfigContent extends AuthController
  21. {
  22. /**
  23. * 展示数据
  24. * @param int $id
  25. * @return mixed|void
  26. */
  27. public function index($id = 0)
  28. {
  29. if (!$id) {
  30. return $this->failed('缺少参数');
  31. }
  32. $this->assign([
  33. 'id' => $id,
  34. 'content' => SystemConfigContentModel::getValue($id, 'id'),
  35. 'title' => SystemConfigContentModel::getValue($id, 'id', 'title'),
  36. ]);
  37. return $this->fetch();
  38. }
  39. /**
  40. * 保存数据
  41. * @param int $id
  42. * @throws \think\exception\DbException
  43. */
  44. public function save($id = 0)
  45. {
  46. if (!$id) {
  47. return $this->failed('缺少参数');
  48. }
  49. $content = $this->request->post('content', '');
  50. $info = SystemConfigContentModel::get($id);
  51. if (!$info) {
  52. return JsonService::fail('您保存的配置不存在');
  53. }
  54. if (!$content) {
  55. return JsonService::fail('内容不能为空');
  56. }
  57. $info->content = htmlspecialchars($content);
  58. if ($info->save()) {
  59. return JsonService::successful('保存成功');
  60. } else {
  61. return JsonService::fail('保存失败');
  62. }
  63. }
  64. }