SupplyDemandLists.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 SupplyDemandLists 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%' => ['title','mobile'],
  37. '=' => ['type']
  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. if (isset($this->params['cate_id']) && $this->params['cate_id']) {
  54. $cate_id_arr = [];
  55. $cate_id = $this->params['cate_id'];
  56. $cate_info = SupplyDemandCate::find($cate_id);
  57. if($cate_info){
  58. array_push($cate_id_arr,$cate_id);
  59. if($cate_info['level'] == 1){
  60. $children_cate_info = SupplyDemandCate::where(['pid'=>$cate_id])->field('id,pid')->select()->toArray();
  61. if($children_cate_info){
  62. $children_cate = array_column($children_cate_info,'id');
  63. $cate_id_arr = array_merge($cate_id_arr,$children_cate);
  64. }
  65. }
  66. $where[] = ['cate_id', 'in',$cate_id_arr];
  67. }
  68. }
  69. if (isset($this->params['area_id']) && $this->params['area_id']) {
  70. $area_id = $this->params['area_id'];
  71. $where[] = ['area_id', '=',$area_id];
  72. }
  73. return $where;
  74. }
  75. /**
  76. * @notes 设置支持排序字段
  77. * @return array
  78. * @author heshihu
  79. * @date 2022/2/9 15:11
  80. */
  81. public function setSortFields(): array
  82. {
  83. return [ 'id' => 'id'];
  84. }
  85. /**
  86. * @notes 设置默认排序
  87. * @return array
  88. * @author heshihu
  89. * @date 2022/2/9 15:08
  90. */
  91. public function setDefaultOrder(): array
  92. {
  93. return ['id' => 'desc'];
  94. }
  95. /**
  96. * @notes 获取管理列表
  97. * @return array
  98. * @author heshihu
  99. * @date 2022/2/21 17:11
  100. */
  101. public function lists(): array
  102. {
  103. $supplyDemandLists = SupplyDemandInfo::where($this->searchWhere)
  104. ->where($this->queryWhere())
  105. ->limit($this->limitOffset, $this->limitLength)
  106. ->order($this->sortOrder)
  107. ->append(['status_desc','type_desc','user','area'])
  108. ->select()
  109. ->toArray();
  110. return $supplyDemandLists;
  111. }
  112. /**
  113. * @notes 获取数量
  114. * @return int
  115. * @author heshihu
  116. * @date 2022/2/9 15:12
  117. */
  118. public function count(): int
  119. {
  120. return SupplyDemandInfo::where($this->searchWhere)->where($this->queryWhere())->count();
  121. }
  122. public function extend()
  123. {
  124. return [];
  125. }
  126. }