<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        //首页固定图
        $index_image = localpath_to_netpath(config('site.index_image'));

        //产品首页分类
        $fenlei = [];
        $fenlei[] = [
            'id' => -1,
            'name' => '热门推荐',
            'weigh' => 0,
            'image' => '',
        ];
        $protag = Db::name('protag')->order('weigh desc')->select();
        $protag = list_domain_image($protag,['image']);
        foreach($protag as $val){
            $fenlei[] = $val;
        }


        //轮播
        $banner = Db::name('banner')->order('weigh desc')->select();
        $banner = list_domain_image($banner,['image']);

        //自动去掉下架的
        foreach($banner as $key => $val){
            $is_show = Db::name('product')->where('id',$val['product_id'])->value('is_show');
            if($is_show == 0){
                $banner[$key]['product_id'] = 0;
            }
        }

        //
        $rs = [
            'index_image' => $index_image,
            'protag' => $fenlei,
            'banner' => $banner,
            'zhitongche' => config('site.index_zhitongche'),
            'baoche' => config('site.index_baoche'),
        ];
        $this->success(1,$rs);
    }

}
