<?php
/**
 * Created by PhpStorm.
 * User: ywl
 * Date: 2017/4/14
 * Time: 11:38
 */

namespace App\User\Services;


use App\Exceptions\ApiException;
use App\Services\CommonBaseService;
use App\User\Models\SysAdminUserModel;
use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;

class SysLogService extends CommonBaseService
{
    protected $cache = true;

    protected $cacheBucket = 'SysLog:';

    protected $tokenBucket = 'Token:';

    protected $activeBucket = "Active:";

    const LOG_TYPE_LOGIN=0; //系统登录日志

    public function saveSysLog($params=[]){
        $data=[];
        $data['operation_id']=empty($params['operation_id'])?0:$params['operation_id'];
        $data['different_content']=empty($params['different_content'])?'':$params['different_content'];
        $data['teble_name']=empty($params['teble_name'])?'':$params['teble_name'];
        $data['log_type']=empty($params['log_type'])?0:$params['log_type'];
        $data['create_time']=nowTime();
        $id= $this->model->insertGetId($data);
        return $id;
    }

    public function saveSysLoginLog($userId){
        $data=[];
        $ip=getClientIp();
        $data['operation_id']=$userId;
        $data['different_content']='用户ID：'.$userId.';ip地址：'.$ip.';';
        $data['teble_name']='sys_admin_user';
        $this->saveSysLog($data);

    }
}
