Logfile.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. class Logfile extends BaseModel {
  5. protected $table = "logfile";
  6. public $timestamps = false;
  7. function log($list,$page,$where='') {
  8. $data = $this->join('account_detailed', 'logfile.account_identity', '=', 'account_detailed.account_identity')
  9. ->select('account', 'add_time', 'type', 'ip', 'url', 'register_ip')
  10. ->orderBy('add_time', 'desc')
  11. ->paginate($list);
  12. if(!empty($where)&&is_array($where)){
  13. $data = $this->join('account_detailed', 'logfile.account_identity', '=', 'account_detailed.account_identity')
  14. ->select('account', 'add_time', 'type', 'ip', 'url', 'register_ip')
  15. ->where($where)
  16. ->orderBy('add_time', 'desc')
  17. ->paginate($list);
  18. }
  19. if (!$data) {
  20. return -2020032003; //没有用户登录日志
  21. }
  22. return $data->toArray();
  23. }
  24. //获取用户登录网址和注册网址
  25. function getUrl($account_identity){
  26. //DB::connection()->enableQueryLog();
  27. $sql = 'SELECT b.account,b.account_identity,a.maxtime,a.mintime,b.type,b.ip,b.url as last_url,c.url as register_url FROM (SELECT max(add_time) as maxtime,min(add_time) as mintime,account_identity from logfile group by account_identity) as a LEFT JOIN logfile as b ON b.add_time=a.maxtime and a.account_identity=b.account_identity LEFT JOIN logfile as c ON c.add_time=a.mintime and a.account_identity=c.account_identity WHERE b.account_identity IN '.$account_identity;
  28. $data = DB::select($sql);
  29. //$queries = DB::getQueryLog();
  30. //print_r($queries);
  31. if (!$data < 0) {
  32. return -2020000102; //没有相关信息
  33. }
  34. $data = json_encode($data);
  35. $data = json_decode($data,1);
  36. return $data;
  37. }
  38. //统计当前用户在线数目
  39. function getUser(){
  40. $time=date('Y-m-d H:i:s',time()-30*60);
  41. // $time=1512357978;
  42. $data=$this->select(DB::raw('url as name,count(account) as value'))
  43. ->where('add_time','>',$time)
  44. // ->join('account_token as b','b.account_identity',$this->table.'.account_identity')
  45. ->groupBy('url')
  46. ->get();
  47. if(!$data){
  48. return -2020032103; //没有用户登录日志
  49. }
  50. // echo '<pre>';
  51. // print_r($data->toArray());
  52. return $data->toArray();
  53. }
  54. //在线人数
  55. function onlineUser($where){
  56. $data=$this->select((DB::raw('max("id"),url as name')))
  57. ->whereIn('account_identity',$where)
  58. ->groupBy('url')
  59. ->get();
  60. // echo '<pre>';
  61. // print_r($data->toArray());
  62. return $data->toArray();
  63. }
  64. }
  65. ?>