From d4c1354ee792da977193e3933b2fcaa36c4ad0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E6=A1=83?= <1098598843@qq.com> Date: Thu, 9 Feb 2023 14:42:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Village.php | 55 +++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/app/api/controller/Village.php b/app/api/controller/Village.php index e0ba933..1bfc76b 100644 --- a/app/api/controller/Village.php +++ b/app/api/controller/Village.php @@ -17,7 +17,7 @@ class Village extends BaseController * @var array */ protected $middleware = [ - Auth::class => ['except' => ['get_list','get_ranking_list','get_detail','get_json','get_village','thumbs_up','get_ranking_town'] ] + Auth::class => ['except' => ['get_list','get_ranking_list','get_detail','get_json','get_village','thumbs_up','get_ranking_town','get_town_list'] ] ]; /** @@ -653,5 +653,58 @@ class Village extends BaseController } } + /** + * 获取镇 + * + */ + public function get_town_list($area_id=0,$street_id=0,$type=1, $page = 1) + { + if ($area_id){ + $where['area_id'] = $area_id; + } +// if ($street_id){ +// $where['street_id'] = $street_id; +// } + if($type==1){ + $where['is_hot'] = 1; + } + if($type==2){ + $where['is_tourism'] = 1; + } + $where['status'] = 1; + $list = Db::table('fa_szxc_village') + ->where($where) + ->where('village_id','=',0) + ->page($page,10) + ->field('id,title,address,people_num,images,views,likes,createtime,area_id,street_id,village_id') + ->order('likes desc') + ->withAttr('images', function ($value, $data) { + if ($data['images'] != '') { + return explode(',',$data['images']); + } + }) + ->withAttr('is_dz', function ($value, $data) { + // 判断redis + $user_id = JWT_UID; + if($user_id){ + $name = $user_id . $data['id']; + $is_zan = Cache::store('redis')->get($name); + if($is_zan){ + return 1; + }else{ + return 0; + } + }else{ + return 0; + } + }) + ->select(); + if($list){ + $this->apiSuccess('获取成功',$list); + }else{ + $this->apiError('暂无数据',[]); + } + } + }