PrivateTmp.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\admin\controller\template;
  3. use app\admin\model\template\TemplateModel;
  4. use app\admin\service\template\TemplateService;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\Exception;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. use think\Session;
  11. /**
  12. * 私有模板
  13. * @icon fa fa-circle-o
  14. */
  15. class PrivateTmp extends Backend
  16. {
  17. protected $model = null;
  18. protected $service = null;
  19. protected $noNeedRight = ['parentindex','childindex'];
  20. /**
  21. * 快速搜索时执行查找的字段
  22. */
  23. protected $searchFields = ['title'];
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new TemplateModel();
  28. $this->service = new TemplateService();
  29. }
  30. /**
  31. * 模板列表
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags']);
  37. return $this->view->fetch();
  38. }
  39. /**
  40. * 父级列表
  41. * @return string|\think\response\Json
  42. * @throws \think\Exception
  43. * @author matielong
  44. */
  45. public function parentIndex()
  46. {
  47. //设置过滤方法
  48. $this->request->filter(['strip_tags']);
  49. if ($this->request->isAjax()) {
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. $my_where = [
  52. 'is_public' => 2,
  53. 'parent_id' => 0
  54. ];
  55. $total = $this->model
  56. ->where($where)
  57. ->where($my_where)
  58. ->order($sort, $order)
  59. ->count();
  60. $list = $this->model
  61. ->where($where)
  62. ->where($my_where)
  63. ->order($sort, $order)
  64. ->limit($offset, $limit)
  65. ->select();
  66. $list = collection($list)->toArray();
  67. $result = array("total" => $total, "rows" => $list);
  68. return json($result);
  69. }
  70. return $this->view->fetch();
  71. }
  72. /**
  73. * 子级列表
  74. * @return string|\think\response\Json
  75. * @throws Exception
  76. * @author matielong
  77. */
  78. public function childIndex()
  79. {
  80. $pid = $this->request->param('pid');
  81. //设置过滤方法
  82. $this->request->filter(['strip_tags']);
  83. if ($this->request->isAjax()) {
  84. list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields, true);
  85. $my_where = [
  86. 'is_public' => 2,
  87. 'parent_id' => $pid
  88. ];
  89. $total = $this->model->alias('tmp')
  90. ->where($where)
  91. ->where($my_where)
  92. ->order($sort, $order)
  93. ->count();
  94. $list = $this->model->alias('tmp')
  95. ->where($where)
  96. ->where($my_where)
  97. ->order($sort, $order)
  98. ->limit($offset, $limit)
  99. ->select();
  100. $list = collection($list)->toArray();
  101. $result = array("total" => $total, "rows" => $list);
  102. return json($result);
  103. }
  104. return $this->view->fetch();
  105. }
  106. }