ServiceLists.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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,cate_id,area_id,mechanical_cate_id,money,content,status,audit_status,audit_time,expiration_time,create_time';
  98. $result = UserService::field($field)
  99. ->where($this->queryWhere())
  100. ->where($this->searchWhere)
  101. ->where($wheres)
  102. ->where($catwhere)
  103. ->where($mcatwhere)
  104. ->append(['type_desc','cate_desc','area_desc','images','user','mechanical_cate_desc'])
  105. ->limit($this->limitOffset, $this->limitLength)
  106. ->select()->toArray();
  107. return $result;
  108. }
  109. /**
  110. * @notes 获取服务商数量
  111. * @return int
  112. * @author 段誉
  113. * @date 2022/9/16 18:55
  114. */
  115. public function count(): int
  116. {
  117. $wheres = [] ;
  118. if (!empty($this->params['area_id'])) {
  119. $cwhere=[];
  120. $cwhere[]=['pid','=',$this->params['area_id']];
  121. $cate_list = AssetArea::where($cwhere)->select() ->toArray();
  122. $cate_ids = array_column($cate_list,'id');
  123. array_push($cate_ids,(int)$this->params['area_id']);
  124. $ccs = [];
  125. foreach ($cate_ids as &$v){
  126. $ccs[]='%,'.$v.',%';
  127. }
  128. $wheres[] = ['area_id', 'like', $ccs, 'or'];
  129. }
  130. $catwhere=[];
  131. if (!empty($this->params['cate_id'])) {
  132. $cate_id_arr = explode(',',$this->params['cate_id']);
  133. $cats = [];
  134. foreach ($cate_id_arr as &$v){
  135. $cats[]='%,'.$v.',%';
  136. }
  137. $catwhere[] = ['cate_id', 'like', $cats, 'or'];
  138. }
  139. $mcatwhere=[];
  140. if (!empty($this->params['mechanical_cate_id'])) {
  141. $m_cate_id_arr = explode(',',$this->params['mechanical_cate_id']);
  142. $mcats = [];
  143. foreach ($m_cate_id_arr as &$v){
  144. $mcats[]='%,'.$v.',%';
  145. }
  146. $mcatwhere[] = ['mechanical_cate_id', 'like', $mcats, 'or'];
  147. }
  148. return UserService::where($this->searchWhere)
  149. ->where($this->queryWhere())
  150. ->where($wheres)
  151. ->where($catwhere)
  152. ->where($mcatwhere)
  153. ->count();
  154. }
  155. }