AdminLogService.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. namespace common\services;
  3. use common\models\AccidentCasesUpdateHistory;
  4. use common\models\AdminLog;
  5. use common\models\BaseUser;
  6. class AdminLogService
  7. {
  8. public static array $ignoreList = [
  9. "/admin-log/list",
  10. "/admin-log/detail",
  11. "/admin-log/url-title",
  12. "/admin-log/staff-list",
  13. "/mail/get-unread-messages-number",
  14. "/accident-cases/study",
  15. ];
  16. public static array $ignoreContentList = [
  17. "/basic/rules-add-batch",
  18. "/user/add-batch",
  19. ];
  20. public static array $staffTitle = [
  21. "/login/index",
  22. "/user/logout",
  23. "/accident-cases/add",
  24. "/accident-cases/update",
  25. "/accident-cases/update-total-score",
  26. "/emergency-response/add",
  27. "/emergency-response/update",
  28. "/emergency-response/delete",
  29. "/operational-adjustments/add",
  30. "/operational-adjustments/update",
  31. "/operational-adjustments/delete",
  32. "/event-overview/add",
  33. "/event-overview/update",
  34. "/event-overview/delete",
  35. "/event-source-data/add",
  36. "/event-source-data/delete",
  37. "/accident-cases-score/update",
  38. "/accident-cases-dimension/update",
  39. "/operational-adjustments-dimension/update",
  40. "/emergency-response-dimension/update",
  41. "/case/detail",
  42. "/case/list-new",
  43. "/accident-cases/delete",
  44. "/accident-cases/publish",
  45. "/accident-cases/cancel",
  46. "/accident-cases/revoke",
  47. "/accident-cases/refuse",
  48. "/accident-cases/commit",
  49. "/accident-cases/pass"
  50. ];
  51. public static array $title = [
  52. "/accident-cases/list" => "案例列表",
  53. "/accident-cases/add" => "案例添加",
  54. "/accident-cases/update" => "案例修改",
  55. "/accident-cases/update-total-score" => "案例评语修改",
  56. "/accident-cases/delete" => "案例删除",
  57. "/accident-cases/publish" => "案例上架",
  58. "/accident-cases/revoke" => "案例下架",
  59. "/accident-cases/pass" => "案例通过",
  60. "/accident-cases/refuse" => "案例驳回",
  61. "/accident-cases/commit" => "案例提交",
  62. "/accident-cases/cancel" => "案例撤回",
  63. "/accident-cases-dimension/update" => "评价维度修改",
  64. "/accident-cases-focus/list" => "关注列表",
  65. "/accident-cases-focus/add" => "添加关注",
  66. "/accident-cases-focus/cancel" => "取消关注",
  67. "/accident-cases-score-config/info" => "评价打分显示配置",
  68. "/accident-cases-score-config/update" => "评价打分显示配置修改",
  69. "/accident-cases-score/update" => "评价打分",
  70. "/basic/rules-show-list" => "规则需要展示的列表",
  71. "/basic/rules-get-by-id" => "规则需要展示的列表",
  72. "/basic/rules-get-by-case-id" => "根据案例ID展示规章",
  73. "/basic/rules-and-points-by-event-id" => "通过应急处置ID或者运营调整ID查找规章",
  74. "/basic/rules-list" => "规则列表",
  75. "/basic/rules-add" => "规章添加",
  76. "/basic/rules-add-batch" => "从excel批量导入规章",
  77. "/basic/rules-update" => "规章修改",
  78. "/basic/rules-delete" => "规章删除",
  79. "/basic/rules-list-category" => "规章列表",
  80. "/basic/rules-points-list-by-id" => "规章知识点列表",
  81. "/basic/rules-points-add" => "规章知识点添加",
  82. "/basic/rules-points-update" => "规章知识点更新",
  83. "/basic/rules-points-delete-by-id" => "规章知识点删除",
  84. "/case/search-history" => "搜索历史",
  85. "/case/recommend" => "推荐案例",
  86. "/case/list-new" => "案例搜索",
  87. "/case/detail" => "案例详情",
  88. "/case/compare" => "案例对比",
  89. "/case-manage/check" => "查询案例是否重名",
  90. "/dictionary/list" => "字典对象数据",
  91. "/dictionary/list-category" => "字典分类列表",
  92. "/dictionary/list-category-name" => "字典分类列表",
  93. "/dictionary/list-all" => "字典列表",
  94. "/dictionary/all" => "字典列表",
  95. "/dictionary/add" => "字典添加",
  96. "/dictionary/update" => "字典修改",
  97. "/emergency-response/list" => "应急处置列表",
  98. "/emergency-response/add" => "应急处置添加",
  99. "/emergency-response/update" => "应急处置修改",
  100. "/emergency-response/delete" => "应急处置删除",
  101. "/emergency-response-dimension/update" => "评价维度修改",
  102. "/event-overview/list" => "事件概览列表",
  103. "/event-overview/add" => "事件概览添加",
  104. "/event-overview/update" => "事件概览修改",
  105. "/event-overview/delete" => "事件概览删除",
  106. "/event-source-data/list" => "原始资料列表",
  107. "/event-source-data/add" => "原始资料添加",
  108. "/event-source-data/delete" => "原始资料删除",
  109. "/login/index" => "登录",
  110. "/login/check-username" => "校验昵称",
  111. "/login/x5Login" => "x5登录",
  112. "/operational-adjustments/list" => "运营调整列表",
  113. "/operational-adjustments/add" => "添加运营调整",
  114. "/operational-adjustments/update" => "运营调整修改",
  115. "/operational-adjustments/delete" => "运营调整删除",
  116. "/operational-adjustments-dimension/update" => "评价维度修改",
  117. "/permission/route" => "路由列表",
  118. "/permission/route-refresh" => "刷新路由",
  119. "/permission/route-list" => "读取路由",
  120. "/permission/route-update" => "路由修改",
  121. "/permission/role" => "角色列表",
  122. "/permission/roles-list" => "角色合集",
  123. "/permission/role-add" => "角色新增",
  124. "/permission/role-update" => "角色资料和权限修改",
  125. "/search-config/info" => "高级搜索显示配置",
  126. "/search-config/update" => "高级搜索显示配置修改",
  127. "/system/department-list" => "部门列表",
  128. "/system/department-add" => "部门添加",
  129. "/system/department-update" => "部门修改",
  130. "/system/job-list" => "岗位列表",
  131. "/system/job-add" => "岗位添加",
  132. "/system/job-update" => "岗位修改",
  133. "/system/roles-list" => "类型列表",
  134. "/upload/user-avatar" => "上传头像",
  135. "/upload/case-avatar" => "头像上传",
  136. "/user/list" => "用户列表",
  137. "/user/info" => "用户信息",
  138. "/user/add" => "用户添加",
  139. "/user/user-update" => "用户修改",
  140. "/user/add-batch" => "从excel批量导入",
  141. "/user/check" => "用户名查重",
  142. "/user/change-info" => "修改资料",
  143. "/user/save-avatar" => "保存头像",
  144. "/user/logout" => "登出",
  145. "/util/time-feature" => "时间特征查询",
  146. ];
  147. public static function saveLog(BaseUser $userInfo, $url, $params)
  148. {
  149. if (in_array($url, self::$ignoreList)) {
  150. return 0;
  151. }
  152. $content = "excel批量导入不保存参数";
  153. if (!in_array($url, self::$ignoreContentList)) {
  154. $content = is_array($params) && count($params) == 0 ? json_encode(['default' => '无请求参数'], JSON_UNESCAPED_UNICODE) : json_encode($params, JSON_UNESCAPED_UNICODE);
  155. }
  156. $AdminLog = new AdminLog();
  157. $AdminLog->uid = $userInfo->id;
  158. $AdminLog->role_name = $userInfo->roleName;
  159. $AdminLog->username = $userInfo->username;
  160. $AdminLog->name = $userInfo->realName;
  161. $AdminLog->url = $url;
  162. $AdminLog->ip = $_SERVER["REMOTE_ADDR"];
  163. $AdminLog->title = self::$title[$url] ?? $url; // 等价 isset(self::$title[$url]) ? self::$title[$url] : $url 网址:https://wiki.php.net/rfc/isset_ternary
  164. $AdminLog->content = $content;
  165. $AdminLog->create_time = date("Y-m-d H:i:s");
  166. $AdminLog->history_id = 0;
  167. $AdminLog->save();
  168. return $AdminLog;
  169. }
  170. public static function saveLogWithUpdateHistory($origin, $model, $caseId, $caseTitle, $allParams): void
  171. {
  172. if (isset($allParams["adminLogId"])) {
  173. /** @var $adminLogModel AdminLog */
  174. $adminLogModel = $allParams["adminLogModel"];
  175. $history = new AccidentCasesUpdateHistory();
  176. $history->admin_log_id = $allParams["adminLogId"];
  177. $history->uid = $adminLogModel->uid;
  178. $history->name = $adminLogModel->name;
  179. $history->role_name = $adminLogModel->role_name;
  180. $history->username = $adminLogModel->username;
  181. $history->url = $adminLogModel->url;
  182. $history->title = $adminLogModel->title;
  183. $history->case_id = $caseId;
  184. $history->case_title = $caseTitle;
  185. $history->content = $adminLogModel->content;
  186. $history->ip = $adminLogModel->ip;
  187. $history->create_time = $adminLogModel->create_time;
  188. $history->origin = $origin;
  189. $history->current = self::dealWithModel($model);
  190. $history->save();
  191. }
  192. }
  193. public static function getOrigin($model, $allParams, $isCreate = false)
  194. {
  195. if ($isCreate) {
  196. return "";
  197. }
  198. //查询原始资料
  199. if (isset($allParams["adminLogId"])) {
  200. if ($model == "") {
  201. $new = "";
  202. } else {
  203. $new = clone $model;
  204. }
  205. return self::dealWithModel($new);
  206. }
  207. return "";
  208. }
  209. public static function dealWithModel($model)
  210. {
  211. if ($model == "") {
  212. return "";
  213. }
  214. if ($model->hasAttribute("source_data") && $model->source_data != "[]") {
  215. $sourceDataList = array_column(EventSourceDataService::getSourceDataListByAccidentId($model->accident_id), null, "id");
  216. self::dealWithSourceData($model, $sourceDataList);
  217. }
  218. return json_encode($model->getAttributes());
  219. }
  220. public static function dealWithSourceData($model, $sourceDataList)
  221. {
  222. $sourceDataIdList = json_decode($model->source_data, true);
  223. $sourceDataObj = [];
  224. foreach ($sourceDataIdList as $sourceDataId) {
  225. if (isset($sourceDataList[$sourceDataId])) {
  226. $sourceDataObj[] = $sourceDataList[$sourceDataId]->getAttributes();
  227. }
  228. }
  229. $model->source_data = $sourceDataObj;
  230. }
  231. }