<?php
/**
 * 搜索
 * @Copyright (C) 2017 汉潮 All rights reserved.
 * @License http://mendian.hanchao9999.com
 * @Author sunshine <1090855764@qq.com>
 */
namespace Mobile\Controller;
class ProLevelController extends BaseController {
    public function _initialize()
    {
        parent::_initialize();
        if(!MID){
			cookie('forward',U('Mobile/'.CONTROLLER_NAME.'/'.ACTION_NAME));
			$this->redirect('Mobile/Login/index');
		}
    }
	public function index() {
		$u_map['id']=MID;
		$info=M('Member')->where($u_map)->field(true)->find();
		$this->assign('info',$info);
		// $postdata = I('param.');
        // if(empty($postdata))return false;
        $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();

        $info=unserialize($res['value']);
        $goods_ids=implode(',',unserialize($info['temp']));
        $map['id'] = array('in',$goods_ids);
        $goods_list = M('Goods')->where($map)->field(true)->select();
        $shop_id = get_wxsmall_shop_id();
        if($goods_list){
            foreach ($goods_list as $key => $value) {
                $goods_list[$key]['format_spec'] = D("Common/GoodsAttr")->get_shop_attr($value['id']);
                $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]['cart_num']=$cart_num=0;
                if(MID){
                    $c_map = array();
                    $c_map['is_valid'] = 1;
                    $c_map['user_id'] = MID;
                    $c_map['goods_id'] = $value['id'];
                    $c_map['shop_id'] = $shop_id;
                    $cart_num=M('Cart')->where($c_map)->getField('goods_num');
                }
                if($cart_num)$goods_list[$key]['cart_num']=$cart_num?$cart_num:0;
            }
        }
        $this->assign('shop_id',$shop_id);
        $this->assign('rank_list',$member_rank);
        $this->assign('goods_list',$goods_list);
        $this->assign('tplseo_title','等级晋升'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','等级晋升');
        $this->cart_list($shop_id);
		$this->display();
	}
    //购物车列表
    public function cart_list($shop_id){
        if(!$shop_id){
            $cart_info=array();
        }else{
            $return=D('Mobile/Takeout')->get_cart_list($shop_id);
            if($return['status'] == 1){
                $cart_info = $return['data'];
            }
        }
        $this->assign($cart_info);
        $html=$this->fetch('Takeout/footer_cart');
        $this->assign('cart_html',$html);
    }
	public function info() {
		$where['name'] = 'PRO_INFO';
        $res = M('Config')->field('value')->where($where)->find();
        $this->assign('content',$res['value']);
        $this->assign('tplseo_title','等级晋升规则'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','等级晋升规则');
		$this->display();
	}
}