123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:25
- */
- namespace common\models;
- use Yii;
- //use yii\db\ActiveRecord;
- //use yii\behaviors\TimestampBehavior;
- class AdminLog extends \yii\db\ActiveRecord{
- /**
- * 修改操作.
- * @param obj $event
- * @return mixed
- */
- public static function afterUpdate($event)
- {
- if(!empty($event->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);
- }
- }
|