1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace common\models;
- use Yii;
- /**
- * This is the model class for table "{{%article}}".
- **/
- class AdminLog extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%admin_log}}';
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id'=>'操作记录ID',
- 'title'=>'操作记录描述',
- 'addtime'=>'记录时间',
- 'admin_name'=>'操作人姓名',
- 'admin_ip'=>'操作人IP地址',
- 'admin_agent'=>'操作人浏览器代理商',
- 'handle_id'=>'操作控制器名称',
- 'type'=>'操作类型',
- 'model'=>'操作数据编号',
- 'result'=>'操作结果',
- ];
- }
- public static function saveLog($controller ,$action,$result,$objId){
- $model = new self;
- $model->admin_ip = Yii::$app->request->userIP;
- $headers = Yii::$app->request->headers;
- $model->addtime = time();
- if ($headers->has('User-Agent')) {
- $model->admin_agent = $headers->get('User-Agent');
- }
- $model->admin_id = Yii::$app->user->identity->id;
- $model->admin_name = Yii::$app->user->identity->email;
- $controllers = ['article','video','collection','collection-album','category','banner','exchange','user','admin'];
- if(!in_array(strtolower($controller),$controllers)) $controller = '';
- $actions = ['create','update','delete','login','logout'];
- if(!in_array(strtolower($action),$actions))$action = '';
- $model->handle_id = $controller;
- $model->type = $action;
- $model->result = $result;
- $model->model = $objId;
- $model->title = $model->admin_name.' '.$model->type.' '.$model->handle_id;
- $model->save(false);
- }
- }
|