Products.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\controller\product;
  3. use app\common\controller\Backend;
  4. use Exception;
  5. use think\Db;
  6. use think\exception\DbException;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. /**
  10. * 产品分类
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Products extends Backend
  15. {
  16. /**
  17. * Products模型对象
  18. * @var \app\admin\model\Products
  19. */
  20. protected $model = null;
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->model = new \app\common\model\ProductsModel();
  25. }
  26. /**
  27. * 查看
  28. *
  29. * @return string|Json
  30. * @throws \think\Exception
  31. * @throws DbException
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags', 'trim']);
  37. if (false === $this->request->isAjax()) {
  38. return $this->view->fetch();
  39. }
  40. //如果发送的来源是 Selectpage,则转发到 Selectpage
  41. if ($this->request->request('keyField')) {
  42. return $this->selectpage();
  43. }
  44. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  45. $list = $this->model
  46. ->where($where)
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. $result = ['total' => $list->total(), 'rows' => $list->items()];
  50. return json($result);
  51. }
  52. }