<?php
namespace Api\Model;

use Think\Model;

header("Content-Type:text/html;CharSet=UTF-8");
class CarouselModel extends Model
{
    /**
     * 首页轮播图
     * @param   $village_id 村ID
     * @return array
     */
    public function getList($village_id)
    {
        $data = array();
        // 读取该村轮播图
        $list = $this
            ->order("`sort` ASC,`id` ASC")
            ->where("`village_id`={$village_id}")
            ->select();
        if (!is_array($list) || count($list) === 0) {
            // 该村无独立轮播图, 读取首页轮播图
            $list = $this
                ->order("`sort` ASC,`id` ASC")
                ->where("`village_id`=0")
                ->select();
        }
        foreach ($list as $key => $value) {
            array_push($data, array(
                "img" => "http://" . $_SERVER['HTTP_HOST'] . __ROOT__ . "/Uploads/" . $value['img'],
                "good_id" => $value['good_id']
            ));
        }
        return $data;
    }
}