stanley-king 6 yıl önce
ebeveyn
işleme
89c5241e47
1 değiştirilmiş dosya ile 360 ekleme ve 360 silme
  1. 360 360
      mobile/control/control.php

+ 360 - 360
mobile/control/control.php

@@ -1,361 +1,361 @@
-<?php
-/**
- * mobile父类
- *
- *
- */
-
-//use Shopnc\Tpl;
-
-defined('InShopNC') or exit('Access Invalid!');
-
-require_once (BASE_ROOT_PATH . "/helper/statistics_helper.php");
-require_once (BASE_ROOT_PATH . "/helper/session_helper.php");
-require_once (BASE_ROOT_PATH . "/helper/bonus_helper.php");
-
-/********************************** 前台control父类 **********************************************/
-class mobileControl
-{
-    //客户端类型
-    private static $stClienTypes = ['android', 'wap', 'wechat', 'ios', 'ajax', 'web','mini'];
-
-    //列表默认分页数
-    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;
-        }
-        $this->initpage($this->page_size, $this->cur_page);
-        $this->check_app_type();
-
-        $param = $_GET;
-        $param['client_type'] = $_SESSION['client_type'];
-
-        $this->set_relay();
-        statistics_helper::instance()->add_call($param);
-    }
-
-    private function record_path()
-    {
-        $record = [];
-        $record['user_session'] = session_helper::session_id();
-        $record['member_id'] = session_helper::memberid();
-        $record['relay_id'] = session_helper::relay_id();
-        $record['add_time'] = time();
-        $record['exec_time'] = intval((microtime(true) - self::$startime) * 1000000);
-        $record['content'] = $_SERVER['original_querystring'];
-        $record['client_type'] = session_helper::client_type();
-
-        if(!empty($_GET['from'])) {
-            $from = base64_decode($_GET['from']);
-            Log::record("ort={$_GET['from']}",Log::DEBUG);
-            Log::record("from={$from}",Log::DEBUG);
-        }
-        Log::record_path(json_encode($record));
-    }
-
-    public function __destruct()
-    {
-        $this->record_path();
-    }
-
-    private function set_relay()
-    {
-        if(isset($_GET['relay_id'])) {
-            session_helper::set_relay($_GET['relay_id']);
-        }
-        elseif (isset($_COOKIE['relay_id'])) {
-            session_helper::set_relay($_COOKIE['relay_id']);
-        }
-    }
-
-    protected function initpage($page_size,$cur_page)
-    {
-        pagecmd('seteachnum', $page_size);
-        pagecmd('setnowpage', $cur_page);
-    }
-
-    protected function price_calcer()
-    {
-        if(session_helper::logined()) {
-            return new bonus\account(session_helper::memberid(),true);
-        } else {
-            return new bonus\normal_calc();
-        }
-    }
-
-    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);
-    }
-
-    /**
-     * @throws UnloginException
-     */
-    protected function need_login()
-    {
-        if ($_SESSION['is_login'] != 1) {
-            throw new UnloginException();
-        }
-    }
-
-    private static function eclipse_time()
-    {
-        return (microtime(true) - self::$startime);
-    }
-
-    function get_client_ip()
-    {
-        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
-            $ip = getenv('HTTP_CLIENT_IP');
-            Log::record("get_client_ip 1 = {$ip}",Log::DEBUG);
-        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
-            $ip = getenv('HTTP_X_FORWARDED_FOR');
-            Log::record("get_client_ip 2 = {$ip}",Log::DEBUG);
-
-        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
-            $ip = getenv('REMOTE_ADDR');
-            Log::record("get_client_ip 3 = {$ip}",Log::DEBUG);
-
-        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
-            $ip = $_SERVER['REMOTE_ADDR'];
-            Log::record("get_client_ip 4 = {$ip}",Log::DEBUG);
-
-        }
-        return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
-    }
-
-    protected function check_app_type()
-    {
-        $this->get_client_ip();
-        $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, self::$stClienTypes)) {
-            $_SESSION['client_type'] = 'wap';
-        } else {
-            $_SESSION['client_type'] = $client;
-        }
-
-        if (!empty($version)) {
-            $_SESSION['client_version'] = $version;
-        }
-
-        $version = intval($version * 100 + 0.5);
-        if($client == 'ios')
-        {
-            $cur_ver = $GLOBALS['setting_config']['mobile_ios_version'];
-            $lastest_version = intval($cur_ver * 100 + 0.5);
-            if($version >= $lastest_version) {
-                $_SESSION['is_lasted'] = true;
-            } else {
-                $_SESSION['is_lasted'] = false;
-            }
-        }
-        elseif($client == 'android')
-        {
-            $cur_ver = $GLOBALS['setting_config']['mobile_apk_version'];
-            $lastest_version = intval($cur_ver * 100 + 0.5);
-
-            if($version >= $lastest_version) {
-                $_SESSION['is_lasted'] = true;
-            } else {
-                $_SESSION['is_lasted'] = false;
-            }
-        }
-
-        return true;
-    }
-
-    static public function outerr($code, $msg = '', $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_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 = ['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);
-        }
-        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 extends mobileControl
-{
-    public $err_code = errcode::Success;
-
-    public function __construct()
-    {
-        parent::__construct();
-
-        if (!session_helper::logined()) {
-            throw new UnloginException();
-        }
-    }
-}
-
-function bonus_version()
-{
-    return "v=2018122802";
-}
-function shop_version()
-{
-    return "v=2018122802";
+<?php
+/**
+ * mobile父类
+ *
+ *
+ */
+
+//use Shopnc\Tpl;
+
+defined('InShopNC') or exit('Access Invalid!');
+
+require_once (BASE_ROOT_PATH . "/helper/statistics_helper.php");
+require_once (BASE_ROOT_PATH . "/helper/session_helper.php");
+require_once (BASE_ROOT_PATH . "/helper/bonus_helper.php");
+
+/********************************** 前台control父类 **********************************************/
+class mobileControl
+{
+    //客户端类型
+    private static $stClienTypes = ['android', 'wap', 'wechat', 'ios', 'ajax', 'web','mini'];
+
+    //列表默认分页数
+    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;
+        }
+        $this->initpage($this->page_size, $this->cur_page);
+        $this->check_app_type();
+
+        $param = $_GET;
+        $param['client_type'] = $_SESSION['client_type'];
+
+        $this->set_relay();
+        statistics_helper::instance()->add_call($param);
+    }
+
+    private function record_path()
+    {
+        $record = [];
+        $record['user_session'] = session_helper::session_id();
+        $record['member_id'] = session_helper::memberid();
+        $record['relay_id'] = session_helper::relay_id();
+        $record['add_time'] = time();
+        $record['exec_time'] = intval((microtime(true) - self::$startime) * 1000000);
+        $record['content'] = $_SERVER['original_querystring'];
+        $record['client_type'] = session_helper::client_type();
+
+        if(!empty($_GET['from'])) {
+            $from = base64_decode($_GET['from']);
+            Log::record("ort={$_GET['from']}",Log::DEBUG);
+            Log::record("from={$from}",Log::DEBUG);
+        }
+        Log::record_path(json_encode($record));
+    }
+
+    public function __destruct()
+    {
+        $this->record_path();
+    }
+
+    private function set_relay()
+    {
+        if(isset($_GET['relay_id'])) {
+            session_helper::set_relay($_GET['relay_id']);
+        }
+        elseif (isset($_COOKIE['relay_id'])) {
+            session_helper::set_relay($_COOKIE['relay_id']);
+        }
+    }
+
+    protected function initpage($page_size,$cur_page)
+    {
+        pagecmd('seteachnum', $page_size);
+        pagecmd('setnowpage', $cur_page);
+    }
+
+    protected function price_calcer()
+    {
+        if(session_helper::logined()) {
+            return new bonus\account(session_helper::memberid(),true);
+        } else {
+            return new bonus\normal_calc();
+        }
+    }
+
+    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);
+    }
+
+    /**
+     * @throws UnloginException
+     */
+    protected function need_login()
+    {
+        if ($_SESSION['is_login'] != 1) {
+            throw new UnloginException();
+        }
+    }
+
+    private static function eclipse_time()
+    {
+        return (microtime(true) - self::$startime);
+    }
+
+    function get_client_ip()
+    {
+        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
+            $ip = getenv('HTTP_CLIENT_IP');
+            Log::record("get_client_ip 1 = {$ip}",Log::DEBUG);
+        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
+            $ip = getenv('HTTP_X_FORWARDED_FOR');
+            Log::record("get_client_ip 2 = {$ip}",Log::DEBUG);
+
+        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
+            $ip = getenv('REMOTE_ADDR');
+            Log::record("get_client_ip 3 = {$ip}",Log::DEBUG);
+
+        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
+            $ip = $_SERVER['REMOTE_ADDR'];
+            Log::record("get_client_ip 4 = {$ip}",Log::DEBUG);
+
+        }
+        return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
+    }
+
+    protected function check_app_type()
+    {
+        $this->get_client_ip();
+        $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, self::$stClienTypes)) {
+            $_SESSION['client_type'] = 'wap';
+        } else {
+            $_SESSION['client_type'] = $client;
+        }
+
+        if (!empty($version)) {
+            $_SESSION['client_version'] = $version;
+        }
+
+        $version = intval($version * 100 + 0.5);
+        if($client == 'ios')
+        {
+            $cur_ver = $GLOBALS['setting_config']['mobile_ios_version'];
+            $lastest_version = intval($cur_ver * 100 + 0.5);
+            if($version >= $lastest_version) {
+                $_SESSION['is_lasted'] = true;
+            } else {
+                $_SESSION['is_lasted'] = false;
+            }
+        }
+        elseif($client == 'android')
+        {
+            $cur_ver = $GLOBALS['setting_config']['mobile_apk_version'];
+            $lastest_version = intval($cur_ver * 100 + 0.5);
+
+            if($version >= $lastest_version) {
+                $_SESSION['is_lasted'] = true;
+            } else {
+                $_SESSION['is_lasted'] = false;
+            }
+        }
+
+        return true;
+    }
+
+    static public function outerr($code, $msg = '', $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_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 = ['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);
+        }
+        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 extends mobileControl
+{
+    public $err_code = errcode::Success;
+
+    public function __construct()
+    {
+        parent::__construct();
+
+        if (!session_helper::logined()) {
+            throw new UnloginException();
+        }
+    }
+}
+
+function bonus_version()
+{
+    return "v=2018122802";
+}
+function shop_version()
+{
+    return "v=2018122802";
 }