changedAttributes)) { // 内容 $arr['changedAttributes'] = $event->changedAttributes; $arr['oldAttributes'] = []; foreach($event->sender as $key => $value) { $arr['oldAttributes'][$key] = $value; } $description = json_encode($arr); $log = new \common\models\AdminLog(); $log->admin_id = Yii::$app->session['user_info']['uid']; $log->create_at =$_SERVER['REQUEST_TIME']; $log->admin_ip = Yii::$app->request->userIP; $log->controller =strtolower(Yii::$app->controller->id); $log->action =strtolower(Yii::$app->controller->action->id); $log->table =$event->sender->tableName(); $log->class =$event->sender->className(); $log->description = $description; $log->type = 2; if(isset($event->sender->primaryKey) && !empty($event->sender->primaryKey)) { $log->primary_keys = $event->sender->primaryKey; } //特殊操作 if($event->sender->className() == 'common\models\CategoryTelCity' || $event->sender->className() == 'common\models\CategoryTel') { Yii::$app->redis->del('params:citytel'); } if($event->sender->className() == 'common\models\Characteristic') { Yii::$app->redis->del('params:characteristic'); } $log->save(false); } } /** * 添加操作. * @param obj $event * @return mixed */ public static function afterInsert($event) { if($event->sender->className() != 'common\models\UserOperationrecord' && $event->sender->tableName() != self::tableName() ){ $arr = []; foreach($event->sender as $key => $value) { $arr[$key] = $value; } $description = json_encode($arr); $log = new \common\models\AdminLog(); $log->admin_id = Yii::$app->session['user_info']['uid']; $log->create_at =$_SERVER['REQUEST_TIME']; $log->admin_ip = Yii::$app->request->userIP; $log->controller =strtolower(Yii::$app->controller->id); $log->action =strtolower(Yii::$app->controller->action->id); $log->table =$event->sender->tableName(); $log->class =$event->sender->className(); $log->description = $description; $log->type = 1; if(isset($event->sender->primaryKey) && !empty($event->sender->primaryKey)) { $log->primary_keys = $event->sender->primaryKey; } //特殊操作 if($event->sender->className() == 'common\models\CategoryTelCity' || $event->sender->className() == 'common\models\CategoryTel') { Yii::$app->redis->del('params:citytel'); } if($event->sender->className() == 'common\models\Characteristic') { Yii::$app->redis->del('params:characteristic'); } $log->save(false); } } public static function afterDels($event) { // 内容 $arr = []; foreach($event->sender as $key => $value) { $arr[$key] = $value; } $description = json_encode($arr); $log = new \common\models\AdminLog(); $log->admin_id = Yii::$app->session['user_info']['uid']; $log->create_at =$_SERVER['REQUEST_TIME']; $log->admin_ip = Yii::$app->request->userIP; $log->controller =strtolower(Yii::$app->controller->id); $log->action =strtolower(Yii::$app->controller->action->id); $log->table =$event->sender->tableName(); $log->class =$event->sender->className(); $log->description = $description; $log->type = 3; if(isset($event->sender->primaryKey) && !empty($event->sender->primaryKey)) { $log->primary_keys = $event->sender->primaryKey; } //特殊操作 if($event->sender->className() == 'common\models\CategoryTelCity' || $event->sender->className() == 'common\models\CategoryTel') { Yii::$app->redis->del('params:citytel'); } if($event->sender->className() == 'common\models\Characteristic') { Yii::$app->redis->del('params:characteristic'); } $log->save(false); } }