UserLog.php 718 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\weixin\model;
  3. use think\Model;
  4. class UserLog extends Model
  5. {
  6. protected $table = 'sg_user_logs';
  7. /**
  8. * 保存日志
  9. * @param $data
  10. * @return int|string
  11. */
  12. public static function saveLog($data)
  13. {
  14. $data['ip'] = get_client_ip();
  15. $data['created_at'] = date('Y-m-d H:i:s');
  16. $data['status'] = 1;
  17. $userLogDel = config('weixin.userLogDel');
  18. if($userLogDel){
  19. $userLogDay = config('weixin.userLogDay');
  20. $day = $userLogDay? $userLogDay : 7;
  21. UserLog::where('created_at','<', date('Y-m-d H:i:s', strtotime("-{$day} days")))->delete();
  22. }
  23. return UserLog::insertGetId($data);
  24. }
  25. }