<?php
namespace  App\Models;
class System_log extends BaseModel {
	protected $table = "system_log";
	public $timestamps = false;
	
	//获取日志列表
	function getLoglist($value='',$type=1,$page=10,$sort=4,$ads='desc') {
		$key = $this->getFeild($type);
		$sort = is_integer($sort)?$this->getFeild($sort):$sort;
		if(empty($value)){
			$data = $this->select('identity','system_log.status as logstatus','ip','operation_time','system_identity','operation','loginname','root_id','system_user.status as userstatus')->join('system_user','id','system_identity')->orderby($sort,$ads)->paginate($page);
		}else if(is_array($value)){
			$data = $this->where($value)->select('identity','system_log.status as logstatus','ip','operation_time','system_identity','operation','loginname','root_id','system_user.status as userstatus')->join('system_user','id','system_identity')->orderby($sort,$ads)->paginate($page);
		}else{
			$data = $this->where($key,$value)->select('identity','system_log.status as logstatus','ip','operation_time','system_identity','operation','loginname','root_id','system_user.status as userstatus')->join('system_user','id','system_identity')->orderby($sort,$ads)->paginate($page);
		}
		
		if (!$data) {
			return -7011000102; //没有列表数据
		}
		return $data->toArray();
	}
	
	//获取日志详情
	function getLogDetails($value,$type=1,$jointable='',$columnn='',$columnw='') {
		$key = $this->getFeild($type);
		if(empty($jointable)){
			$data = $this->where($key, $value)->first();
		}elseif($jointable=='account_bank'){
			$data = $this->select('money_recharge.account_name as account','order_id as trade_id','bank_name','account_bank.account_name','bank_number','bank_address','apply_time as money_time','money','money_recharge.status','recharge_type as trade_type','reason')->where($key, $value)->join($jointable,$this->table.'.'.$columnn,$jointable.'.'.$columnw)->first();
		}else{
			$data = $this->where($key, $value)->join($jointable,$this->table.'.'.$columnn,$jointable.'.'.$columnw)->first();
		}
		;
		if (!$data) {
			return -7011000202; //没有日志信息
		}
		return $data->toArray();
	}
	
	//字段对应值
	private function getFeild($num){
		$data = array(
			'1' => 'identity',
			'2' => 'status',
			'3' => 'ip',
			'4' => 'operation_time',
			'5' => 'random',
			'6' => 'apply_time',
			'7' => 'system_identity',
		);
		return $data[$num];
	}
	//插入操作日志
	function insertData($data){
        $res=$this->insert($data);
        if(!$res){
            return -7050022222;//添加失败
        }
        return 1;
    }

}