Install.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\home\middleware;
  15. use systematic\Systematic;
  16. use think\facade\Db;
  17. use think\facade\Session;
  18. class Install
  19. {
  20. protected $module = '';
  21. protected $controller = '';
  22. protected $action = '';
  23. public function handle($request, \Closure $next)
  24. {
  25. if (!is_installed()) {
  26. return $request->isAjax() ? to_assign(1, '请先完成系统安装引导') : redirect((string) url('/install/index'));
  27. }
  28. $module = strtolower(app('http')->getName());
  29. $this->module = $module;
  30. $param = $request->param();
  31. $logtype = isset($param['logtype'])?$param['logtype']:'';
  32. $module_son = isset($param['module_son'])?$param['module_son']:'';
  33. $module_old = [];
  34. if($module_son!='' && ($logtype != 'add' || $logtype != 'delete')){
  35. $module_old = Db::name($module_son)->where('id',$param['id'])->find();
  36. }
  37. //return $next($request);
  38. //获取响应,获取响应之前的代码为前置中间件,
  39. //do songthing
  40. //----------以上部分为前置中间件--------------
  41. $response=$next($request);
  42. //----------以下部分为后置中间件--------------
  43. //获取响应之后的为后置中间件的执行内容
  44. $this->controller = strtolower($request->controller());
  45. $this->action = strtolower($request->action());
  46. //获取返回的HTTPCode
  47. //$code = $response->getCode();
  48. $responseData = $response->getData();
  49. if(isset($responseData['code']) && $responseData['code'] == 0){
  50. if(isset($responseData['datas'])){
  51. $logData = $responseData['datas'];
  52. }
  53. else{
  54. $logData = $responseData['data'];
  55. }
  56. $log_conf = get_config('log');
  57. $type_action = $log_conf['type_action'];
  58. if(isset($logData['logtype']) && isset($logData['id']) && isset($type_action[$logData['logtype']])){
  59. $logData['type_title'] = $type_action[$logData['logtype']];
  60. $moduleLogData = [];
  61. if($module_son!='' && isset($log_conf[$this->module])){
  62. $log_conf_module = $log_conf[$this->module];
  63. $module_field_key = $log_conf_module[$module_son];
  64. $module_new = Db::name($module_son)->where('id',$logData['id'])->find();
  65. $param_id = $module_new['id'];
  66. $param_son_id = 0;
  67. if($module_son!=$this->module){
  68. $param_id = $module_new[$this->module.'_id'];
  69. $param_son_id = $module_new['id'];
  70. }
  71. else{
  72. $module_son = '';
  73. }
  74. if(isset($module_field_key)){
  75. $moduleLogData = [
  76. 'param_id'=>$param_id,
  77. 'module_son'=>$module_son,
  78. 'param_son_id'=>$param_son_id,
  79. 'old'=>$module_old,
  80. 'new'=>$module_new,
  81. 'key'=>$module_field_key
  82. ];
  83. }
  84. }
  85. $this->addLog($logData,$moduleLogData);
  86. }
  87. }
  88. //这里回调本身返回response对象
  89. return $response;
  90. }
  91. /*
  92. public function end(\think\Response $response){
  93. dump($response->getData());
  94. exit;
  95. //dump($response->header());
  96. }
  97. */
  98. protected function addLog($logData = [],$moduleLogData=[])
  99. {
  100. $session_admin = get_config('app.session_admin');
  101. $uid = Session::get($session_admin);
  102. $data = [
  103. 'uid' => $uid,
  104. 'type' => $logData['logtype'],
  105. 'action' => $logData['type_title'],
  106. 'param_id' => $logData['id'],
  107. 'param' => json_encode($logData),
  108. 'module' => $this->module,
  109. 'controller' => $this->controller,
  110. 'function' => $this->action,
  111. 'ip' => app('request')->ip(),
  112. 'create_time' => time(),
  113. 'subject' => '系统'
  114. ];
  115. if(isset($logData['subject']) && $logData['subject'] != ''){
  116. $data['subject'] = $logData['subject'];
  117. }
  118. else{
  119. $rule = $data['module'] . '/' . $data['controller'] . '/' . $data['function'];
  120. $rule_menu = Db::name('AdminRule')->where(array('src' => $rule))->find();
  121. if($rule_menu){
  122. $data['subject'] = $rule_menu['name'];
  123. }
  124. }
  125. Db::name('AdminLog')->strict(false)->field(true)->insert($data);
  126. if(!empty($moduleLogData)){
  127. $GOUGU = new Systematic();
  128. $GOUGU->moduleLog($uid,$logData['logtype'],$this->module,$moduleLogData);
  129. }
  130. }
  131. }