<?php
/**
 * 会员中心
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Wxsmall\Controller;
class ExtensionMatterController extends BaseController {
	public function _initialize(){
        parent::_initialize ();
    }
	public function posters(){
		$return = array('status'=>0,'msg'=>'参数错误');
		$param = I('param.');
		$goods_id = $param['goods_id'];
		$user_info=$this->checkuserauth();
		$uid=$user_info['id'];
		if($goods_id && $uid){
			// $tuijian_code = U('Mobile/goods/goods_cont',array('id'=>$goods_id,'eid'=>$uid,'appid'=>C('appid')),true,true);
			// $tj_code = U('Home/Qrcode/index',array('data'=>urlencode($tuijian_code),'appid'=>C('appid')),true,true);
			$invite_key = base64_encode($uid);
			$param_code=array();$param_code['width']=120;
			$param_code['type']=1;
			$param_code['path'] = "pages/takeout/cont/cont?invite_key=".$invite_key."&id=".$goods_id;//小程序参数
			$wxsmall = new \Common\Vendor\Wxsmallopen;
			$tj_code=$wxsmall->get_location_small_code($param_code);

			$map = array();$map['id'] = $goods_id;
			$goods_info = M('Goods')->where($map)->field('goods_name,market_price,shop_price')->find();
			$list = $postdata = array();
			$map = array();$map['goods_id'] = $goods_id;
			$list = M("GoodsMatter")->where($map)->field(true)->order('sort desc')->select();
			if($list){
				foreach ($list as $key => $value) {
					$list[$key]['matter_img']=format_url($value['matter_img']);
				}
				$return['big_pic'] = format_url($list[0]['matter_img']);
				$return['matter_img_id'] = $list[0]['id'];
				$return['status'] = 1;
			}else{
				$return['status'] = 0;
			}
			$return['list'] = $list;
			$return['tj_code'] = $tj_code;
			$return['goods_name'] = $goods_info['goods_name'];
			$return['shop_price'] = format_decimal($goods_info['shop_price']);
			$return['market_price'] = format_decimal($goods_info['market_price']);
		}
        $this->ajaxReturn($return);
    }
	/**
     * 获取门店小程序二维码
     */
    public function save_xcx_matter(){
		$return = array('status'=>0,'msg'=>'参数错误');
		$user_info=$this->checkuserauth();
		$uid=$user_info['id'];
		$param = I('param.');
		$goods_id = $param['goods_id'];
		$matter_img_id = $param['matter_img_id'];
		if($uid && $goods_id && $matter_img_id){
			$map = array();$map['goods_id'] = $goods_id;$map['id'] = $matter_img_id;
			$matter_img = M("GoodsMatter")->where($map)->getField('matter_img');
			if($matter_img){
				$ret = matter_code($uid,0,$goods_id,$matter_img,$matter_img_id);
				if($ret['status'] == 1){
					$img_url = $ret['url'];
				}
			}
			if($img_url){
				$return['status'] = 1;
				$return['bc_url'] = $img_url;
			}
		}
		$this->ajaxReturn($return);
    }
	
}