ServiceLists.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. return $where;
  53. }
  54. /**
  55. * @notes 获取服务商列表
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @author 段誉
  61. * @date 2022/9/16 18:55
  62. */
  63. public function lists(): array
  64. {
  65. $wheres = [] ;
  66. if (!empty($this->params['area_id'])) {
  67. $cwhere=[];
  68. $cwhere[]=['pid','=',$this->params['area_id']];
  69. $cate_list = AssetArea::where($cwhere)->select() ->toArray();
  70. $cate_ids = array_column($cate_list,'id');
  71. array_push($cate_ids,(int)$this->params['area_id']);
  72. $ccs = [];
  73. foreach ($cate_ids as &$v){
  74. $ccs[]='%,'.$v.',%';
  75. }
  76. $wheres[] = ['area_id', 'like', $ccs, 'or'];
  77. }
  78. $catwhere=[];
  79. if (!empty($this->params['cate_id'])) {
  80. $cate_id_arr = explode(',',$this->params['cate_id']);
  81. $cats = [];
  82. foreach ($cate_id_arr as &$v){
  83. $cats[]='%,'.$v.',%';
  84. }
  85. $catwhere[] = ['cate_id', 'like', $cats, 'or'];
  86. }
  87. $field = 'id,user_id,name,mobile,type,agricultural_machinery_model,images,cate_id,area_id,money,content,status,expiration_time,create_time';
  88. $result = UserService::field($field)
  89. ->where($this->queryWhere())
  90. ->where($this->searchWhere)
  91. ->where($wheres)
  92. ->where($catwhere)
  93. ->append(['type_desc','cate_desc','area_desc','images','user'])
  94. ->limit($this->limitOffset, $this->limitLength)
  95. ->select()->toArray();
  96. return $result;
  97. }
  98. /**
  99. * @notes 获取服务商数量
  100. * @return int
  101. * @author 段誉
  102. * @date 2022/9/16 18:55
  103. */
  104. public function count(): int
  105. {
  106. return UserService::where($this->searchWhere)
  107. ->where($this->queryWhere())
  108. ->count();
  109. }
  110. }