Esempio n. 1
0
 public function getRedis($data, $visitRate)
 {
     $suffix = $this->getUrl($data['visit_url'], $data['cid']);
     $key = 'visit_' . $suffix;
     $time = time();
     //1>假如同一天同一ip同一页面,先是游客,再是会员访问,则认为是同一人访问
     $visitOneDay = VisitlogModel::where('ip', Tools::getIp())->where('visit_id', 0)->where('loginTime', '>', strtotime(date('Ymd', time()) . '000000'))->where('action', $data['visit_url'])->orderBy('id', 'desc')->first();
     if ($visitOneDay && $data['uid']) {
         VisitlogModel::where('ip', Tools::getIp())->where('visit_id', 0)->where('loginTime', '>', strtotime(date('Ymd', time()) . '000000'))->where('action', $data['visit_url'])->update(array('uid' => $data['uid'], 'logoutTime' => time()));
     }
     //2>假如同一天同一ip同一页面,先是会员,再是游客访问,则认为是同一人访问
     $visitOneDay = VisitlogModel::where('ip', Tools::getIp())->where('visit_id', '>', 0)->where('loginTime', '>', strtotime(date('Ymd', time()) . '000000'))->where('action', $data['visit_url'])->orderBy('id', 'desc')->first();
     if ($visitOneDay && !$data['uid']) {
         VisitlogModel::where('ip', Tools::getIp())->where('visit_id', '>', 0)->where('loginTime', '>', strtotime(date('Ymd', time()) . '000000'))->where('action', $data['visit_url'])->update(array('uid' => 0, 'logoutTime' => time()));
     }
     //3>以下是更新访问日志的几种情况
     if (Redis::exists($key)) {
         $visit = unserialize(Redis::get($key));
         if ($visit['logoutTime'] + $visitRate < time()) {
             $visit1 = $visit;
             $visit1['logoutTime'] = $time;
             Redis::setex($key, 3600, serialize($visit1));
             //更新缓存,有效1小时
             //更新数据库
             VisitlogModel::where('serial', $visit['serial'])->update(['logoutTime' => $time]);
             VisitlogModel::where('serial', $visit['serial'])->increment('timeCount', $visitRate);
         }
         dd('更新成功!');
         exit;
     } else {
         $visit = $this->getData($data);
         $visit['logoutTime'] = $time;
         Redis::setex($key, 3600, serialize($visit));
         //添加缓存,有效1小时
         //插入或更新数据库
         $where = ['visit_id' => $data['uid'], 'action' => $data['visit_url'], 'cid' => $data['cid']];
         $visitModel = VisitlogModel::where($where)->where('loginTime', '>', strtotime(date('Ymd', time()) . '000000'))->where('logoutTime', '<', strtotime(date('Ymd', time()) . '235959'))->first();
         $visitModel2 = VisitlogModel::where($where)->where('ip', $visit['ip'])->where('loginTime', '>', strtotime(date('Ymd', time()) . '000000'))->where('logoutTime', '<', strtotime(date('Ymd', time()) . '235959'))->first();
         if ($data['uid'] && $visitModel) {
             //假如是注册会员,并且当天有记录,则更新数据库
             VisitlogModel::where($where)->update(['logoutTime' => $time]);
             VisitlogModel::where($where)->increment('timeCount', $visitRate);
             VisitlogModel::where($where)->increment('dayCount');
             dd('更新成功!');
             exit;
         } elseif (!$data['uid'] && $visitModel2) {
             //假如是非注册会员同地区,并且当天有记录,则更新数据库
             VisitlogModel::where($where)->where('ip', $visit['ip'])->update(['logoutTime' => $time]);
             VisitlogModel::where($where)->increment('timeCount', $visitRate);
             VisitlogModel::where($where)->increment('dayCount');
             dd('更新成功!');
             exit;
         } else {
             //假如非注册会员,不在同一地区
             VisitlogModel::create($visit);
             dd('添加成功!');
             exit;
         }
     }
 }
Esempio n. 2
0
 public function query()
 {
     $datas = VisitlogModel::where('cid', $this->cid)->orderBy('id', 'desc')->paginate($this->limit);
     $datas->limit = $this->limit;
     return $datas;
 }