Data.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\data\controller\api;
  3. use app\data\model\BaseUserMessage;
  4. use think\admin\Controller;
  5. use think\admin\helper\QueryHelper;
  6. use think\admin\model\SystemBase;
  7. /**
  8. * 基础数据接口
  9. * Class Data
  10. * @package app\data\controller\api
  11. */
  12. class Data extends Controller
  13. {
  14. /**
  15. * 获取指定数据
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\DbException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. */
  20. public function getData()
  21. {
  22. $data = $this->_vali(['name.require' => '数据名称不能为空!']);
  23. $extra = ['about', 'slider', 'agreement', 'cropper']; // 其他数据
  24. if (in_array($data['name'], $extra) || isset(SystemBase::items('页面内容')[$data['name']])) {
  25. $this->success('获取数据对象', sysdata($data['name']));
  26. } else {
  27. $this->error('获取数据失败', []);
  28. }
  29. }
  30. /**
  31. * 图片内容数据
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function getSlider()
  37. {
  38. $this->keys = input('keys', '首页图片');
  39. if (isset(SystemBase::items('图片内容')[$this->keys])) {
  40. $this->success('获取图片内容', sysdata($this->keys));
  41. } else {
  42. $this->error('获取图片失败', []);
  43. }
  44. }
  45. /**
  46. * 系统通知数据
  47. */
  48. public function getNotify()
  49. {
  50. BaseUserMessage::mQuery(null, function (QueryHelper $query) {
  51. if (($id = input('id')) > 0) {
  52. BaseUserMessage::mk()->where(['id' => $id])->inc('num_read')->update([]);
  53. }
  54. $query->equal('id')->where(['status' => 1, 'deleted' => 0]);
  55. $this->success('获取系统通知', $query->order('sort desc,id desc')->page(true, false, false, 20));
  56. });
  57. }
  58. }