AppframeController.class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. namespace Common\Controller;
  8. use Think\Controller;
  9. class AppframeController extends Controller {
  10. function _initialize() {
  11. $this->assign("waitSecond", 3);
  12. $time=time();
  13. $this->assign("js_debug",APP_DEBUG?"?v=$time":"");
  14. if(APP_DEBUG){
  15. }
  16. }
  17. /**
  18. * Ajax方式返回数据到客户端
  19. * @access protected
  20. * @param mixed $data 要返回的数据
  21. * @param String $type AJAX返回数据格式
  22. * @return void
  23. */
  24. protected function ajaxReturn($data, $type = '',$json_option=0) {
  25. $data['referer']=$data['url'] ? $data['url'] : "";
  26. $data['state']=$data['status'] ? "success" : "fail";
  27. if(empty($type)) $type = C('DEFAULT_AJAX_RETURN');
  28. switch (strtoupper($type)){
  29. case 'JSON' :
  30. // 返回JSON数据格式到客户端 包含状态信息
  31. header('Content-Type:application/json; charset=utf-8');
  32. exit(json_encode($data,$json_option));
  33. case 'XML' :
  34. // 返回xml格式数据
  35. header('Content-Type:text/xml; charset=utf-8');
  36. exit(xml_encode($data));
  37. case 'JSONP':
  38. // 返回JSON数据格式到客户端 包含状态信息
  39. header('Content-Type:application/json; charset=utf-8');
  40. $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER');
  41. exit($handler.'('.json_encode($data,$json_option).');');
  42. case 'EVAL' :
  43. // 返回可执行的js脚本
  44. header('Content-Type:text/html; charset=utf-8');
  45. exit($data);
  46. case 'AJAX_UPLOAD':
  47. // 返回JSON数据格式到客户端 包含状态信息
  48. header('Content-Type:text/html; charset=utf-8');
  49. exit(json_encode($data,$json_option));
  50. default :
  51. // 用于扩展其他返回格式数据
  52. Hook::listen('ajax_return',$data);
  53. }
  54. }
  55. //分页
  56. protected function page($Total_Size = 1, $Page_Size = 0, $Current_Page = 1, $listRows = 6, $PageParam = '', $PageLink = '', $Static = FALSE) {
  57. import('Page');
  58. if ($Page_Size == 0) {
  59. $Page_Size = C("PAGE_LISTROWS");
  60. }
  61. if (empty($PageParam)) {
  62. $PageParam = C("VAR_PAGE");
  63. }
  64. $Page = new \Page($Total_Size, $Page_Size, $Current_Page, $listRows, $PageParam, $PageLink, $Static);
  65. $Page->SetPager('default', '{first}{prev}{liststart}{list}{listend}{next}{last}', array("listlong" => "9", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
  66. return $Page;
  67. }
  68. //空操作
  69. public function _empty() {
  70. $this->error('该页面不存在!');
  71. }
  72. /**
  73. * 检查操作频率
  74. * @param int $duration 距离最后一次操作的时长
  75. */
  76. protected function check_last_action($duration){
  77. $action=MODULE_NAME."-".CONTROLLER_NAME."-".ACTION_NAME;
  78. $time=time();
  79. if(!empty($_SESSION['last_action']['action']) && $action==$_SESSION['last_action']['action']){
  80. $mduration=$time-$_SESSION['last_action']['time'];
  81. if($duration>$mduration){
  82. $this->error("您的操作太过频繁,请稍后再试~~~");
  83. }else{
  84. $_SESSION['last_action']['time']=$time;
  85. }
  86. }else{
  87. $_SESSION['last_action']['action']=$action;
  88. $_SESSION['last_action']['time']=$time;
  89. }
  90. }
  91. }