<?php 
class Member_Model extends Model{
	function __construct(){
		parent::__construct();
		
	}
	function checkVipNumber($vip,$userdata){
		//查询卡号数据
		$result		=	$this->db->where("vip_number",$vip['vip_number'])->get('member_vip');
		if($result->count()!=1){
			return false;
		}
		$vipNumber	=	$result->current();
		//检查有效日期
		$vip_start_time	=	strtotime($vipNumber->vip_start_time);
		$vip_end_time 	=	strtotime($vipNumber->vip_end_time);
		$current_time	=	time();
		if($vip_start_time<=$current_time&&$current_time<=$vip_end_time){
			if($vipNumber->vip_number_pwd==$vip['vip_number_pwd']&&$vipNumber->vip_number_status!=3){
				$this->db->where('vip_number',$vip['vip_number'])->update('member_vip',array('vip_number_status'=>3));
				$newUserVIP	=	array(
					'user_name'		=>	$vipNumber->vip_number,
					'user_pwd'		=>	$vipNumber->vip_number_pwd,
					'use_start_time'=>	$vipNumber->vip_start_time,
					"use_end_time"	=>	$vipNumber->vip_end_time,
					'user_role'		=>	3,
					'user_status'	=>	1
					);
				return $this->db->insert('user',array_merge($newUserVIP,$userdata));
			}
			else{
				return false;
			}
		}
		else{
			return false;
		}
	}
	function updateUserData($user,$user_id){
		return $this->db->where('user_id',$user_id)->update('user',$user);
	}
	function updateUserPwd($pwd,$user_id){
		$re	=	$this->db->where("user_id",$user_id)
		->where("user_pwd",md5($pwd['old_pwd']))
		->get('user')
		->count();
		if($re==1){
			return $this->db->where("user_id",$user_id)->update('user',array('user_pwd'=>md5($pwd['new_pwd'])));
		}
		else{
			return false;
		}
	}
	function getOrderList($page=false,$showline=30,$user_id=false){
		if($user_id){
			$this->db->where('client_id',$user_id);
		}
		if($page!==false){
			$this->db->limit($showline,$page*$showline-$showline);
		}
		$this->db->orderby("order_time","DESC");
		return $this->db->get("order");
	}
}