AdminLoginList.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace backendApi\modules\v1\models\lists\log;
  3. use common\helpers\MongodbSearchFilter;
  4. use common\libs\dataList\DataListInterface;
  5. use common\models\LogAdminLogin;
  6. use common\libs\dataList\column\DateTime;
  7. use yii\helpers\ArrayHelper;
  8. class AdminLoginList extends \common\libs\dataList\DataList implements DataListInterface
  9. {
  10. /**
  11. * 列表名称
  12. * @return string
  13. */
  14. public function getListName(){
  15. return '管理员登录日志';
  16. }
  17. /**
  18. * 列表筛选到的数据
  19. * @throws \yii\base\Exception
  20. */
  21. public function dataHandle()
  22. {
  23. $filter = MongodbSearchFilter::filterCondition([
  24. 'opt_type' => 'opt_type',
  25. 'adm_name' => 'adm_name',
  26. 'success_times' => 'success_times',
  27. 'created_at' => 'created_at',
  28. 'period_num' => 'period_num',
  29. 'ip' => 'ip',
  30. 'device' => 'device',
  31. 'user_agent' => 'user_agent',
  32. 'request_route' => 'request_route',
  33. ]);
  34. $this->listData = LogAdminLogin::lists($filter['condition'], []);
  35. }
  36. /**
  37. * 要展示和导出的所有字段
  38. * @return array
  39. */
  40. public function getColumn(){
  41. if(!$this->columns){
  42. $this->columns = [
  43. 'opt_type' => [
  44. 'header' => '操作类型',
  45. 'headerOther' => [
  46. 'width' => '120',
  47. ],
  48. 'value' => function($row) {
  49. return (isset($row['opt_type']) && $row['opt_type'] == 1 )? '登录成功' : '登录失败';
  50. },
  51. 'valueOther' => function($row) {
  52. return [
  53. 'tag'=>['type'=>(isset($row['opt_type']) && $row['opt_type'] == 1 )? 'success' : 'danger', 'size' => 'small']
  54. ];
  55. },
  56. ],
  57. 'opt_obj' => [
  58. 'header' => '操作对象',
  59. 'headerOther' => [
  60. 'width' => '120',
  61. ],
  62. 'value' => function($row) {
  63. return '管理员';
  64. },
  65. ],
  66. 'adm_name' => [
  67. 'header' => '对象编号',
  68. 'headerOther' => [
  69. 'width' => '110',
  70. ],
  71. ],
  72. 'return_result' => [
  73. 'header' => '返回内容',
  74. 'headerOther' => [
  75. 'width' => '250',
  76. ],
  77. ],
  78. 'success_times' => [
  79. 'header' => '登录成功次数',
  80. 'headerOther' => [
  81. 'width' => '110',
  82. ],
  83. ],
  84. 'fail_times' => [
  85. 'header' => '登录失败次数',
  86. 'headerOther' => [
  87. 'width' => '110',
  88. ],
  89. ],
  90. 'created_at' => [
  91. 'header' => '操作时间',
  92. 'value' => function($row) {
  93. return (new DateTime([
  94. 'value' => $row['created_at'],
  95. ]))->result();
  96. },
  97. 'headerOther' => ['width' => '180'],
  98. ],
  99. 'period_num' => '期数',
  100. 'ip' => [
  101. 'header' => 'IP地址',
  102. 'headerOther' => [
  103. 'width' => '150',
  104. ],
  105. ],
  106. 'device' => [
  107. 'header' => '客户端',
  108. 'headerOther' => [
  109. 'width' => '150',
  110. ],
  111. ],
  112. 'user_agent' => [
  113. 'header' => '操作系统',
  114. 'headerOther' => [
  115. 'width' => '950',
  116. ],
  117. ],
  118. 'request_route' => [
  119. 'header' => '请求路径',
  120. 'headerOther' => [
  121. 'width' => '250',
  122. ],
  123. ],
  124. ];
  125. }
  126. return $this->columns;
  127. }
  128. /**
  129. * 前台用于筛选的类型集合
  130. * @return mixed
  131. */
  132. public function getFilterTypes()
  133. {
  134. if(!$this->filterTypes){
  135. $this->filterTypes = [
  136. 'opt_type' => ['isUserTable'=>false, 'name'=>'操作类型', 'other'=> 'select', 'selectData'=> [['id'=> 1, 'name'=> '登录成功'], ['id'=> 0, 'name'=> '登录失败']]],
  137. 'adm_name' => ['isUserTable'=>false, 'name'=>'对象编号'],
  138. 'success_times' => ['isUserTable'=>false, 'name'=>'登录成功次数'],
  139. 'fail_times' => ['isUserTable'=>false, 'name'=>'登录失败次数'],
  140. 'created_at' => ['isUserTable'=>false, 'name'=>'操作时间', 'other'=> 'date'],
  141. 'period_num' => ['isUserTable'=>false, 'name'=>'期数'],
  142. 'ip' => ['isUserTable'=>false, 'name'=>'IP地址'],
  143. 'device' => ['isUserTable'=>false, 'name'=>'客户端'],
  144. 'user_agent' => ['isUserTable'=>false, 'name'=>'操作系统'],
  145. 'request_route' => ['isUserTable'=>false, 'name'=>'请求路径'],
  146. ];
  147. }
  148. return $this->filterTypes;
  149. }
  150. }