Index.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\admin\controller\supplier;
  3. use app\common\controller\Backend;
  4. use app\common\Enum\StatusEnum;
  5. use app\admin\model\supplier\Index as IndexModel;
  6. /**
  7. * 商品供应商
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Index extends Backend
  12. {
  13. /**
  14. * Index模型对象
  15. * @var \app\admin\model\supplier\Index
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new IndexModel;
  22. $this->view->assign("statusList", StatusEnum::getMap());
  23. $this->assignconfig("statusList", json_encode(StatusEnum::getMap()));
  24. }
  25. public function index()
  26. {
  27. $this->request->filter(['strip_tags', 'trim']);
  28. if ($this->request->isAjax()) {
  29. if ($this->request->request('keyField')) {
  30. return $this->selectpage();
  31. }
  32. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  33. $list = $this->model
  34. ->with(['category'])
  35. ->where($where)
  36. ->order($sort, $order)
  37. ->paginate($limit);
  38. foreach ($list as $row) {
  39. $row->visible(['id', 'name', 'category_id', 'contact', 'mobile', 'landline', 'weigh', 'status', 'createtime', 'updatetime']);
  40. $row->visible(['status_text', 'category.name']);
  41. $row->hidden(['deletetime']);
  42. }
  43. $result = array("total" => $list->total(), "rows" => $list->items());
  44. return json($result);
  45. }
  46. return $this->view->fetch();
  47. }
  48. /**
  49. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  50. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  51. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  52. */
  53. }