ServiceLists.php 3.9 KB

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