Преглед изворни кода

会员登录记录版本号,统计新旧会员端使用情况

kevin_zhangl пре 2 година
родитељ
комит
ef7318aaf7

+ 16 - 5
backendApi/modules/v1/models/lists/log/UserLoginList.php

@@ -37,6 +37,7 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                 'device' => 'device',
                 'user_agent' => 'user_agent',
                 'request_route' => 'request_route',
+                'version' => 'version',
             ]);
             $condition = $filter['condition'];
         }
@@ -72,7 +73,7 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                 'opt_obj' => [
                     'header' => 'Operation Object', // 操作对象
                     'headerOther' => [
-                        'width' => '120',
+                        'width' => '130',
                     ],
                     'value' => function($row) {
                         return 'member'; // 会员
@@ -81,7 +82,7 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                 'user_name' => [
                     'header' => 'Object Number', // 对象编号
                     'headerOther' => [
-                        'width' => '110',
+                        'width' => '120',
                     ],
                 ],
                 'return_result' => [
@@ -93,13 +94,13 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                 'success_times' => [
                     'header' => 'Login Success Times', // 登录成功次数
                     'headerOther' => [
-                        'width' => '110',
+                        'width' => '160',
                     ],
                 ],
                 'fail_times' => [
                     'header' => 'Number Of Login Failures', // 登录失败次数
                     'headerOther' => [
-                        'width' => '110',
+                        'width' => '190',
                     ],
                 ],
                 'created_at' => [
@@ -111,7 +112,10 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                     },
                     'headerOther' => ['width' => '180'],
                 ],
-                'period_num' => 'Number Of Periods', // 期数
+                'period_num' => [
+                    'header' => 'Number Of Periods', // 期数
+                    'headerOther' => ['width' => '180'],
+                    ],
                 'ip' => [
                     'header' => 'IP Address', // IP地址
                     'headerOther' => [
@@ -136,6 +140,12 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                         'width' => '250',
                     ],
                 ],
+                'version' => [
+                    'header' => 'Version', // 版本
+                    'headerOther' => [
+                        'width' => '100',
+                    ],
+                ],
             ];
         }
         return $this->columns;
@@ -160,6 +170,7 @@ class UserLoginList extends \common\libs\dataList\DataList implements DataListIn
                 'device' => ['isUserTable'=>false, 'name'=>'Client'],//客户端
                 'user_agent' => ['isUserTable'=>false, 'name'=>'Operating System'],//操作系统
                 'request_route' => ['isUserTable'=>false, 'name'=>'Request Path'],//请求路径
+                'version' => ['isUserTable'=>false, 'name'=>'Version'],//版本
             ];
         }
         return $this->filterTypes;

+ 4 - 3
common/libs/logging/login/UserLogin.php

@@ -22,10 +22,10 @@ class UserLogin {
      * @return LogUserLoginForm
      * @throws \Exception
      */
-    public static function success($userInfo){
+    public static function success($userInfo, $version){
         $returnResult = '';
         $successTimes = intval($userInfo['LOGIN_NUMS']) + 1;
-        $result = self::recorder($userInfo['USER_NAME'], '1', $returnResult, $userInfo['FAIL_NUMS'], $successTimes);
+        $result = self::recorder($userInfo['USER_NAME'], '1', $returnResult, $userInfo['FAIL_NUMS'], $successTimes, $version);
         return $result;
     }
 
@@ -52,7 +52,7 @@ class UserLogin {
      * @return LogUserLoginForm
      * @throws \Exception
      */
-    public static function recorder($account, $optType, $returnResult, $failTimes, $successTimes){
+    public static function recorder($account, $optType, $returnResult, $failTimes, $successTimes, $version = ''){
         $period = Period::instance();
         $periodNum = $period->getNowPeriodNum();
         $form = new LogUserLoginForm([
@@ -67,6 +67,7 @@ class UserLogin {
             'device' => Yii::$app->request->getDevice(),
             'request_route' => Yii::$app->requestedRoute,
             'return_result' => $returnResult,
+            'version' => $version,
         ]);
         if(!$form->add()){
             throw new \Exception(Form::formatErrorsForApi($form->getErrors()));

+ 3 - 0
common/models/LogUserLogin.php

@@ -20,6 +20,7 @@ use Yii;
  * @property mixed $created_at
  * @property mixed $user_agent
  * @property mixed $period_num
+ * @property mixed $version
  */
 class LogUserLogin extends MongoActiveRecord
 {
@@ -64,6 +65,7 @@ class LogUserLogin extends MongoActiveRecord
             'device',
             'request_route',
             'return_result',
+            'version'
         ];
     }
 
@@ -99,6 +101,7 @@ class LogUserLogin extends MongoActiveRecord
             'device' => '客户端',
             'request_route' => '请求路径',
             'return_result' => '返回内容',
+            'version' => '版本',
         ];
     }
 

+ 3 - 0
common/models/forms/LogUserLoginForm.php

@@ -21,6 +21,7 @@ class LogUserLoginForm extends \yii\base\Model
     public $device;
     public $request_route;
     public $return_result;
+    public $version;
     /**
      * DB
      * @return \yii\db\Connection the database connection used by this AR class.
@@ -74,6 +75,7 @@ class LogUserLoginForm extends \yii\base\Model
             'device' => '客户端',
             'request_route' => '请求路径',
             'return_result' => '返回内容',
+            'version' => '版本',
         ];
     }
 
@@ -97,6 +99,7 @@ class LogUserLoginForm extends \yii\base\Model
         $model->device = $this->device;
         $model->request_route = $this->request_route;
         $model->return_result = $this->return_result;
+        $model->version = $this->version;
 
         if(!$model->save()){
             return false;

+ 3 - 1
frontendApi/modules/v1/controllers/OauthController.php

@@ -106,9 +106,11 @@ class OauthController extends BaseController
      */
     public function actionLogin() {
         $userName = Yii::$app->request->post('userName');
+        $version = Yii::$app->request->post('version', '');
         $model = new LoginForm(
             [
-                'userName' =>$userName
+                'userName' => $userName,
+                'version'  => $version,
             ]
         );
         if ( $model->isLoginVerify() ) {

+ 2 - 1
frontendApi/modules/v1/models/LoginForm.php

@@ -23,6 +23,7 @@ class LoginForm extends Model
     public $password;
     public $verifyCode;
     public $rememberMe = true;
+    public $version;
 
     private $_user;
     private $_userInfo;
@@ -194,7 +195,7 @@ class LoginForm extends Model
             $this->_updateSuccessTimes();
             $transaction->commit();
 
-            UserLoginLogger::success($this->_userInfo);
+            UserLoginLogger::success($this->_userInfo, $this->version);
 
             // 把用户的登录时间存在操作时间里
             Yii::$app->tokenRedis->hset('user:timeOut', $this->_userInfo['USER_ID'], time());