SupplyDemandLists.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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\asset\AssetArea;
  19. use app\common\model\supply_demand\SupplyDemandInfo;
  20. use app\common\model\supply_demand\SupplyDemandCate;
  21. /**
  22. * 供需列表
  23. * Class ArticleCateLists
  24. * @package app\adminapi\lists\article
  25. */
  26. class SupplyDemandLists 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%' => ['title','mobile'],
  38. '=' => ['type']
  39. ];
  40. }
  41. /**
  42. * @notes 自定查询条件
  43. * @return array
  44. * @author 段誉
  45. * @date 2022/10/25 16:53
  46. */
  47. public function queryWhere()
  48. {
  49. $where = [];
  50. if (isset($this->params['status']) && $this->params['status']) {
  51. $status = $this->params['status'];
  52. $where[] = ['status', '=',$status];
  53. }
  54. if (isset($this->params['type']) && $this->params['type']) {
  55. $type = $this->params['type'];
  56. $where[] = ['type', '=',$type];
  57. }
  58. if (isset($this->params['cate_id']) && $this->params['cate_id']) {
  59. $cate_id_arr = [];
  60. $cate_id = $this->params['cate_id'];
  61. $cate_info = SupplyDemandCate::find($cate_id);
  62. if($cate_info){
  63. array_push($cate_id_arr,$cate_id);
  64. if($cate_info['level'] == 1){
  65. $children_cate_info = SupplyDemandCate::where(['pid'=>$cate_id])->field('id,pid')->select()->toArray();
  66. if($children_cate_info){
  67. $children_cate = array_column($children_cate_info,'id');
  68. $cate_id_arr = array_merge($cate_id_arr,$children_cate);
  69. }
  70. }
  71. $where[] = ['cate_id', 'in',$cate_id_arr];
  72. }
  73. }
  74. if (isset($this->params['area_id']) && $this->params['area_id']) {
  75. // $area_id = $this->params['area_id'];
  76. // $where[] = ['area_id', '=',$area_id];
  77. $area_id_arr = [];
  78. $area_id = $this->params['area_id'];
  79. $area_info = AssetArea::find($area_id);
  80. if($area_info){
  81. array_push($area_id_arr,$area_id);
  82. if($area_info['level'] == 1){
  83. $children_area_info = AssetArea::where(['pid'=>$area_id])->field('id,pid')->select()->toArray();
  84. if($children_area_info){
  85. $children_area = array_column($children_area_info,'id');
  86. $area_id_arr=array_merge($area_id_arr,$children_area);
  87. }
  88. }
  89. }
  90. $where[] = ['area_id', 'in',$area_id_arr];
  91. }
  92. return $where;
  93. }
  94. /**
  95. * @notes 设置支持排序字段
  96. * @return array
  97. * @author heshihu
  98. * @date 2022/2/9 15:11
  99. */
  100. public function setSortFields(): array
  101. {
  102. return [ 'id' => 'id'];
  103. }
  104. /**
  105. * @notes 设置默认排序
  106. * @return array
  107. * @author heshihu
  108. * @date 2022/2/9 15:08
  109. */
  110. public function setDefaultOrder(): array
  111. {
  112. return ['id' => 'desc'];
  113. }
  114. /**
  115. * @notes 获取管理列表
  116. * @return array
  117. * @author heshihu
  118. * @date 2022/2/21 17:11
  119. */
  120. public function lists(): array
  121. {
  122. $supplyDemandLists = SupplyDemandInfo::where($this->searchWhere)
  123. ->where($this->queryWhere())
  124. ->limit($this->limitOffset, $this->limitLength)
  125. ->order($this->sortOrder)
  126. ->append(['status_desc','type_desc','user','area','cateInfo'])
  127. ->select()
  128. ->toArray();
  129. return $supplyDemandLists;
  130. }
  131. /**
  132. * @notes 获取数量
  133. * @return int
  134. * @author heshihu
  135. * @date 2022/2/9 15:12
  136. */
  137. public function count(): int
  138. {
  139. return SupplyDemandInfo::where($this->searchWhere)->where($this->queryWhere())->count();
  140. }
  141. public function extend()
  142. {
  143. return [];
  144. }
  145. }