<?php
namespace Api\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class ManyStoreController extends Controller
{
	//子门店列表
	public function SubsidiaryStore(){
		$business_id = I('post.business_id');
		if (empty($business_id)) apiReturn(['status' => -1, 'msg' => '商户id不能为空']);
		$where = "(parent_id = {$business_id} OR id = {$business_id}) AND status = 1";

		$data = M('Admin') -> field('id,business_name,picture,business_phone,business_address,lnglat') -> where($where) -> select();
		foreach ($data as $key => $value) {
			$data[$key]['picture'] = 'https://'.$_SERVER['HTTP_HOST'].'/canyin/Uploads/'.$value['picture'];
		}

		apiReturn(['status' => 1, 'msg' => '已获取数据', 'data' => $data]);

	}

	//首页门店
	public function IndexSubsidiaryStore(){
		$business_id = I('post.business_id');
		if (empty($business_id)) apiReturn(['status' => -1, 'msg' => '商户id不能为空']);
		$where = "(parent_id = {$business_id} AND status = 1 AND index_status = 1) OR (id = {$business_id} AND status = 1)";

		$data = M('Admin') -> field('id,business_name,picture,business_phone,business_address,lnglat') -> where($where) -> select();
		foreach ($data as $key => $value) {
			$data[$key]['picture'] = 'https://'.$_SERVER['HTTP_HOST'].'/canyin/Uploads/'.$value['picture'];
		}

		apiReturn(['status' => 1, 'msg' => '已获取数据', 'data' => $data]);
	}

	//首页展示图片列表
    public function IndexShowPicture(){
		$business_id = I('post.business_id');
		if (empty($business_id)) apiReturn(['status' => -1, 'msg' => '商户id不能为空']);

		$data = M('Index_show_picture') -> field('picture') -> where("admin_id = {$business_id}") -> order('id DESC') -> select();
		foreach ($data as $key => $value) {
			$data[$key]['picture'] = 'https://'.$_SERVER['HTTP_HOST'].'/canyin/Uploads/'.$value['picture'];
		}

		apiReturn(['status' => 1, 'msg' => '已获取数据', 'data' => $data]);		
    }
}