LogAdminHandleForm.php 3.3 KB

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