<?php
/**
 * 搜索
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Mobile\Controller;
class ShopController extends BaseController {
	public function _initialize(){
		parent::_initialize();
        if(!checksiteauth('MenDian')){ exit;}
		$param=I('param.');
		$param['request_type']='wap';
		$param['mid']=MID;
		$this->assign($param);
		$shop_id=I('id');
		$result=D('Common/Shops')->get_common($param);
		//print_r($result);
		if($result['status']==0){$this->error($result['msg']);}
        $this->assign($result);
    }
    public function index(){
		$page=I('page',1);
		$result=D('Common/Shops')->get_shop_goods($this->shop_id,8,$page,2);
		$this->assign($result);
		$this->assign('tplseo_title','店铺中心'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','店铺中心');
        $this->display();
    }
	public function lists(){
		$param=I('param.');
		$result=D('Common/Shops')->get_lists($this->shop_id,$param);
		$this->assign($result);
		$this->assign('tplseo_title','商品列表'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','商品列表');
        $this->display();
    }
	public function get_goods_list(){
        $param=I('param.');
		if($param['order']){
			$param[$param['order']]=1;
			unset($param['order']);
		}
		$result=D('Common/Shops')->get_lists($this->shop_id,$param);
        $this->assign($result);
        $list_html=$this->fetch('goods_list');
		if($result['glist']['list'])$return['status']=1;
		else$return['status']=0;
        $return['data']=$list_html;
        $this->ajaxReturn($return);
    }
	public function activity_list(){
        $map['shop_id']=$this->shop_id;
    	$map['status']=1;
    	$order='id desc';
    	$field='id,title,content,addtime,updatetime';
    	$list=page_list('ShopsArticle',$map,$order,$field);
		$this->assign('tplseo_title','店铺动态'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','店铺动态');
    	$this->assign($list);
    	$this->display();
    }
    public function activity_cont(){
    	$id=I('article_id');
    	if(empty($id)) $this->error(L('PARAM_ERR'));
    	$where['id']=$id;
    	$info=M('ShopsArticle')->where($where)->field('title,content,addtime')->find();
    	$this->assign($info);
		$this->assign('tplseo_title','动态详情'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','动态详情');
    	$this->display();
    }
	public function collect(){
        $id=I('id');
        $data=D('Common/Shops')->collect_shop($id);
        $this->ajaxReturn($data);
	}
	public function mendian_index(){
        $this->redirect('Index/index');
		$map = $map_s = $g_map = $maps = array();
		$id = I('param.id');
		$map_s['status'] = 1;
		$map_s['id'] = $id;
		$nearby_info = M('Shops')->where($map_s)->field(true)->find();
		$this->assign('nearby_info', $nearby_info);
		$this->assign($id);
		// 维信
		$Jssdk = new \Common\Vendor\Jssdk();
        $AddCartParam = $Jssdk->GetSignPackage();
        $this->assign('AddCartParam',$AddCartParam);

        if(!$id){
			$this->error('参数错误');
		}
		
		//查询服务
		$map = array();
		$map['status'] = 1;
		$shop_ids = ','.$id.',';
		$map['goods_type'] = 4;
		$map['publish_wait'] = 1;
		$map['is_delete'] = 0;
		$map['_string'] = "shop_ids like '%".$shop_ids."%' OR shop_ids='0'";
		
		$map['goods_type'] = array('IN','4,6');
		$service_num = M('Goods')->where($map)->count();
		
		//该门店商品数量
		$g_map['shop_id'] = $id;
		$goods_num = M('ShopsGoods')->where($g_map)->count();
		$return=D('Mobile/Dp')->get_dp_goods($id);
		if(!empty($return['status'])){
			$this->assign($return);
		}
		
		//代金券
		$member_info = session('member_info');
        $list = D('Shop/CouponsGet')->coupons_list($member_info['id']);
        $coupons_num = count($list['info']);
		$this->assign('coupons_list',$list['info']);
		
		
		// echo "<pre>";
		// print_r($zong);exit;
		$this->assign('zong',$zong);
		$this->assign('service_num',$service_num);
		$this->assign('goods_num',$goods_num);
		$this->assign('coupons_num',$coupons_num);
		$this->display();
	}
		//门店全景图
	public function shop_allmap(){
		$id=I('id');
		$map['id']=$id;
		$map_info=M('Shops')->where($map)->field('id,xpoint,ypoint')->find();
        $this->assign($map_info);
		$this->assign('tplseo_title','门店全景图'.'_'.C('WEB_SITE_TITLE'));
        $this->display();
	}
	//门店商品标签评论
	public function shop_comment(){
		$return = array();
		$shop_id = I('id');
		if(empty($shop_id)){
			$this->error('参数错误！');
		}
		$return=D('Dp')->get_dp_goods($shop_id);
		if(!empty($return['status'])){
			$this->assign($return);
		}
		$this->display();
	}
}