<?php
namespace app\mobile\controller;
use \think\Controller;
/**
 * 
 * @author admin
 *			单点登录操作
 *			用户登录vip系统时，传openid给vipshop，vishop建立单方法 接收openid
 */

class Oauth extends Controller{
	function index() {
		//接受vip传过来的openid
		$openid = input("get.authcode");
		$openid = think_decrypt($openid);
		if(!empty($openid)){
			session('openid',$openid);
			//店配置
            $shopData = isShopMain();
            if($shopData['url']){
                session('vip_url',$shopData['url']);
                session('addr',$shopData['url']);
            }
			$brand = getSiteBrand();
            session('brand_id',$brand['id']);
            if(!session('vip_url')){
                session('vip_url',$brand['vip_url']);    
            }
            if(!session('addr')){
                session('addr',$brand['vip_url']);    
            }
            session('appid',$brand['wx_appid']);
		}
		$res = db("m_users","dbvip")->where("openid",$openid)->find();
		if(!empty($res)){
			/*$userArr = db("m_users u","dbvip")->join("m_users_phone p","u.id=p.userid","left")
		    		->field("u.simg,u.openid,u.brandid,p.id,p.phone,p.pay_password,p.password,p.money,p.total_score")
		    		->where("u.openid",session('openid'))->find();*/
			session('user',$res);
			setcookie('user_id', $res['id'], null, '/');
			//setcookie('user_id', $res['result']['id'], null, '/');
			setcookie('is_distribut', $res['result']['is_distribut'], null, '/');
		}
	}
}