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. protected $relationSearch = true;
  17. protected $searchFields = 'id';
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\shop\Collect;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. /**
  25. * 查看
  26. */
  27. public function index()
  28. {
  29. //设置过滤方法
  30. $this->request->filter(['strip_tags', 'trim']);
  31. if ($this->request->isAjax()) {
  32. //如果发送的来源是Selectpage,则转发到Selectpage
  33. if ($this->request->request('keyField')) {
  34. return $this->selectpage();
  35. }
  36. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  37. $list = $this->model
  38. ->with(['user', 'goods'])
  39. ->where($where)
  40. ->order($sort, $order)
  41. ->paginate($limit);
  42. foreach ($list as $index => $item) {
  43. if ($item->user) {
  44. $item->user->visible(['id', 'nickname', 'avatar','username']);
  45. }
  46. }
  47. $result = array("total" => $list->total(), "rows" => $list->items());
  48. return json($result);
  49. }
  50. return $this->view->fetch();
  51. }
  52. }