<?php
namespace Api\Model;

use Think\Model;

header("Content-Type:text/html;CharSet=UTF-8");
class CarouselCityModel extends Model
{
    /**
     * 首页轮播图
     * @return array
     */
    public function getList($village_id = null)
    {
        if (is_numeric($village_id) && $village_id > 0) {
            $where = "`village_id`={$village_id}";
        } else {
            $where = "`village_id`=0";
        }
        $count = $this->where($where)->count();
        if (!$count) {
            $where = "`village_id`=0";
        }
        $data = array();
        $list = $this
            ->order("`sort` ASC,`id` ASC")
            ->where($where)
            ->select();
        foreach ($list as $key => $value) {
            array_push($data, array(
                "img" => "http://" . $_SERVER['HTTP_HOST'] . __ROOT__ . "/Uploads/" . $value['img']
            ));
        }
        return $data;
    }
}