ServiceLists.php 3.5 KB

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