UserLoginList.php 6.3 KB

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