ToolAvoidPit.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\sys\controller;
  3. use app\BaseController;
  4. use app\Request;
  5. use app\logics\ToolAvoidPitLogic;
  6. use think\facade\View;
  7. class ToolAvoidPit extends BaseController
  8. {
  9. /**
  10. * 显示资源列表
  11. */
  12. public function index()
  13. {
  14. if(!$this->request->isAjax()){
  15. View::assign('type', config('app.params.avoid_pit_type'));
  16. return View::fetch();
  17. }
  18. $param = $this->request->param();
  19. $condition = [];
  20. if (!empty($param['type'])) {
  21. $condition[] = ['type', 'eq', $param['type']];
  22. }
  23. if (!empty($param['label'])) {
  24. $condition[] = ['label', 'like', '%'.$param['label'].'%'];
  25. }
  26. if (!empty($param['title'])) {
  27. $condition[] = ['title', 'like', '%'.$param['title'].'%'];
  28. }
  29. $data = ToolAvoidPitLogic::list($condition);
  30. $count = ToolAvoidPitLogic::count($condition);
  31. return json(['code'=>0, 'data'=>$data, 'count'=>$count]);
  32. }
  33. /**
  34. * 保存新建的资源
  35. */
  36. public function save()
  37. {
  38. $param = $this->request->param();
  39. ToolAvoidPitLogic::save($param);
  40. return json(['code'=>0, 'msg'=>'保存成功']);
  41. }
  42. /**
  43. * 删除
  44. */
  45. public function delete()
  46. {
  47. $id = $this->request->param('id');
  48. ToolAvoidPitLogic::delete($id);
  49. return json(['code'=>0, 'msg'=>'删除成功']);
  50. }
  51. }