Product.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\controller\wwh;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. * 产品库
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Product extends Backend
  11. {
  12. /**
  13. * WwhProduct模型对象
  14. * @var \app\admin\model\wwh\Product
  15. */
  16. protected $model = null;
  17. /**
  18. * 快速搜索时执行查找的字段
  19. */
  20. protected $relationSearch = true;
  21. protected $searchFields = 'productname';
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = model('\app\admin\model\wwh\Product');
  26. $productcategorylist = collection(model('\app\admin\model\wwh\Productcategory')->select())->toArray();
  27. Tree::instance()->init($productcategorylist);
  28. $productcategorylist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  29. $categorylist = array('' => '==请选择==');
  30. $this->categoryList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
  31. foreach ($productcategorylist as $k => $v) {
  32. $categorylist[$v['id']] = $v['name'];
  33. }
  34. $this->view->assign("tjdataList", $this->model->getTjdataList());
  35. $this->view->assign('productcategorylist', $categorylist);
  36. }
  37. /**
  38. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  39. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  40. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  41. */
  42. /**
  43. * 查看
  44. */
  45. public function index()
  46. {
  47. //设置过滤方法
  48. $this->request->filter(['strip_tags']);
  49. if ($this->request->isAjax()) {
  50. //如果发送的来源是Selectpage,则转发到Selectpage
  51. if ($this->request->request('keyField')) {
  52. return $this->selectpage();
  53. }
  54. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  55. $categoryids = $this->request->request("categoryids");
  56. $query = [];
  57. if ($categoryids !== null) {
  58. $query["product.productcategoryid"] = ["in", $categoryids];
  59. }
  60. $total = $this->model
  61. ->with('productcategory')
  62. ->where($where)
  63. ->where($query)
  64. ->order($sort, $order)
  65. ->count();
  66. $list = $this->model
  67. ->with('productcategory')
  68. ->where($where)
  69. ->where($query)
  70. ->order($sort, $order)
  71. ->limit($offset, $limit)
  72. ->select();
  73. $list = collection($list)->toArray();
  74. $result = array("total" => $total, "rows" => $list);
  75. return json($result);
  76. }
  77. return $this->view->fetch();
  78. }
  79. /**
  80. * 获取所有产品列表
  81. */
  82. public function getallproductlist()
  83. {
  84. //设置过滤方法
  85. if ($this->request->isAjax()) {
  86. $list = $this->model
  87. ->select();
  88. $list = collection($list)->toArray();
  89. return json($list);
  90. }
  91. }
  92. }