diff --git a/app/api/controller/Village.php b/app/api/controller/Village.php index 8599043..011fe1e 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_detail','get_json','get_village','thumbs_up'] ] + Auth::class => ['except' => ['get_list','get_ranking_list','get_detail','get_json','get_village','thumbs_up'] ] ]; /** @@ -74,6 +74,50 @@ class Village extends BaseController } } + /** + * 获取村庄 + * + * //php think crud -t slide_info -c work/slideinfo + * php think menu -c work/slideinfo + */ + public function get_ranking_list($page = 1,$limit=10) + { + + $where['status'] = 1; + $list = Db::table('fa_szxc_village') + ->where($where) + ->page($page,$limit) + ->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('暂无数据',[]); + } + } + + // 获取村庄详情 public function get_detail($id){ if (empty($id)) {