MechanicalCateLists.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\agricultural_machinery;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\lists\ListsSearchInterface;
  17. use app\common\lists\ListsSortInterface;
  18. use app\common\model\supply_demand\SupplyDemandInfo;
  19. use app\common\model\supply_demand\SupplyDemandCate;
  20. use app\common\model\agricultural_machinery\MechanicalCate;
  21. /**
  22. * 机械分类列表
  23. * Class ArticleCateLists
  24. * @package app\adminapi\lists\article
  25. */
  26. class MechanicalCateLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
  27. {
  28. /**
  29. * @notes 设置搜索条件
  30. * @return array
  31. * @author heshihu
  32. * @date 2022/2/8 18:39
  33. */
  34. public function setSearch(): array
  35. {
  36. return [
  37. '%like%' => ['name']
  38. ];
  39. }
  40. /**
  41. * @notes 自定查询条件
  42. * @return array
  43. * @author 段誉
  44. * @date 2022/10/25 16:53
  45. */
  46. public function queryWhere()
  47. {
  48. $where = [];
  49. // if (isset($this->params['status']) && $this->params['status']) {
  50. // $status = $this->params['status'];
  51. // $where[] = ['status', '=',$status];
  52. // }
  53. return $where;
  54. }
  55. /**
  56. * @notes 设置支持排序字段
  57. * @return array
  58. * @author heshihu
  59. * @date 2022/2/9 15:11
  60. */
  61. public function setSortFields(): array
  62. {
  63. return [ 'id' => 'id'];
  64. }
  65. /**
  66. * @notes 设置默认排序
  67. * @return array
  68. * @author heshihu
  69. * @date 2022/2/9 15:08
  70. */
  71. public function setDefaultOrder(): array
  72. {
  73. return ['sort' => 'desc','id'=>'desc'];
  74. }
  75. /**
  76. * @notes 获取分类列表
  77. * @return array
  78. * @author heshihu
  79. * @date 2022/2/21 17:11
  80. */
  81. public function lists(): array
  82. {
  83. $supplyDemandLists = MechanicalCate::where($this->searchWhere)
  84. ->where($this->queryWhere())
  85. ->field('id,name,sort,create_time')
  86. ->limit($this->limitOffset, $this->limitLength)
  87. ->order($this->sortOrder)
  88. ->select()
  89. ->toArray();
  90. // $treeList = linear_to_tree($supplyDemandLists, 'children');
  91. // if(empty($treeList) && !empty($supplyDemandLists))
  92. // {
  93. // foreach($supplyDemandLists as &$v){
  94. // $v['children']=[];
  95. // }
  96. return $supplyDemandLists;
  97. // }
  98. // return $treeList;
  99. }
  100. /**
  101. * @notes 获取数量
  102. * @return int
  103. * @author heshihu
  104. * @date 2022/2/9 15:12
  105. */
  106. public function count(): int
  107. {
  108. return MechanicalCate::where($this->searchWhere)->where($this->queryWhere())->count();
  109. }
  110. public function extend()
  111. {
  112. return [];
  113. }
  114. }