ServiceLists.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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\article\ArticleCollect;
  20. use app\common\model\agricultural_machinery\UserService;
  21. /**
  22. * 服务商列表
  23. * Class ArticleLists
  24. * @package app\api\lists\article
  25. */
  26. class ServiceLists extends BaseApiDataLists implements ListsSearchInterface
  27. {
  28. /**
  29. * @notes 搜索条件
  30. * @return \string[][]
  31. * @author 段誉
  32. * @date 2022/9/16 18:54
  33. */
  34. public function setSearch(): array
  35. {
  36. return [
  37. '%like%' => ['name','mobile'],
  38. '=' => ['type']
  39. ];
  40. }
  41. /**
  42. * @notes 自定查询条件
  43. * @return array
  44. * @author 段誉
  45. * @date 2022/10/25 16:53
  46. */
  47. public function queryWhere()
  48. {
  49. $where[] = ['status', '=', 1];
  50. $where[] = ['expiration_time', '>=', time()];
  51. if (!empty($this->params['cate_id'])) {
  52. $where[] = ['cate_id', 'like', '%' . ',' .$this->params['cate_id'].',' . '%'];
  53. }
  54. if (!empty($this->params['area_id'])) {
  55. $where[] = ['area_id', 'like', '%' . ',' .$this->params['area_id'].',' . '%'];
  56. }
  57. return $where;
  58. }
  59. /**
  60. * @notes 获取服务商列表
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @author 段誉
  66. * @date 2022/9/16 18:55
  67. */
  68. public function lists(): array
  69. {
  70. $orderRaw = 'expiration_time desc';
  71. $field = 'id,user_id,name,mobile,type,agricultural_machinery_model,images,cate_id,area_id,money,content,status,expiration_time,create_time';
  72. $result = UserService::field($field)
  73. ->where($this->queryWhere())
  74. ->where($this->searchWhere)
  75. ->orderRaw($orderRaw)
  76. ->append(['type_desc','cate_desc','area_desc','images','user'])
  77. ->limit($this->limitOffset, $this->limitLength)
  78. ->select()->toArray();
  79. // $articleIds = array_column($result, 'id');
  80. //
  81. // $collectIds = ArticleCollect::where(['user_id' => $this->userId, 'status' => YesNoEnum::YES])
  82. // ->whereIn('article_id', $articleIds)
  83. // ->column('article_id');
  84. // foreach ($result as &$item) {
  85. // $item['collect'] = in_array($item['id'], $collectIds);
  86. // }
  87. return $result;
  88. }
  89. /**
  90. * @notes 获取服务商数量
  91. * @return int
  92. * @author 段誉
  93. * @date 2022/9/16 18:55
  94. */
  95. public function count(): int
  96. {
  97. return UserService::where($this->searchWhere)
  98. ->where($this->queryWhere())
  99. ->count();
  100. }
  101. }