LogSystemForm.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace common\models\forms;
  3. use common\models\LogAdminHandle;
  4. use common\models\LogSystem;
  5. use Yii;
  6. class LogSystemForm extends \yii\base\Model
  7. {
  8. public $_id;
  9. public $ip;
  10. public $created_at;
  11. public $request_route;
  12. public $opt_type;
  13. public $request_content;
  14. public $response_content;
  15. public $opt_obj_id;
  16. public $opt_obj_name;
  17. public $opt_target_name;
  18. public $opt_user;
  19. public $user_agent;
  20. public $period_num;
  21. public $is_batch;
  22. public $device;
  23. /**
  24. * @inheritdoc
  25. */
  26. public function rules(){
  27. return [
  28. [['ip', 'created_at', 'request_route', 'opt_type', 'request_content', 'response_content', 'opt_obj_id', 'opt_obj_name', 'opt_target_name', 'opt_user', 'user_agent', 'period_num', 'is_batch', 'device'], 'trim'],
  29. [[ 'request_route', 'opt_type'], 'required'],
  30. [['created_at', 'is_batch', 'period_num'], 'filter', 'filter' => function($value){
  31. return ($value) ? $value : 0;
  32. }],
  33. [['opt_obj_id'], 'string', 'max' => 32],
  34. [['ip', 'opt_obj_name'], 'string', 'max' => 16],
  35. [['_id', 'opt_type', 'request_content', 'response_content', 'device'], 'safe'],
  36. [['user_agent', 'request_route'], 'string', 'max' => 1000],
  37. ];
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function attributeLabels(){
  43. return [
  44. '_id' => 'ID',
  45. 'ip'=>'操作ip',
  46. 'created_at'=>'创建时间',
  47. 'request_route'=>'请求路由',
  48. 'opt_type'=>'操作类型',
  49. 'request_content'=>'请求内容',
  50. 'response_content'=>'响应内容',
  51. 'opt_obj_id'=>'操作对象id',
  52. 'opt_obj_name'=>'操作对象名称',
  53. 'opt_target_name'=>'操作对象',
  54. 'opt_user'=>'操作人',
  55. 'user_agent'=>'浏览器特征',
  56. 'period_num'=>'期数',
  57. 'is_batch'=>'批量保存',
  58. 'device'=>'客户端',
  59. ];
  60. }
  61. /**
  62. * 添加
  63. * @return LogAdminHandle|bool
  64. */
  65. public function add(){
  66. if(!$this->validate()){
  67. return false;
  68. }
  69. $model = new LogSystem();
  70. $model->ip = $this->ip;
  71. $model->created_at = intval($this->created_at);
  72. $model->request_route = $this->request_route;
  73. $model->opt_type = $this->opt_type;
  74. $model->request_content = $this->request_content;
  75. $model->response_content = $this->response_content;
  76. $model->opt_obj_id = $this->opt_obj_id;
  77. $model->opt_obj_name = $this->opt_obj_name;
  78. $model->opt_target_name = $this->opt_target_name;
  79. $model->opt_user = $this->opt_user;
  80. $model->user_agent = $this->user_agent;
  81. $model->period_num = intval($this->period_num);
  82. $model->is_batch = intval($this->is_batch);
  83. $model->device = $this->device;
  84. if(!$model->save()){
  85. $this->addErrors($model->getErrors());
  86. return false;
  87. }
  88. return $model;
  89. }
  90. }