| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\api\lists\service;
- use app\api\lists\BaseApiDataLists;
- use app\common\enum\YesNoEnum;
- use app\common\lists\ListsSearchInterface;
- use app\common\model\article\Article;
- use app\common\model\asset\AssetArea;
- use app\common\model\article\ArticleCollect;
- use app\common\model\agricultural_machinery\UserService;
- /**
- * 服务商列表
- * Class ArticleLists
- * @package app\api\lists\article
- */
- class ServiceLists extends BaseApiDataLists implements ListsSearchInterface
- {
- /**
- * @notes 搜索条件
- * @return \string[][]
- * @author 段誉
- * @date 2022/9/16 18:54
- */
- public function setSearch(): array
- {
- return [
- '%like%' => ['name','mobile'],
- '=' => ['type']
- ];
- }
- /**
- * @notes 自定查询条件
- * @return array
- * @author 段誉
- * @date 2022/10/25 16:53
- */
- public function queryWhere()
- {
- $where[] = ['status', '=', 1];
- $where[] = ['expiration_time', '>=', time()];
- $where[] = ['audit_status','=',1];
- return $where;
- }
- /**
- * @notes 获取服务商列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author 段誉
- * @date 2022/9/16 18:55
- */
- public function lists(): array
- {
- $wheres = [] ;
- if (!empty($this->params['area_id'])) {
- $cwhere=[];
- $cwhere[]=['pid','=',$this->params['area_id']];
- $cate_list = AssetArea::where($cwhere)->select() ->toArray();
- $cate_ids = array_column($cate_list,'id');
- array_push($cate_ids,(int)$this->params['area_id']);
- $ccs = [];
- foreach ($cate_ids as &$v){
- $ccs[]='%,'.$v.',%';
- }
- $wheres[] = ['area_id', 'like', $ccs, 'or'];
- }
- $catwhere=[];
- if (!empty($this->params['cate_id'])) {
- $cate_id_arr = explode(',',$this->params['cate_id']);
- $cats = [];
- foreach ($cate_id_arr as &$v){
- $cats[]='%,'.$v.',%';
- }
- $catwhere[] = ['cate_id', 'like', $cats, 'or'];
- }
- $mcatwhere=[];
- if (!empty($this->params['mechanical_cate_id'])) {
- $m_cate_id_arr = explode(',',$this->params['mechanical_cate_id']);
- $mcats = [];
- foreach ($m_cate_id_arr as &$v){
- $mcats[]='%,'.$v.',%';
- }
- $mcatwhere[] = ['mechanical_cate_id', 'like', $mcats, 'or'];
- }
- $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';
- $result = UserService::field($field)
- ->where($this->queryWhere())
- ->where($this->searchWhere)
- ->where($wheres)
- ->where($catwhere)
- ->where($mcatwhere)
- ->append(['type_desc','cate_desc','area_desc','images','user','mechanical_cate_desc'])
- ->limit($this->limitOffset, $this->limitLength)
- ->select()->toArray();
- return $result;
- }
- /**
- * @notes 获取服务商数量
- * @return int
- * @author 段誉
- * @date 2022/9/16 18:55
- */
- public function count(): int
- {
- $wheres = [] ;
- if (!empty($this->params['area_id'])) {
- $cwhere=[];
- $cwhere[]=['pid','=',$this->params['area_id']];
- $cate_list = AssetArea::where($cwhere)->select() ->toArray();
- $cate_ids = array_column($cate_list,'id');
- array_push($cate_ids,(int)$this->params['area_id']);
- $ccs = [];
- foreach ($cate_ids as &$v){
- $ccs[]='%,'.$v.',%';
- }
- $wheres[] = ['area_id', 'like', $ccs, 'or'];
- }
- $catwhere=[];
- if (!empty($this->params['cate_id'])) {
- $cate_id_arr = explode(',',$this->params['cate_id']);
- $cats = [];
- foreach ($cate_id_arr as &$v){
- $cats[]='%,'.$v.',%';
- }
- $catwhere[] = ['cate_id', 'like', $cats, 'or'];
- }
- $mcatwhere=[];
- if (!empty($this->params['mechanical_cate_id'])) {
- $m_cate_id_arr = explode(',',$this->params['mechanical_cate_id']);
- $mcats = [];
- foreach ($m_cate_id_arr as &$v){
- $mcats[]='%,'.$v.',%';
- }
- $mcatwhere[] = ['mechanical_cate_id', 'like', $mcats, 'or'];
- }
- return UserService::where($this->searchWhere)
- ->where($this->queryWhere())
- ->where($wheres)
- ->where($catwhere)
- ->where($mcatwhere)
- ->count();
- }
- }
|