merchantweb.php 4.4 KB

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