Controller.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Routing\Controller as BaseController;
  4. use Request,Auth,Response;
  5. /**
  6. * 父控制类类
  7. *
  8. * @author wangzhoudong <m@9026.com>
  9. */
  10. abstract class Controller extends BaseController
  11. {
  12. protected $_user;
  13. protected $_serviceAdminRole;
  14. public function __construct() {
  15. $this->middleware(function ($request, $next) {
  16. $this->_user = Auth::guard('admin')->user();
  17. view()->share('_user',$this->_user);
  18. return $next($request);
  19. });
  20. }
  21. public function api($data) {
  22. return Response::json($data);
  23. }
  24. public function formatUrl($url){
  25. // echo substr($url, 0, 7);
  26. //dd($url);
  27. if (substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://') {
  28. if(substr($url, 0, 7) == 'http://'){
  29. $url = str_replace('http://','https://',$url);
  30. }
  31. if(substr($url,0,19) == 'https://t6.9026.com'){
  32. $url = str_replace('https://t6.9026.com',env('CDN_URL'),$url);
  33. }
  34. return $url;
  35. } else {
  36. return env('APP_URL').$url;
  37. }
  38. }
  39. /**
  40. * 检测表单篡改
  41. *
  42. * @return true|exception
  43. */
  44. protected function checkFormHash()
  45. {
  46. return (new Formhash())->checkFormHash();
  47. }
  48. /**
  49. * 启用操作日志记录
  50. */
  51. protected function setActionLog($extDatas = [])
  52. {
  53. return app()->make(Mark::BIND_NAME)->setMarkYes()->setExtDatas($extDatas);
  54. }
  55. /**
  56. * 显示提示消息
  57. */
  58. public function showMessage($msg, $links = NULL, $data = NULL, $redirect = true)
  59. {
  60. $this->_showMessage($msg, $links, $data, SUCESS_CODE, $redirect);
  61. }
  62. /**
  63. * 显示错误消息
  64. */
  65. public function showWarning($msg, $links = NULL, $data = NULL, $redirect = true)
  66. {
  67. $this->_showMessage($msg, $links, $data, FAILURE_CODE, $redirect);
  68. }
  69. /**
  70. * 显示消息
  71. */
  72. public function _showMessage($msgs, $links, $data, $code, $redirect)
  73. {
  74. header("Content-type:text/html;charset=utf-8");
  75. if(!is_array($msgs)) {
  76. $msgs = array($msgs);
  77. }
  78. $urls = $links;
  79. if(!is_array($links)) {
  80. $urls = array();
  81. if($links) {
  82. $urls[0]['url'] = $links;
  83. }elseif(isset($_SERVER['HTTP_REFERER'])) {
  84. $urls[0]['url'] = $_SERVER['HTTP_REFERER'];
  85. }else{
  86. $urls[0]['url'] = 'javascript:history.back();';
  87. }
  88. $urls[0]['title'] = '点击立即跳转';
  89. }
  90. if($redirect) {
  91. $redirect = $urls[0]['url'];
  92. $redirect = (strstr($redirect, 'javascript:') !== false) ? $redirect : "location.href='{$redirect}'";
  93. } else {
  94. $redirect = '';
  95. }
  96. if(Request::ajax()){
  97. $retval['msg'] = $msgs;
  98. $retval['redirect'] = $redirect;
  99. $retval['data'] = $data;
  100. $retval['status'] = $code;
  101. echo json_encode($retval);exit;
  102. return ;
  103. }
  104. if($links=="refresh") {
  105. echo "<script>alert('{$msgs[0]}');</script>";
  106. echo "<script>window.close();</script>";
  107. echo "<script>opener.location.reload();</script>";
  108. exit;
  109. }
  110. if($code==SUCESS_CODE) {
  111. $ico = '<i class="fa fa-check"></i>';
  112. $titleHtml = '信息提示';
  113. }else{
  114. $ico = '<i class="fa fa-warning"></i>';
  115. $titleHtml = '错误警告';
  116. }
  117. $msgHtml = '';
  118. foreach ($msgs as $msg) {
  119. $msgHtml .= "<li>$msg</li>";
  120. }
  121. $urlHtml = '';
  122. foreach ($urls as $url) {
  123. if($url['url'] == 'history_back'){
  124. $u = "javascript:history.back();";
  125. }else{
  126. $u = $url['url'];
  127. }
  128. $urlHtml .= '&nbsp;<a class="btn btn-primary" href="' . $u . '" >' . $url['title'] . '</a>';
  129. }
  130. $html ='<!DOCTYPE html>
  131. <html>
  132. <head>
  133. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  134. <meta name="renderer" content="webkit">
  135. <title>' . $titleHtml .'</title>
  136. <link href="/base/css/bootstrap.min.css?v=3.4.0.css" rel="stylesheet">
  137. <link href="/base/css/font-awesome.min.css?v=4.3.0.css" rel="stylesheet">
  138. <link href="/base/css/style.min.css?v=3.0.0.css" rel="stylesheet">
  139. <script type="text/javascript">
  140. setTimeout(function(){
  141. var url = "' . $urls[0]['url'] . '";
  142. if(url == "history_back"){
  143. window.location.href = history.back();
  144. }else{
  145. window.location.href = url;
  146. }
  147. }, 3000);
  148. </script>
  149. </head>
  150. <body class="gray-bg">
  151. <div class="ibox-content middle-box" style="width:600px; margin-top: 150px;">
  152. <h2 class="text-center">' . $ico . ' ' . $titleHtml . '</h2>
  153. <ul class="todo-list m-t ui-sortable">
  154. ' . $msgHtml . '
  155. </ul>
  156. <div class="text-center">
  157. 该页面将在 3 秒钟后自动转向
  158. </div>
  159. <div class="text-center" style="margin-top: 10px;">
  160. ' . $urlHtml . '
  161. <a href="javascript:history.back();" class="btn btn-success">
  162. 返回
  163. </a>
  164. </div>
  165. </div>
  166. </body>
  167. </html>';
  168. exit($html);
  169. }
  170. }