| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\ActionLogModel;
- use App\Services\Api\MemberService;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 行为日志-服务类
- * @author laravel开发员
- * @since 2020/11/12
- * Class ActionLogService
- * @package App\Services\Common
- */
- class ActionLogService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/12
- * ActionLogService constructor.
- */
- public function __construct()
- {
- $this->model = new ActionLogModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 常用设备
- * @param $username
- * @return array|false|mixed
- */
- public function getDevices($username)
- {
- $cacheKey = "caches:devices:".md5($username);
- if($datas = RedisService::get($cacheKey)){
- return $datas;
- }
- $datas = $this->model->where(['username'=> $username,'mark'=>1])
- ->distinct()
- ->select(['user_agent','ip','username','create_time'])
- ->orderBy('create_time','desc')
- ->take(3)
- ->get();
- $datas = $datas? $datas->toArray() : [];
- if($datas){
- foreach ($datas as &$item){
- $br = $item['user_agent'];
- if($br){
- if (preg_match('/MSIE\/[0-9\.]+/i', $br, $result)) {
- $br = isset($result[0])? trim($result[0]) : '';
- } elseif (preg_match('/Firefox\/[0-9\.]+/i', $br, $result)) {
- $br = isset($result[0])? trim($result[0]) : '';
- } elseif (preg_match('/Chrome\/[0-9\.]+/i', $br, $result)) {
- $br = isset($result[0])? trim($result[0]) : '';
- } elseif (preg_match('/Safari\/[0-9\.]+/i', $br, $result)) {
- $br = isset($result[0])? trim($result[0]) : '';
- } elseif (preg_match('/Opera\/[0-9\.]+/i', $br, $result)) {
- $br = isset($result[0])? trim($result[0]) : '';
- } else {
- $br = 'Other';
- }
- }
- $item['device'] = $br;
- $item['time_text'] = $item['create_time']? datetime($item['create_time'], 'm-d H:i'):'';
- }
- RedisService::set($cacheKey, $datas, rand(10, 30));
- }
- return $datas;
- }
- }
|