SupplyDemandLists.php 4.0 KB

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