Goods.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller\goods;
  3. use app\common\controller\Backend;
  4. /**
  5. * 商品管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Goods extends Backend
  10. {
  11. protected $modelValidate = true;
  12. /**
  13. * Goods模型对象
  14. * @var \app\admin\model\goods\Goods
  15. */
  16. protected $model = null;
  17. protected $indexField = 'delete_time';
  18. protected $indexFieldExcept = true;
  19. protected $noNeedRight = ['selectpage'];
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\goods\Goods;
  24. $this->view->assign("tagList", $this->model->getTagList());
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. public function selectpage()
  32. {
  33. return parent::selectpage();
  34. }
  35. /**
  36. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  37. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  38. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  39. */
  40. public function index()
  41. {
  42. //设置过滤方法
  43. $this->request->filter(['strip_tags', 'trim']);
  44. if ($this->request->isAjax()) {
  45. //如果发送的来源是Selectpage,则转发到Selectpage
  46. if ($this->request->request('keyField')) {
  47. return $this->selectpage();
  48. }
  49. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  50. $where_status = ['status'=>'online'];
  51. $filter = json_decode(input('filter'),true);
  52. if ($filter) {
  53. $where_status = [];
  54. }
  55. $list = $this->model
  56. ->field($this->indexField, $this->indexFieldExcept)
  57. ->where($where)
  58. ->where($where_status)
  59. ->order($sort, $order)
  60. ->paginate($limit);
  61. $result = array("total" => $list->total(), "rows" => $list->items());
  62. //print_r($result);die;
  63. return json($result);
  64. }
  65. // tab默认选项
  66. $this->assignconfig('tab_default','#tab-status-online');
  67. return $this->view->fetch();
  68. }
  69. }