SupplyDemandLists.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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\api\lists\supply_demand;
  15. use app\api\lists\BaseApiDataLists;
  16. use app\common\enum\YesNoEnum;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\agricultural_machinery\UserService;
  19. use app\common\model\supply_demand\SupplyDemandCate;
  20. use app\common\model\asset\AssetArea;
  21. use app\common\model\supply_demand\SupplyDemandInfo;
  22. /**
  23. * 供应列表
  24. * Class ArticleLists
  25. * @package app\api\lists\article
  26. */
  27. class SupplyDemandLists extends BaseApiDataLists implements ListsSearchInterface
  28. {
  29. /**
  30. * @notes 搜索条件
  31. * @return \string[][]
  32. * @author 段誉
  33. * @date 2022/9/16 18:54
  34. */
  35. public function setSearch(): array
  36. {
  37. return [
  38. '%like%' => ['title','mobile','address'],
  39. '=' => ['type']
  40. ];
  41. }
  42. /**
  43. * @notes 自定查询条件
  44. * @return array
  45. * @author 段誉
  46. * @date 2022/10/25 16:53
  47. */
  48. public function queryWhere()
  49. {
  50. // $where[] = ['expiration_time', '>=', time()];
  51. if (!empty($this->params['flag'])) {
  52. $where[] = ['user_id', '=', $this->userId];
  53. }else{
  54. $where[] = ['status', '=', 2];
  55. }
  56. if (isset($this->params['cate_id']) && $this->params['cate_id']) {
  57. $cate_id_arr = [];
  58. $cate_id = $this->params['cate_id'];
  59. $cate_info = SupplyDemandCate::find($cate_id);
  60. if($cate_info){
  61. array_push($cate_id_arr,$cate_id);
  62. if($cate_info['level'] == 1){
  63. $children_cate_info = SupplyDemandCate::where(['pid'=>$cate_id])->field('id,pid')->select()->toArray();
  64. if($children_cate_info){
  65. $children_cate = array_column($children_cate_info,'id');
  66. $cate_id_arr = array_merge($cate_id_arr,$children_cate);
  67. }
  68. }
  69. $where[] = ['cate_id', 'in',$cate_id_arr];
  70. }
  71. }
  72. if (isset($this->params['area_id']) && $this->params['area_id']) {
  73. $area_id_arr = [];
  74. $area_id = $this->params['area_id'];
  75. $area_info = AssetArea::find($area_id);
  76. if($area_info){
  77. array_push($area_id_arr,$area_id);
  78. if($area_info['level'] == 1){
  79. $children_area_info = AssetArea::where(['pid'=>$area_id])->field('id,pid')->select()->toArray();
  80. if($children_area_info){
  81. $children_area = array_column($children_area_info,'id');
  82. $area_id_arr=array_merge($area_id_arr,$children_area);
  83. }
  84. }
  85. }
  86. $where[] = ['area_id', 'in',$area_id_arr];
  87. }
  88. return $where;
  89. }
  90. /**
  91. * @notes 获取供需列表
  92. * @return array
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\DbException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @author 段誉
  97. * @date 2022/9/16 18:55
  98. */
  99. public function lists(): array
  100. {
  101. $orderRaw = 'id desc';
  102. $field = 'id,user_id,title,type,cate_id,mobile,images,area_id,address,number,content,status,remark,create_time';
  103. $result = SupplyDemandInfo::field($field)
  104. ->where($this->queryWhere())
  105. ->where($this->searchWhere)
  106. ->orderRaw($orderRaw)
  107. ->append(['type_desc','cateInfo','status_desc','images','user','area'])
  108. ->limit($this->limitOffset, $this->limitLength)
  109. ->select()->toArray();
  110. return $result;
  111. }
  112. /**
  113. * @notes 获取服务商数量
  114. * @return int
  115. * @author 段誉
  116. * @date 2022/9/16 18:55
  117. */
  118. public function count(): int
  119. {
  120. return SupplyDemandInfo::where($this->searchWhere)
  121. ->where($this->queryWhere())
  122. ->count();
  123. }
  124. }