Controller.php 6.0 KB

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