123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- require_once(BASE_HELPER_PATH . "/session_helper.php");
- class merchantwebControl
- {
- //列表默认分页数
- protected $page;
- protected $cur_page;
- //任务开始时间
- private static $startime = 0;
- public function __construct()
- {
- $_SESSION['client_type'] = $_GET['client_type'];
- if (is_numeric($_GET['page']) && intval(trim($_GET['page'])) > 0) {
- $this->page = intval(trim($_GET['page']));
- } else {
- $this->page = 10;
- }
- if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
- $this->cur_page = intval(trim($_GET['curpage']));
- } else {
- $this->cur_page = 1;
- }
- $this->initpage($this->page, $this->cur_page);
- }
- public static function outerr($code, $msg = '', $page = '', $type = 'ajax')
- {
- static $json_clients = ['android', 'ios', 'mini'];
- if (!empty($type)) {
- $show_type = $type;
- } else {
- $show_type = $_SESSION['client_type'];
- }
- if (in_array($show_type, $json_clients)) {
- joutput_error($code, $msg);
- } elseif ($show_type == 'wap') {
- Tpl::clear();
- Tpl::output("error", $msg);
- if (!empty($page)) {
- Tpl::showpage($page);
- }
- } elseif ($show_type == 'ajax') {
- $callback = $_GET['callback'];
- if (!isset($callback) || empty($callback)) {
- joutput_error($code, $msg);
- } else {
- echo "{$callback}(";
- joutput_error($code, $msg);
- echo ");";
- }
- } else {
- if (empty($msg)) {
- $msg = errcode::msg($code);
- }
- $start = microtime(true);
- echo joutput_error($code, $msg, 'web') . "<br/>";
- perfor_period("joutput", $start, "web");
- echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
- echo "性能关键统计:<br/><br/>";
- echo perfor_log();
- $sqls = Log::sql_log();
- echo "sql count = " . count($sqls) . "<br/><br/>";
- foreach ($sqls as $sql) {
- echo "{$sql}<br/>";
- }
- }
- return true;
- }
- public static function outsuccess($data, $page = '', $type = NULL)
- {
- static $json_clients = ['android', 'ios', 'mini'];
- if (!empty($type)) {
- $show_type = $type;
- } else {
- $show_type = $_SESSION['client_type'];
- }
- if (in_array($show_type, $json_clients)) {
- joutput_data($data);
- } elseif ($show_type == 'wap') {
- Tpl::clear();
- if (is_array($data)) {
- foreach ($data as $key => $val) {
- Tpl::output($key, $val);
- }
- }
- if (!empty($page)) {
- Tpl::showpage($page);
- }
- } elseif ($show_type == 'ajax') {
- $callback = $_GET['callback'];
- if (!isset($callback) || empty($callback)) {
- joutput_data($data);
- } else {
- echo "{$callback}(";
- joutput_data($data);
- echo ");";
- }
- } else {
- echo 'success: return data=<br/>';
- $start = microtime(true);
- joutput_data($data, 'web');
- perfor_period("joutput", $start, "web");
- echo "<br/><br/>";
- echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
- echo "性能关键统计:<br/><br/>";
- echo perfor_log();
- $sqls = Log::sql_log();
- echo "sql count = " . count($sqls) . "<br/><br/>";
- foreach ($sqls as $sql) {
- echo "{$sql}<br/>";
- }
- }
- return true;
- }
- private static function eclipse_time()
- {
- return (microtime(true) - self::$startime);
- }
- protected function initpage($page_size, $cur_page)
- {
- pagecmd('seteachnum', $page_size);
- pagecmd('setnowpage', $cur_page);
- }
- }
- class mbMerchantControl extends merchantwebControl
- {
- public $err_code = errcode::Success;
- public function __construct()
- {
- parent::__construct();
- if (empty($_SESSION['mchid'])) {
- throw new UnloginException();
- }
- }
- public function mchid()
- {
- return intval($_SESSION['mchid']);
- }
- }
|