<?php 
namespace Bll;
use \Pub\Fram;
use \Pub\SysFram;

class Code
{

    //--user code start--
	public static function DoWrite($Tel,$Num,$UserID=null,$ModuleID=1)
	{
	    if(!$UserID && \Pub\SysFram::CheckAdminLogin(false))
	        $UserID=\Pub\SysFram::GetLoginID();
	    $m=new \Model\Code();
	    $m->Mobile($Tel);
	    $m->Code($Num);
	    if(\Pub\Fram::CheckNum($UserID))
	       $m->UserId($UserID);
	    $m->ModuleId($ModuleID);
	    $m->Shijian(\Pub\Fram::Date());
	    return $m->Insert();
	}
	
	public static function Get_Code_Pic()
	{
	    return Fram::GetSession('sys_code_pic');
	}
	
	public static function Mobile_Get_Code($MobileNum)
	{
	    $m=new \Model\Code();
	    $r=\Bll\Code::GetList(1,1,[$m->_Mobile->w('=',$MobileNum),$m->_Shijian->w_and('>',\Pub\Fram::Data_Add_Fen(-20))]);
	    if($r)
	    {
	        \Pub\SysFram::RowToModel($m, $r[0]);
	        return $m->Code();
	    }
	    else
	       return false;
	}
	//--user code end--

	public static function Insert($m,$Conn=null)
	{
		return \Dal\Code::Insert($m,$Conn);
	}

	public static function Update($m,$Whare='',$Conn=null,$_IfRowCount=false)
	{
		return \Dal\Code::Update($m,$Whare,$Conn,$_IfRowCount);
	}
	
	public static function ForUpdate($Id,$Conn)
	{
		return \Dal\Code::ForUpdate($Id,$Conn);
	}

	public static function Del($Id,$Conn=null)
	{
		return \Dal\Code::Del($Id,$Conn);
	}

	public static function DelRows($IDS,$Conn=null)
	{
		return \Dal\Code::DelRows($IDS,$Conn);
	}

	public static function DelWhere($w_arr,$Conn=null)
	{
		return \Dal\Code::DelWhere($w_arr,$Conn);
	}
	
	public static function Row($Id = -1,$Whare = "",$Fields = "*",$Conn=null,$ForUpdate=false)
	{
	    return \Dal\Code::Row($Id,$Fields,$Whare,$Conn,$ForUpdate);
	}
	
	public static function Column($Id,$SqlField='*',$Whare='',$Conn=null)
	{
	    $Id=intval($Id);
	    if(Fram::CheckNum($Id))
	        $Whare=["ID=?",[$Id]];
	    return \Dal\Code::Column($SqlField,$Whare,$Conn);
	}
	
	public static function Model($Id,$Whare = "",$Conn=null,$ForUpdate=false)
	{
	    return \Dal\Code::Model($Id,$Whare,$Conn,$ForUpdate);
	}
	
	public static function GetList($_PageNum,$_PageSize,$_Where="",&$_RecordCount=0,$_Fields="",$_OrderBy="",$Conn=null)
	{
	    if(!$_OrderBy || $_OrderBy=='')
	        $_OrderBy='ID desc';
	    return \Dal\Code::GetList($_PageNum,$_PageSize,$_RecordCount,$_Fields,$_Where,$_OrderBy,$Conn);
	}
	//index列表
	public static function GetListByIndex($_LastID,$_PageSize,$_Where="",&$_RecordCount=0,$_Fields="",$_OrderBy="",$Conn=null)
	{
	    if(!$_OrderBy || $_OrderBy=='')
	        $_OrderBy='ID desc';
	    return \Dal\Code::GetListByIndex($_LastID,$_PageSize,$_RecordCount,$_Fields,$_Where,$_OrderBy,$Conn);
	}
}