ServiceLists.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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\service;
  15. use app\api\lists\BaseApiDataLists;
  16. use app\common\enum\YesNoEnum;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\article\Article;
  19. use app\common\model\asset\AssetArea;
  20. use app\common\model\article\ArticleCollect;
  21. use app\common\model\agricultural_machinery\UserService;
  22. /**
  23. * 服务商列表
  24. * Class ArticleLists
  25. * @package app\api\lists\article
  26. */
  27. class ServiceLists 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%' => ['name','mobile'],
  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[] = ['status', '=', 1];
  51. $where[] = ['expiration_time', '>=', time()];
  52. $where[] = ['audit_status','=',1];
  53. return $where;
  54. }
  55. /**
  56. * @notes 获取服务商列表
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @author 段誉
  62. * @date 2022/9/16 18:55
  63. */
  64. public function lists(): array
  65. {
  66. $wheres = [] ;
  67. if (!empty($this->params['area_id'])) {
  68. $cwhere=[];
  69. $cwhere[]=['pid','=',$this->params['area_id']];
  70. $cate_list = AssetArea::where($cwhere)->select() ->toArray();
  71. $cate_ids = array_column($cate_list,'id');
  72. array_push($cate_ids,(int)$this->params['area_id']);
  73. $ccs = [];
  74. foreach ($cate_ids as &$v){
  75. $ccs[]='%,'.$v.',%';
  76. }
  77. $wheres[] = ['area_id', 'like', $ccs, 'or'];
  78. }
  79. $catwhere=[];
  80. if (!empty($this->params['cate_id'])) {
  81. $cate_id_arr = explode(',',$this->params['cate_id']);
  82. $cats = [];
  83. foreach ($cate_id_arr as &$v){
  84. $cats[]='%,'.$v.',%';
  85. }
  86. $catwhere[] = ['cate_id', 'like', $cats, 'or'];
  87. }
  88. $mcatwhere=[];
  89. if (!empty($this->params['mechanical_cate_id'])) {
  90. $m_cate_id_arr = explode(',',$this->params['mechanical_cate_id']);
  91. $mcats = [];
  92. foreach ($m_cate_id_arr as &$v){
  93. $mcats[]='%,'.$v.',%';
  94. }
  95. $mcatwhere[] = ['mechanical_cate_id', 'like', $mcats, 'or'];
  96. }
  97. $field = 'id,user_id,name,mobile,type,agricultural_machinery_model,images,driver_image,driving_image,agricultural_image,cate_id,area_id,mechanical_cate_id,money,
  98. content,status,audit_status,audit_time,expiration_time,create_time';
  99. $result = UserService::field($field)
  100. ->where($this->queryWhere())
  101. ->where($this->searchWhere)
  102. ->where($wheres)
  103. ->where($catwhere)
  104. ->where($mcatwhere)
  105. ->append(['type_desc','cate_desc','area_desc','images','user','mechanical_cate_desc'])
  106. ->limit($this->limitOffset, $this->limitLength)
  107. ->select()->toArray();
  108. return $result;
  109. }
  110. /**
  111. * @notes 获取服务商数量
  112. * @return int
  113. * @author 段誉
  114. * @date 2022/9/16 18:55
  115. */
  116. public function count(): int
  117. {
  118. $wheres = [] ;
  119. if (!empty($this->params['area_id'])) {
  120. $cwhere=[];
  121. $cwhere[]=['pid','=',$this->params['area_id']];
  122. $cate_list = AssetArea::where($cwhere)->select() ->toArray();
  123. $cate_ids = array_column($cate_list,'id');
  124. array_push($cate_ids,(int)$this->params['area_id']);
  125. $ccs = [];
  126. foreach ($cate_ids as &$v){
  127. $ccs[]='%,'.$v.',%';
  128. }
  129. $wheres[] = ['area_id', 'like', $ccs, 'or'];
  130. }
  131. $catwhere=[];
  132. if (!empty($this->params['cate_id'])) {
  133. $cate_id_arr = explode(',',$this->params['cate_id']);
  134. $cats = [];
  135. foreach ($cate_id_arr as &$v){
  136. $cats[]='%,'.$v.',%';
  137. }
  138. $catwhere[] = ['cate_id', 'like', $cats, 'or'];
  139. }
  140. $mcatwhere=[];
  141. if (!empty($this->params['mechanical_cate_id'])) {
  142. $m_cate_id_arr = explode(',',$this->params['mechanical_cate_id']);
  143. $mcats = [];
  144. foreach ($m_cate_id_arr as &$v){
  145. $mcats[]='%,'.$v.',%';
  146. }
  147. $mcatwhere[] = ['mechanical_cate_id', 'like', $mcats, 'or'];
  148. }
  149. return UserService::where($this->searchWhere)
  150. ->where($this->queryWhere())
  151. ->where($wheres)
  152. ->where($catwhere)
  153. ->where($mcatwhere)
  154. ->count();
  155. }
  156. }