Page.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\adminapi\controller\v1\page;
  3. use app\adminapi\controller\AuthController;
  4. use app\models\page\PageModel;
  5. use crmeb\services\{UtilService as Util};
  6. use think\Request;
  7. class Page extends AuthController
  8. {
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function index()
  15. {
  16. $where = Util::getMore([
  17. ['page', 1],
  18. ['limit', 10]
  19. ], $this->request);
  20. $list = PageModel::systemPage($where);
  21. return $this->success($list);
  22. }
  23. /**
  24. * 保存新建的资源
  25. *
  26. * @param \think\Request $request
  27. * @return \think\Response
  28. */
  29. public function save(Request $request)
  30. {
  31. $data = Util::postMore([
  32. ['id', 0],
  33. ['title', ''],
  34. ['unique', ''],
  35. ['content', '']
  36. ]);
  37. $data['add_time'] = time();
  38. if ($data['id']) {
  39. $id = $data['id'];
  40. unset($data['id']);
  41. $res = PageModel::edit($data, $id, 'id');
  42. if($res)
  43. return $this->success('修改成功!', ['id' => $id]);
  44. else
  45. return $this->fail('修改失败!');
  46. } else {
  47. $res = PageModel::create($data);
  48. return $this->success('添加成功!', ['id' => $res->id]);
  49. }
  50. }
  51. /**
  52. * 显示指定的资源
  53. *
  54. * @param int $id
  55. * @return \think\Response
  56. */
  57. public function read($id)
  58. {
  59. $info = PageModel::getOne($id);
  60. return $this->success(compact('info'));
  61. }
  62. /**
  63. * 删除指定资源
  64. *
  65. * @param int $id
  66. * @return \think\Response
  67. */
  68. public function delete($id)
  69. {
  70. if (!$id) return $this->fail('数据不存在');
  71. $res = PageModel::get($id);
  72. if (!$res) return $this->fail('数据不存在!');
  73. if ($res['is_del']) return $this->fail('已删除!');
  74. $data['is_del'] = 1;
  75. if (PageModel::edit($data, $id))
  76. return $this->success('删除成功!');
  77. else
  78. return $this->fail('删除失败,请稍候再试!');
  79. }
  80. }