merchantweb.php 4.3 KB

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