merchant_base.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. require_once (BASE_HELPER_PATH . "/session_helper.php");
  3. class merchant_baseControl
  4. {
  5. //列表默认分页数
  6. protected $page;
  7. protected $cur_page;
  8. public function __construct()
  9. {
  10. $_SESSION['client_type'] = $_GET['client_type'];
  11. if($_GET['act'] != 'merchant_login'){
  12. if (empty($_SESSION['mch_id'])) {
  13. throw new UnloginException();
  14. }
  15. }
  16. if (is_numeric($_GET['page']) && intval(trim($_GET['page'])) > 0) {
  17. $this->page = intval(trim($_GET['page']));
  18. } else {
  19. $this->page = 10;
  20. }
  21. if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
  22. $this->cur_page = intval(trim($_GET['curpage']));
  23. } else {
  24. $this->cur_page = 1;
  25. }
  26. $this->initpage($this->page, $this->cur_page);
  27. }
  28. public static function outerr($code, $msg = '', $page = '', $type = 'ajax')
  29. {
  30. static $json_clients = ['android', 'ios','mini'];
  31. if(!empty($type)) {
  32. $show_type = $type;
  33. } else {
  34. $show_type = $_SESSION['client_type'];
  35. }
  36. if (in_array($show_type, $json_clients))
  37. {
  38. joutput_error($code, $msg);
  39. }
  40. elseif ($show_type == 'wap')
  41. {
  42. Tpl::clear();
  43. Tpl::output("error", $msg);
  44. if (!empty($page)) {
  45. Tpl::showpage($page);
  46. }
  47. }
  48. elseif ($show_type == 'ajax')
  49. {
  50. $callback = $_GET['callback'];
  51. if(!isset($callback) || empty($callback)) {
  52. joutput_error($code, $msg);
  53. } else {
  54. echo "{$callback}(";
  55. joutput_error($code, $msg);
  56. echo ");";
  57. }
  58. }
  59. else
  60. {
  61. if(empty($msg)) {
  62. $msg = errcode::msg($code);
  63. }
  64. $start = microtime(true);
  65. echo joutput_error($code, $msg, 'web') . "<br/>";
  66. perfor_period("joutput",$start,"web");
  67. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  68. echo "性能关键统计:<br/><br/>";
  69. performance_helper::format_log();
  70. $sqls = Log::sql_log();
  71. echo "sql count = " . count($sqls) . "<br/><br/>";
  72. foreach ($sqls as $sql) {
  73. echo "{$sql}<br/>";
  74. }
  75. }
  76. return true;
  77. }
  78. public static function outsuccess($data, $page = '', $type = NULL)
  79. {
  80. static $json_clients = ['android', 'ios','mini'];
  81. if(!empty($type)) {
  82. $show_type = $type;
  83. } else {
  84. $show_type = $_SESSION['client_type'];
  85. }
  86. if (in_array($show_type, $json_clients))
  87. {
  88. joutput_data($data);
  89. }
  90. elseif ($show_type == 'wap')
  91. {
  92. Tpl::clear();
  93. if (is_array($data)) {
  94. foreach ($data as $key => $val) {
  95. Tpl::output($key, $val);
  96. }
  97. }
  98. if (!empty($page)) {
  99. Tpl::showpage($page);
  100. }
  101. }
  102. elseif ($show_type == 'ajax')
  103. {
  104. $callback = $_GET['callback'];
  105. if(!isset($callback) || empty($callback)) {
  106. joutput_data($data);
  107. } else {
  108. echo "{$callback}(";
  109. joutput_data($data);
  110. echo ");";
  111. }
  112. }
  113. else
  114. {
  115. echo 'success: return data=<br/>';
  116. $start = microtime(true);
  117. joutput_data($data, 'web');
  118. perfor_period("joutput",$start,"web");
  119. echo "<br/><br/>";
  120. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  121. echo "性能关键统计:<br/><br/>";
  122. performance_helper::format_log();
  123. $sqls = Log::sql_log();
  124. echo "sql count = " . count($sqls) . "<br/><br/>";
  125. foreach ($sqls as $sql) {
  126. echo "{$sql}<br/>";
  127. }
  128. }
  129. return true;
  130. }
  131. protected function initpage($page_size,$cur_page)
  132. {
  133. pagecmd('seteachnum', $page_size);
  134. pagecmd('setnowpage', $cur_page);
  135. }
  136. }