123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <?php
- /**
- * mobile父类
- *
- *
- */
- //use Shopnc\Tpl;
- defined('InShopNC') or exit('Access Invalid!');
- require_once (BASE_ROOT_PATH . "/helper/statistics_helper.php");
- /********************************** 前台control父类 **********************************************/
- class mobileControl
- {
- //客户端类型
- protected $client_type_array = array('android', 'wap', 'wechat', 'ios', 'ajax', 'web');
- //列表默认分页数
- protected $page_size;
- protected $cur_page;
- //任务开始时间
- private static $startime = 0;
- public function __construct()
- {
- self::$startime = microtime(true);
- Language::read('mobile');
- //分页数处理
- if (is_numeric($_GET['page']) && intval(trim($_GET['page'])) > 0) {
- $this->page_size = intval(trim($_GET['page']));
- } else {
- $this->page_size = 20;
- }
- if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
- $this->cur_page = intval(trim($_GET['curpage']));
- } else {
- $this->cur_page = 1;
- }
- $page = $this->cur_page;
- Log::record("curpage = {$page}",Log::DEBUG);
- initpage($this->page_size, $this->cur_page);
- $this->check_app_type();
- statistics_helper::instance()->add_call($_GET);
- }
- public function __destruct()
- {
- }
- protected function android()
- {
- return $_SESSION['client_type'] == 'android';
- }
- protected function page_size()
- {
- return $this->page_size;
- }
- protected function page_no()
- {
- return $this->cur_page;
- }
- protected function pages($count)
- {
- return intval($count / $this->page_size()) + ($count % $this->page_size() == 0 ? 0 : 1);
- }
- private static function eclipse_time()
- {
- return (microtime(true) - self::$startime);
- }
- protected function check_app_type()
- {
- $client = strtolower(trim($_SERVER['HTTP_CLIENT_TYPE']));
- $version = trim($_SERVER['HTTP_CLIENT_VERSION']);
- if (empty($client)) {
- $client = $_POST['client_type'];
- } else {
- $_SESSION['is_app'] = true;
- }
- if (empty($client) || !in_array($client, $this->client_type_array)) {
- $_SESSION['client_type'] = 'wap';
- } else {
- $_SESSION['client_type'] = $client;
- }
- if (!empty($version)) {
- $_SESSION['client_version'] = $version;
- }
- return true;
- }
- static public function outerr($code, $msg = '', $page = '',$type = NULL)
- {
- static $json_clients = array('android', 'ios');
- if(!is_null($type)) {
- $show_type = $type;
- } else {
- $show_type = $_SESSION['client_type'];
- }
- if (in_array($show_type, $json_clients))
- {
- joutput_error($code, $msg);
- }
- else if ($show_type == 'wap')
- {
- Tpl::clear();
- Tpl::output("error", $msg);
- if (!empty($page)) {
- Tpl::showpage($page);
- }
- }
- else if ($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/>";
- performance_helper::format_log();
- $sqls = Log::sql_log();
- echo "sql count = " . count($sqls) . "<br/><br/>";
- foreach ($sqls as $sql) {
- echo "{$sql}<br/>";
- }
- }
- return true;
- }
- static public function outsuccess($data, $page = '',$type = NULL)
- {
- static $json_clients = array('android', 'ios');
- if(!is_null($type)) {
- $show_type = $type;
- } else {
- $show_type = $_SESSION['client_type'];
- }
- if (in_array($show_type, $json_clients))
- {
- joutput_data($data);
- }
- else if ($show_type == 'wap')
- {
- Tpl::clear();
- if (is_array($data)) {
- foreach ($data as $key => $val) {
- Tpl::output($key, $val);
- }
- }
- if (!empty($page)) {
- Tpl::showpage($page);
- }
- }
- else if ($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/>";
- performance_helper::format_log();
- $sqls = Log::sql_log();
- echo "sql count = " . count($sqls) . "<br/><br/>";
- foreach ($sqls as $sql) {
- echo "{$sql}<br/>";
- }
- }
- return true;
- }
- public function separate_page($items,&$pages)
- {
- $arr_items = array_chunk($items,$this->page_size());
- $pages = count($arr_items);
- $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
- return ($arr_items[$page_no - 1]);
- }
- }
- class mobileHomeControl extends mobileControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- }
- /**
- * Class mbMemberControl
- */
- class mbMemberControl extends mobileControl
- {
- public $err_code = errcode::Success;
- public function __construct()
- {
- parent::__construct();
- if ($_SESSION['is_login'] != 1) {
- throw new UnloginException();
- }
- }
- }
- function bonus_version()
- {
- return "v=20161223";
- }
- function shop_version()
- {
- return "v=20161226";
- }
|