| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- use yii\db\BaseActiveRecord;
- use yii\helpers\Json;
- /**
- * Class ActionLog
- * @package app\modules\common\models
- *
- * @property integer $id
- * @property string $route
- * @property integer $admin_id
- * @property string $type
- * @property string $data_id
- * @property string $created_at
- * @property string $created_at_micro
- * @property string $get_params
- * @property string $post_params
- * @property string $header_params
- * @property string $response_params
- * @property int $status
- * @property string $addr_ip
- * @property int $spend_time
- * @property string $request_method
- * @property string $name
- * @property string $role
- */
- class ActionLog extends ActiveRecord
- {
- public static function tableName()
- {
- return '{{%action_log}}';
- }
- public function rules()
- {
- return [
- [['route', 'type'], 'required'],
- [['id', 'admin_id','status','spend_time'], 'integer'],
- [['route', 'type', 'data_id'], 'string', 'max' => 100],
- [['get_params', 'post_params', 'header_params', 'response_params', 'create_at','created_at_micro','addr_ip','request_method','name','role'], 'safe']
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'route' => '路由',
- 'admin_id' => '管理员ID',
- 'type' => '类型',
- 'data_id' => '数据ID',
- 'created_at' => '创建时间',
- 'get_params' => 'GET参数',
- 'post_params' => 'POST参数',
- 'header_params' => 'HEADER参数',
- 'response_params' => '响应参数'
- ];
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- if ($this->isNewRecord) {
- $this->created_at = date('Y-m-d H:i:s');
- }
- return true;
- }
- return false;
- }
- public static function addLog($code,$route,$data_string){
- try {
- $log = new self();
- $log->type = 'log';
- $log->route = $route;
- $log->admin_id = 1;
- $log->request_method = 'POST';
- $log->spend_time = rand(1,100);
- $log->addr_ip = '';
- $log->status = $code;
- $response['response'] =['code'=>$code,'data'=>$data_string] ;
- $log->response_params = Json::encode($response);
- $log->role = 'admin';
- $log->name = 'admin';
- $log->created_at_micro = microtime(true)*1000;
- if (!$log->save()){
- //debug_log([__METHOD__, __LINE__, "actionLog:".$log->getErrorSummary(false)[0]], "app_debug.log");
- }
- }catch (\Throwable $e){
- //debug_log([__METHOD__, __LINE__, "actionLog:".$e->getMessage()], "app_debug.log");
- }
- }
- }
|