AdminLogController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\components\AjaxException;
  4. use common\components\Routes;
  5. use common\models\AccidentCasesUpdateHistory;
  6. use common\models\AdminLog;
  7. use common\services\AdminLogService;
  8. use frontend\modules\api\components\BaseAdminController;
  9. use yii\web\Response;
  10. class AdminLogController extends BaseAdminController
  11. {
  12. /**
  13. * 日志列表
  14. * @param int $current
  15. * @param int $page
  16. * @return Response
  17. */
  18. public function actionList(int $current = 1, int $page = 10)
  19. {
  20. $query = AdminLog::find()
  21. ->limit($page)
  22. ->offset(($current - 1) * $page);
  23. //排序
  24. $this->initSequence($query);
  25. //主要筛选条件
  26. $query = $this->addConditionToQuery("username", $query, true);
  27. $query = $this->addConditionToQuery("role", $query, true);
  28. $query = $this->addConditionToQuery("title", $query, true);
  29. $query = $this->addConditionToQuery("name", $query, true);
  30. $query = $this->addConditionToQuery("url", $query, true);
  31. $query = $this->addConditionToQuery("ip", $query, true);
  32. $query = $this->addConditionToQuery("content", $query, true);
  33. $query = $this->addStartEndConditionToQuery("create_time", $query);
  34. //组合数据
  35. $list = $query->select("id,role_name,uid,name,username,url,title,ip,create_time,content")->all();
  36. $data['data'] = $list;
  37. $data['total'] = $query->count();
  38. return $this->asJson($data);
  39. }
  40. /**
  41. * 用户操作日志列表
  42. * @param int $current
  43. * @param int $page
  44. * @return Response
  45. */
  46. public function actionStaffList(int $current = 1, int $page = 10)
  47. {
  48. $query = AccidentCasesUpdateHistory::find()
  49. ->limit($page)
  50. ->offset(($current - 1) * $page);
  51. //排序
  52. $this->initSequence($query);
  53. //主要筛选条件
  54. $query = $query->andWhere(["url" => AdminLogService::$staffTitle]);
  55. //
  56. $query = $this->addConditionToQuery("username", $query, true);
  57. $query = $this->addConditionToQuery("role", $query, true);
  58. $query = $this->addConditionToQuery("title", $query, true);
  59. $query = $this->addConditionToQuery("name", $query, true);
  60. $query = $this->addConditionToQuery("url", $query);
  61. $query = $this->addConditionToQuery("ip", $query, true);
  62. $query = $this->addConditionToQuery("content", $query, true);
  63. $query = $this->addStartEndConditionToQuery("create_time", $query);
  64. //组合数据
  65. $list = $query->select("id,role_name,uid,name,username,url,title,ip,create_time,content,origin,current,case_id,case_title")->all();
  66. $data['data'] = $list;
  67. $data['total'] = $query->count();
  68. return $this->asJson($data);
  69. }
  70. /**
  71. * 日志详情
  72. * @param $id
  73. * @return Response
  74. * @throws AjaxException
  75. */
  76. public function actionDetail($id)
  77. {
  78. $AdminLogInfo = AdminLog::findOne($id);
  79. if (!$AdminLogInfo) {
  80. throw new AjaxException("日志不存在!");
  81. }
  82. if ($AdminLogInfo->history_id != 0) {
  83. $history = AccidentCasesUpdateHistory::findOne($AdminLogInfo->history_id);
  84. if ($history) {
  85. $AdminLogInfo->origin = $history->origin;
  86. $AdminLogInfo->current = $history->current;
  87. }
  88. }
  89. $newInfo = $AdminLogInfo->getAttributes();
  90. $newInfo["origin"] = $AdminLogInfo->origin;
  91. $newInfo["current"] = $AdminLogInfo->current;
  92. $data['data'] = $newInfo;
  93. //组合数据
  94. return $this->asJson($data);
  95. }
  96. /**
  97. * 服务端urlTitle生成
  98. */
  99. public function actionUrlTitle()
  100. {
  101. $myfile = fopen("testfile.txt", "w");
  102. //获取服务端权限
  103. $array = [];
  104. $array2 = [];
  105. $routes = Routes::getAppRoutes('api');
  106. foreach ($routes as $key => $value) {
  107. // $name = substr(substr($key, 4), 0, strlen(substr($key, 4)) - 1);
  108. // $array[$name] = $name;
  109. if (isset($value['route'])) {
  110. foreach ($value['route'] as $k => $v) {
  111. $name = substr($v[0], 4);
  112. $title = $v[1];
  113. $array[$name] = $title;
  114. $txt = '"' . $name . '"' . "=>" . '"' . $title . '"' . ',' . "\n";
  115. fwrite($myfile, $txt);
  116. }
  117. }
  118. }
  119. fclose($myfile);
  120. var_dump($array2);
  121. exit;
  122. }
  123. }