Browse Source

访问日志

541469799@qq.com 9 months ago
parent
commit
55faf06080

+ 9 - 0
app/index/controller/Captcha.php

@@ -130,6 +130,15 @@ class Captcha extends Controller
             return $this->renderError('Invalid email address.');
         }
 
+        UserAccessLog::doSave([
+            'user_id' => 0,
+            'path' => $this->request->action(),
+            'remark' => $email,
+            'ip' => $this->request->ip(),
+            'store_id' => $this->getStoreId(),
+            'create_time' => time()
+        ]);
+
         $smtp = new MailCaptchaService();
         $flag = $smtp->sendCaptcha($email);
         if ($flag) {

+ 38 - 7
app/index/controller/User.php

@@ -5,6 +5,7 @@ namespace app\index\controller;
 use app\common\enum\order\PayStatus;
 use app\index\model\Goods;
 use app\index\model\ShareKey;
+use app\index\model\user\UserAccessLog;
 use app\index\service\passport\MailCaptcha as MailCaptchaService;
 use app\index\model\OrderAddress;
 use app\index\model\user\PointsLog as PointsLogModel;
@@ -197,19 +198,19 @@ class User extends Controller
         $smtp = new UMailer(config('smtp.host'), config('smtp.port'), true,
             config('smtp.username'), config('smtp.password'));
         $smtp->debug = true;                     //是否显示发送的调试信息
-        $flag = $smtp->sendShareText($mailbox, config('smtp.username'),'Code','HTML','','','', $url);
+        $flag = $smtp->sendShareText($mailbox, config('smtp.username'), 'Code', 'HTML', '', '', '', $url);
         if ($flag) {
             $shareKeyModel = new ShareKey();
             $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
             return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
         }
 
-/*        $MailCaptchaService = new MailCaptchaService;
-        if ($MailCaptchaService->sendText($mailbox, 'From Your Friend', $url)) {
-            $shareKeyModel = new ShareKey();
-            $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
-            return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
-        }*/
+        /*        $MailCaptchaService = new MailCaptchaService;
+                if ($MailCaptchaService->sendText($mailbox, 'From Your Friend', $url)) {
+                    $shareKeyModel = new ShareKey();
+                    $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
+                    return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
+                }*/
 
         if (is_debug()) {
             $shareKeyModel = new ShareKey();
@@ -898,4 +899,34 @@ class User extends Controller
         dd($f);
     }
 
+    public function pullAccessLogs()
+    {
+        $path = $this->request->param('path','');
+
+        $from = $this->request->param('from');
+        $to = $this->request->param('to');
+
+        $page = $this->request->param('page', 1);
+        $size = $this->request->param('size', 50);
+
+        $fromInt = strtotime($from);
+        if (!$fromInt) {
+            return $this->renderError('input valid from time');
+        }
+
+        if (!empty($to) && !strtotime($to)) {
+            return $this->renderError('input valid to time');
+        }
+
+        if (!empty($to)) {
+            $toInt = strtotime($to);
+        } else {
+            $toInt = time();
+        }
+
+         $data = UserAccessLog::getAccessLog($path, $fromInt, $toInt, $page, $size);
+
+        return $this->renderSuccess($data);
+    }
+
 }

+ 20 - 2
app/index/model/user/UserAccessLog.php

@@ -8,11 +8,12 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\index\model\user;
 
 use app\common\model\user\UserAccessLog as UserAccessLogModel;
+use think\db\Where;
 
 /**
  * 系统设置模型
@@ -22,13 +23,30 @@ use app\common\model\user\UserAccessLog as UserAccessLogModel;
 class UserAccessLog extends UserAccessLogModel
 {
     /**
+     * 页面:vapePoints,index
+     * 接口:register,sendEmailCaptcha,login
+     **/
+
+    /**
      * 获取积分名称
      * @return bool
      */
     public static function doSave($data)
     {
-        if (empty($data))return false;
+        if (empty($data)) return false;
         return static::insert($data);
     }
 
+    public static function getAccessLog($path, $from, $to, $page = 1, $size = 50)
+    {
+        $m = self::where('create_time', '>=', $from)->where('create_time', '<=', $to);
+        if (!empty($path)) {
+            $m = $m->where('path', $path);
+        }
+        $count = $m->count();
+        $items = $m->page($page, $size)->select();
+
+        return ['count' => $count, 'item' => $items];
+    }
+
 }