SupplyDemandCateLists.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /**
  21. * 供需分类列表
  22. * Class ArticleCateLists
  23. * @package app\adminapi\lists\article
  24. */
  25. class SupplyDemandCateLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
  26. {
  27. /**
  28. * @notes 设置搜索条件
  29. * @return array
  30. * @author heshihu
  31. * @date 2022/2/8 18:39
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '%like%' => ['name'],
  37. '=' => ['pid']
  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 ['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 = SupplyDemandCate::where($this->searchWhere)
  84. ->where($this->queryWhere())
  85. ->field('id,name,name label,pid,status,sort,create_time')
  86. ->limit($this->limitOffset, $this->limitLength)
  87. ->order($this->sortOrder)
  88. ->append(['status_desc'])
  89. ->select()
  90. ->toArray();
  91. $treeList = linear_to_tree($supplyDemandLists, 'children');
  92. if(empty($treeList) && !empty($supplyDemandLists))
  93. {
  94. foreach($supplyDemandLists as &$v){
  95. $v['children']=[];
  96. }
  97. return $supplyDemandLists;
  98. }
  99. return $treeList;
  100. }
  101. /**
  102. * @notes 获取数量
  103. * @return int
  104. * @author heshihu
  105. * @date 2022/2/9 15:12
  106. */
  107. public function count(): int
  108. {
  109. return SupplyDemandCate::where($this->searchWhere)->where($this->queryWhere())->count();
  110. }
  111. public function extend()
  112. {
  113. return [];
  114. }
  115. }