<?php
/**
 * Created by PhpStorm.
 * User: 中闽 < 1464674022@qq.com >
 * Date: 2019/12/5
 * Time: 17:44
 */

namespace app\api\controller;


use app\api\controller\base\Base;
use app\common\model\Announcement;
use app\common\model\ConfigOption;
use app\common\model\Webconfig;

class Index extends Base
{
    public function index()
    {
        $this->json_success('success', ['ip' => $this->request->ip()]);
    }

    //站点信息接口
    public function siteinfo()
    {
        $banners = (new ConfigOption())->where(['pid' => 1, 'status' => ConfigOption::STATUS_OPEN])->order('sort desc')->select();
        foreach ($banners as $key => $item) {
            $item['image'] = geturl($item->image, '', true);
            $banners[$key] = $item;
        }
        $boxs = (new ConfigOption())->where(['pid' => 2, 'status' => ConfigOption::STATUS_OPEN])->order('sort desc')->select();
        foreach ($boxs as $key => $item) {
            $item['image'] = geturl($item->image, '', true);
            $boxs[$key] = $item;
        }
        $announcements = (new Announcement())->order('id desc')->limit(6)->select();
        foreach ($announcements as $key => $item) {
            $item['thumb_url'] = $item->getThumb();
            $announcements[$key] = $item;
        }
        $this->json_success('success', [
            "sitename" => systemName(),
            "banners" => $banners,//轮播图
            "boxs" => $boxs,//模块
            "contact_us" => "0595-88150395",//联系电话
            "announcements" => $announcements,//公告
            "notice" => [
                "title" => Webconfig::getValue('notice_title'),
                "content" => Webconfig::getValue('notice_content'),
            ],
            "appointment_time_limit" => Webconfig::getValue('appointment_time_limit'),
        ]);
    }
}
