User_logs.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-10-30 13:48:09------
  7. */
  8. namespace App\Commons\Model;
  9. use \System\Model;
  10. class User_logs extends Model
  11. {
  12. public $timestamps = false;
  13. protected $table = 'user_logs';
  14. /**
  15. *初始化
  16. *
  17. * @return void
  18. */
  19. function initVisitor(){
  20. $mob=C()->get('header');
  21. $ip=$mob->getIP();
  22. $time=time()-180;
  23. $had=$this->where('ip',$ip)->where("create_time",'>',date('Y-m-d H:i:s',$time))->orderBy('create_time','desc')->first();
  24. // toLog($had);
  25. if($had){
  26. return;
  27. }
  28. $data=array(
  29. 'ip'=>$ip,
  30. 'header'=>$mob->getHttpHeader(),
  31. 'create_time'=>date('Y-m-d H:i:s'),
  32. );
  33. $this->insert($data);
  34. }
  35. //
  36. function updateUid($uid,$uname){
  37. // $uid=isset($_GET['uid'])?trim($_GET['uid']):null;
  38. // $uname=isset($_GET['uname'])?trim($_GET['uname']):null;
  39. if(empty($uid))
  40. {
  41. return -1;
  42. }
  43. $mob=C()->get('header');
  44. $ip=$mob->getIP();
  45. $this->where('ip',$ip)->orderBy('create_time','desc')->update(['user_id'=>$uid,'user_name'=>$uname]);
  46. }
  47. }