<?php
/**
 * 会员账户
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */

namespace Mobile\Controller;
use Think\Controller;
class MyMoneyController extends BaseController {
	public function _initialize(){
		parent::_initialize ();
		if(!MID){
			cookie('forward',U('Mobile/'.CONTROLLER_NAME.'/'.ACTION_NAME));
			$this->redirect('Mobile/Login/index');
		}
		if($this->m_info['is_tmp']==1&&!$this->m_info['mobile']){
			session('format_url',U('Mobile/'.CONTROLLER_NAME.'/'.ACTION_NAME));
			$this->redirect('Mobile/Login/perfect');
		}elseif($this->m_info['is_tmp']==1&&$this->m_info['mobile']){
			$this->error('您已经领取过会员卡了！');exit;
		}
		$this->account_type=strtoarray(C('ACCOUNT_TYPE'));$this->assign('account_type',$this->account_type);
		$this->account_status=strtoarray(C('ACCOUNT_STATUS'));$this->assign('account_status',$this->account_status);
		
		$user_info=M('Member')->where('id='.MID)->field(true)->find();
		$grade_info = getRankMoney(MID);//获取等级差额
		// user_ranks(MID);
		$this->assign('user_info',$user_info);
		$this->assign($grade_info);
   	}
    public function index(){
		$c_map = array();$c_map['uid']=MID;$c_map['coupons_type'] = 1;
		$n_count=M('CouponsGet')->where($c_map)->field('id')->count();
		$integral_list=D('Common/Member')->integral($postdata);
        $integral_list['allpoints'] = Intval($integral_list['allpoints']);
		$this->assign($integral_list);
		$this->assign('n_count',$n_count);
        $this->assign('tplseo_title','我的资金'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','我的资金');
        $this->display();
    }
	//冻结资金
    public function frozen($type = 0){
		$page=I('param.page');
		$page=$page?$page:1;
		$map['uid']=MID;$map['type']=2;$map['role']=0;
        $pagesize = 50;
		$info=page_list('AccountLog',$map,'change_time desc,id desc',true,$pagesize,'',$page);
        if($info['count'] >= $pagesize*$page){
            $info['show'] = 1;
        }else{
            $info['show'] = 0;
        }
		if ($type == 1) return $info;
		$this->assign($info);
        $this->assign('tplseo_title','冻结资金'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','冻结资金');
        $this->display();
    }
	public function get_frozen_list(){
        $return['status'] = 0;
        $data = $this->frozen(1);
        if (empty($data['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('frozen_list');
        $return['data'] = $list_html;
        $return['show'] = $data['show'];
        $this->ajaxReturn($return);
    }
	//积分
    public function integral($type = 0){
		$postdata=I('param.');
		$integral_list=D('Common/Member')->integral($postdata);
        $integral_list['allpoints'] = intVal($integral_list['allpoints']);
        foreach($integral_list['points_details']['list'] as $k=>$v){
            $integral_list['points_details']['list'][$k]['change_num'] = intVal($v['change_num']);
        }
		if ($type == 1) return $integral_list;
		$this->assign($integral_list);
        $this->assign('tplseo_title','我的积分'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','我的积分');
        $this->display();
    }
	public function get_integral_list(){
        $return['status'] = 0;
        $data = $this->integral(1);
        if (empty($data['points_details']['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('integral_list');
        $return['data'] = $list_html;
		$return['show'] = $data['show'];
        $this->ajaxReturn($return);
    }
    //积分
    public function grade_integral($type = 0){
        $postdata=I('param.');
        $integral_list=D('Common/Member')->integral($postdata,3);
        if ($type == 1) return $integral_list;
        $this->assign($integral_list);
        $this->assign('tplseo_title','我的积分'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','我的积分');
        $this->display();
    }
    public function get_grade_integral_list(){
        $return['status'] = 0;
        $data = $this->grade_integral(1);
        if (empty($data['points_details']['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('grade_integral_list');
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
	//未使用代金券
    public function bonu($type = 0){
		$postdata=I('param.');
		$bonu_list=D('Common/Member')->redPacket(1,$postdata);
		if ($type == 1) return $bonu_list;
		foreach($bonu_list['list'] as $key=>$value){
			$shop_ids = idtoname($value['bonus_id'],'Bonu','shop_id','id',false);
			if($shop_ids){
				$bonu_list['list'][$key]['shop_id'] = explode(',',trim($shop_ids,","));
			}else{
				$bonu_list['list'][$key]['shop_id'] = array();
			}
		}
		$this->assign($bonu_list);
        $this->assign('tplseo_title','我的代金券'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','我的代金券');
        $this->display();
    }
	public function get_bonu_list(){
        $return['status'] = 0;
        $data = $this->bonu(1);
        if (empty($data['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('bonu_list');
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
    //已使用代金券
    public function used_bonu($type = 0){
		$postdata=I('param.');
		$bonu_list=D('Common/Member')->redPacket(2,$postdata);
		if ($type == 1) return $bonu_list;
		$this->assign($bonu_list);
        $this->assign('tplseo_title','已使用代金券'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','已使用代金券');
        $this->display();
    }
	public function get_used_bonu_list(){
        $return['status'] = 0;
        $data = $this->used_bonu(1);
        if (empty($data['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('used_bonu_list');
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
    //过期代金券
    public function overdue_bonu($type = 0){
		$postdata=I('param.');
		$bonu_list=D('Common/Member')->redPacket(3,$postdata);
		if ($type == 1) return $bonu_list;
		$this->assign($bonu_list);
        $this->assign('tplseo_title','已过期代金券'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','已过期代金券');
        $this->display();
    }
	public function get_overdue_bonu_list(){
        $return['status'] = 0;
        $data = $this->overdue_bonu(1);
        if (empty($data['list'])) $this->ajaxReturn($return);

        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('overdue_bonu_list');
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
	/**
	  *删除我的代金券
	  */
	public function del_redPacket($id){
		$data=D('Common/Member')->delete_redPacket($id);
        $this->ajaxReturn($data);
	}

    /**
     * 我的礼品
     */
    public function win_gift($is_ajax = 0){
        $postdata=I('param.');
        $user_id=MID;
        // $map['type']=array('IN','1,2');
        if($postdata['status']==0){
            $map['check_status']=0;
        }else{
            $map['check_status']=1;
        }
		$order = 'id desc';
		// $map['gift_id'] = array('neq',0);
		// $map['gift_type'] = array('neq',1);
        $gift_info=D("Common/Member")->get_win_gift_list($map,'',$order);
        if ($is_ajax == 1) return $gift_info;
        $this->assign($gift_info);
        $this->assign($postdata);
        $list_html=$this->fetch('win_gift_list');
		
        $this->assign('list_html',$list_html);
        $this->assign('tplseo_title','我的礼品'.'_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','我的礼品');
        $this->display();
    }
    public function get_win_gift_list(){
        $return['status'] = 0;
        $data = $this->win_gift(1);
        if (empty($data['list'])) $this->ajaxReturn($return);
        $return['status'] = 1;
        $this->assign($data);
        $list_html = $this->fetch('win_gift_list');
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
	public function win_gift_cont(){
		$id=I('id');
        if(!$id){
            $this->error('参数错误！');exit;
        }
		$map = array();
		$map['id'] = $id;
        $gift_info=M('WinGift')->where($map)->field(true)->find();
		
		
		$map = array();
		$map['id'] = $gift_info['gift_id'];
		$prize_info = M('Prize')->where($map)->field(true)->find();
		if($prize_info['prize_type'] == 4){
			$map = array();$map['id'] = $prize_info['prize_goods'];
			$prize_info['prize_goods'] = M('Coupons')->where($map)->getField('title');
		}
        $this->assign('prize_info',$prize_info);
        $this->assign('gift_info',$gift_info);
		
        $this->assign('tplseo_title','礼品详情_'.C('WEB_SITE_TITLE'));
        $this->assign('page_title','礼品详情');
        $this->display();
	}
}
?>