Data.php 2.1 KB

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