Collect.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\controller\shop;
  3. use app\common\controller\Backend;
  4. /**
  5. * 收藏管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Collect extends Backend
  10. {
  11. /**
  12. * Collect模型对象
  13. * @var \app\admin\model\shop\Collect
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\shop\Collect;
  20. $this->view->assign("statusList", $this->model->getStatusList());
  21. }
  22. /**
  23. * 查看
  24. */
  25. public function index()
  26. {
  27. //设置过滤方法
  28. $this->request->filter(['strip_tags', 'trim']);
  29. if ($this->request->isAjax()) {
  30. //如果发送的来源是Selectpage,则转发到Selectpage
  31. if ($this->request->request('keyField')) {
  32. return $this->selectpage();
  33. }
  34. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  35. $list = $this->model
  36. ->with(['User', 'Goods'])
  37. ->where($where)
  38. ->order($sort, $order)
  39. ->paginate($limit);
  40. foreach ($list as $index => $item) {
  41. if ($item->user) {
  42. $item->user->visible(['id', 'nickname', 'avatar']);
  43. }
  44. }
  45. $result = array("total" => $list->total(), "rows" => $list->items());
  46. return json($result);
  47. }
  48. return $this->view->fetch();
  49. }
  50. }