<?php
/** App登录控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <xiaoq@570035208.com>
 */

namespace Wxsmall\Controller;
class ProLevelController extends BaseController {
	public function _initialize(){
        parent::_initialize ();
    }
    public function index(){
    	$return['status']=1;
    	$user_info=$this->checkuserauth();
    	$uid=$u_map['id']=$user_info['id'];
    	// $u_map['id']=29;
		$info=M('Member')->where($u_map)->field(true)->find();
		$info['rank_name']=idtoname($info['rank_id'],'MemberRank','name');
        $member_rank = M('MemberRank')->where('status=1')->select();
        foreach ($member_rank as $key => $value) {
            $level_pro = unserialize($value['level_pro']);
            $member_rank[$key]['config']=$level_pro;
            if($level_pro['pro_type']==1)$new_array[]=$value['id'];
            else{
                unset($member_rank[$key]);
            }
        }
        // print_r($member_rank);
        $map = array();
        $map['name'] = 'PRO_GOODS';
        $res = M('Config')->field('value')->where($map)->find();

        $thisinfo=unserialize($res['value']);
        $goods_ids=implode(',',unserialize($thisinfo['temp']));
        $map['id'] = array('in',$goods_ids);
        $goods_list = M('Goods')->where($map)->field('id,img,goods_name,goods_sn,shop_price,market_price')->select();
        if($goods_list){
        	foreach ($goods_list as $key => $value) {
        		$goods_list[$key]['img']=thumb($value['img'],300,300);
                $goods_list[$key]['shop_price']=format_price($value['shop_price']);
                $goods_list[$key]['market_price']=format_price($value['market_price']);
                $goods_list[$key]['format_spec']=$value['format_spec'] = D("Common/GoodsAttr")->get_shop_attr($value['id']);
                $goods_list[$key]['cart_num']=$cart_num=0;


                if($uid){
                    $s_shop_id=get_wxsmall_shop_id();
                    $c_map = array();
                    $c_map['is_valid'] = 1;
                    $c_map['user_id'] = $uid;
                    $c_map['goods_id'] = $value['id'];
                    $c_map['shop_id'] = $s_shop_id;
                    $cart_num=M('Cart')->where($c_map)->getField('goods_num');
                    $goods_list[$key]['stock']=D('Wxsmall/Takeout')->format_stock($s_shop_id,$value);
                }
                if($cart_num)$goods_list[$key]['cart_num']=$cart_num;
        	}
        }
        $init_list=array();
        $cart_param=array();
        if($uid){
            $s_shop_id=get_wxsmall_shop_id();
            $cart_param['uid']=$uid;
            $cart_param['shop_id']=$s_shop_id;
            $init_list=D('Wxsmall/Takeout')->get_cart($cart_param);
        }
        $return['data']['init_list'] = $init_list;
    	$return['data']['info']=$info;
        $return['data']['rank_list']=$member_rank;
        $return['data']['goods_list']=$goods_list;
        $cart_info=array();
        if($uid)$cart_info=D("Wxsmall/Takeout")->get_cart_total_info($uid);
        $return['data']['cart_info']=$cart_info;
        $this->ajaxReturn($return);
    }
    public function info() {
    	$return['status']=3;
		$where['name'] = 'PRO_INFO';
        $res = M('Config')->field('value')->where($where)->find();
        $content=$res['value'];
        if($content){
        	$return['data']['content']=h($content);
        	$return['status']=1;
        }else{
        	$return['msg']="未获取到数据";
        }
		$this->ajaxReturn($return);
	}

}