UserLoginList.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. 'version' => 'version',
  38. ]);
  39. $condition = $filter['condition'];
  40. }
  41. $data = LogUserLogin::lists($condition, [
  42. 'pageSize' => $this->pageSize
  43. ]);
  44. unset($filter);
  45. $this->listData = $data;
  46. }
  47. /**
  48. * 要展示和导出的所有字段
  49. * @return array
  50. */
  51. public function getColumn(){
  52. if(!$this->columns){
  53. $this->columns = [
  54. 'opt_type' => [
  55. 'header' => 'Operation Type',//操作类型
  56. 'headerOther' => [
  57. 'width' => '120',
  58. ],
  59. 'value' => function($row) {
  60. return (isset($row['opt_type']) && $row['opt_type'] == 1 )? 'login succeeded' : 'login failed';//'登录成功' : '登录失败';
  61. },
  62. 'valueOther' => function($row) {
  63. return [
  64. 'tag'=>['type'=>(isset($row['opt_type']) && $row['opt_type'] == 1 )? 'success' : 'danger', 'size' => 'small']
  65. ];
  66. },
  67. ],
  68. 'opt_obj' => [
  69. 'header' => 'Operation Object', // 操作对象
  70. 'headerOther' => [
  71. 'width' => '130',
  72. ],
  73. 'value' => function($row) {
  74. return 'member'; // 会员
  75. },
  76. ],
  77. 'user_name' => [
  78. 'header' => 'Object Number', // 对象编号
  79. 'headerOther' => [
  80. 'width' => '120',
  81. ],
  82. ],
  83. 'return_result' => [
  84. 'header' => 'Return Content', // 返回内容
  85. 'headerOther' => [
  86. 'width' => '250',
  87. ],
  88. ],
  89. 'success_times' => [
  90. 'header' => 'Login Success Times', // 登录成功次数
  91. 'headerOther' => [
  92. 'width' => '160',
  93. ],
  94. ],
  95. 'fail_times' => [
  96. 'header' => 'Number Of Login Failures', // 登录失败次数
  97. 'headerOther' => [
  98. 'width' => '190',
  99. ],
  100. ],
  101. 'created_at' => [
  102. 'header' => 'Operation Time', // 操作时间
  103. 'value' => function($row) {
  104. return (new DateTime([
  105. 'value' => $row['created_at'],
  106. ]))->result();
  107. },
  108. 'headerOther' => ['width' => '180'],
  109. ],
  110. 'period_num' => [
  111. 'header' => 'Number Of Periods', // 期数
  112. 'headerOther' => ['width' => '180'],
  113. ],
  114. 'ip' => [
  115. 'header' => 'IP Address', // IP地址
  116. 'headerOther' => [
  117. 'width' => '150',
  118. ],
  119. ],
  120. 'device' => [
  121. 'header' => 'Client', // 客户端
  122. 'headerOther' => [
  123. 'width' => '150',
  124. ],
  125. ],
  126. 'user_agent' => [
  127. 'header' => 'Operating System', // 操作系统
  128. 'headerOther' => [
  129. 'width' => '950',
  130. ],
  131. ],
  132. 'request_route' => [
  133. 'header' => 'Request Path', // 请求路径
  134. 'headerOther' => [
  135. 'width' => '250',
  136. ],
  137. ],
  138. 'version' => [
  139. 'header' => 'Version', // 版本
  140. 'headerOther' => [
  141. 'width' => '100',
  142. ],
  143. ],
  144. ];
  145. }
  146. return $this->columns;
  147. }
  148. /**
  149. * 前台用于筛选的类型集合
  150. * @return mixed
  151. */
  152. public function getFilterTypes()
  153. {
  154. if(!$this->filterTypes){
  155. $this->filterTypes = [
  156. // 'opt_type' => ['isUserTable'=>false, 'name'=>'操作类型', 'other'=> 'select', 'selectData'=> [['id'=> 1, 'name'=> '登录成功'], ['id'=> 0, 'name'=> '登录失败']]],
  157. 'opt_type' => ['isUserTable'=>false, 'name'=>'Operation Type', 'other'=> 'select', 'selectData'=> [['id'=> 1, 'name'=> 'login succeeded'], ['id'=> 0, 'name'=> 'login failed']]],
  158. 'user_name' => ['isUserTable'=>false, 'name'=>'Object Number'],//对象编号
  159. 'success_times' => ['isUserTable'=>false, 'name'=>'Login Success Times'],//登录成功次数
  160. 'fail_times' => ['isUserTable'=>false, 'name'=>'Number Of Login Failures'],//登录失败次数
  161. 'created_at' => ['isUserTable'=>false, 'name'=>'Operation Time', 'other'=> 'date'],//操作时间
  162. 'period_num' => ['isUserTable'=>false, 'name'=>'Number Of Periods'],//期数
  163. 'ip' => ['isUserTable'=>false, 'name'=>'IP Address'],//IP地址
  164. 'device' => ['isUserTable'=>false, 'name'=>'Client'],//客户端
  165. 'user_agent' => ['isUserTable'=>false, 'name'=>'Operating System'],//操作系统
  166. 'request_route' => ['isUserTable'=>false, 'name'=>'Request Path'],//请求路径
  167. 'version' => ['isUserTable'=>false, 'name'=>'Version'],//版本
  168. ];
  169. }
  170. return $this->filterTypes;
  171. }
  172. }