control.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * mobile父类
  4. *
  5. *
  6. */
  7. //use Shopnc\Tpl;
  8. defined('InShopNC') or exit('Access Invalid!');
  9. /********************************** 前台control父类 **********************************************/
  10. class mobileControl
  11. {
  12. //客户端类型
  13. protected $client_type_array = array('android', 'wap', 'wechat', 'ios', 'ajax', 'web');
  14. //列表默认分页数
  15. //protected $page_size = 5;
  16. protected $page = 5;
  17. protected $cur_page = 1;
  18. //任务开始时间
  19. private static $startime = 0;
  20. public function __construct()
  21. {
  22. self::$startime = microtime(true);
  23. Language::read('mobile');
  24. //分页数处理
  25. if (is_numeric($_GET['page']) && intval(trim($_GET['page'])) > 0) {
  26. $this->page = intval(trim($_GET['page']));
  27. }
  28. if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
  29. $this->cur_page = intval(trim($_GET['curpage']));
  30. }
  31. $this->check_app_type();
  32. }
  33. protected function page_size()
  34. {
  35. return $this->page;
  36. }
  37. protected function page_no()
  38. {
  39. return $this->cur_page;
  40. }
  41. private static function eclipse_time()
  42. {
  43. return (microtime(true) - self::$startime);
  44. }
  45. protected function check_app_type()
  46. {
  47. Log::record(">>>>>> check_app_type={$_SERVER['HTTP_CLIENT_TYPE']}",Log::DEBUG);
  48. $client = strtolower(trim($_SERVER['HTTP_CLIENT_TYPE']));
  49. $version = trim($_SERVER['HTTP_CLIENT_VERSION']);
  50. if (empty($client)) {
  51. $client = $_POST['client_type'];
  52. }
  53. if (empty($client) || !in_array($client, $this->client_type_array)) {
  54. $_SESSION['client_type'] = 'wap';
  55. } else {
  56. $_SESSION['client_type'] = $client;
  57. }
  58. Log::record(">>>>>> client_type={$_SESSION['client_type']}",Log::DEBUG);
  59. if (!empty($version)) {
  60. $_SESSION['client_version'] = $version;
  61. }
  62. return true;
  63. }
  64. static public function outerr($code, $msg = '', $page = '')
  65. {
  66. static $json_clients = array('android', 'ios', 'ajax');
  67. Log::record(">>>>>> outerr, client_type={$_SESSION['client_type']}",Log::DEBUG);
  68. if (in_array($_SESSION['client_type'], $json_clients)) {
  69. Log::record(">>>>>> outerr, 1",Log::DEBUG);
  70. joutput_error($code, $msg);
  71. } else if ($_SESSION['client_type'] == 'wap') {
  72. Tpl::output("error", $msg);
  73. if (!empty($page)) {
  74. TPL::showpage($page);
  75. }
  76. Log::record(">>>>>> outerr, 1",Log::DEBUG);
  77. joutput_error($code, $msg);
  78. } else {
  79. Log::record(">>>>>> outerr, 1",Log::DEBUG);
  80. if (empty($msg)) {
  81. $msg = errcode::msg($code);
  82. }
  83. echo joutput_error($code, $msg, 'web') . "<br/>";
  84. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  85. echo "性能关键统计:<br/><br/>";
  86. performance_helper::format_log();
  87. $sqls = Log::sql_log();
  88. echo "sql count = " . count($sqls) . "<br/><br/>";
  89. foreach ($sqls as $sql) {
  90. echo "{$sql}<br/>";
  91. }
  92. }
  93. }
  94. static public function outsuccess($data, $page = '')
  95. {
  96. static $json_clients = array('android', 'ios'); //,'ajax'
  97. if (in_array($_SESSION['client_type'], $json_clients)) {
  98. joutput_data($data);
  99. } else if ($_SESSION['client_type'] == 'wap') {
  100. if (is_array($data)) {
  101. foreach ($data as $key => $val) {
  102. TPL::output($key, $val);
  103. }
  104. }
  105. if (!empty($page)) {
  106. TPL::showpage($page);
  107. }
  108. } else if ($_SESSION['client_type'] == 'ajax') {
  109. echo "callback(";
  110. joutput_data($data);
  111. echo ")";
  112. } else {
  113. echo 'success: return data=<br/>';
  114. joutput_data($data, 'web');
  115. echo "<br/><br/>";
  116. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  117. echo "性能关键统计:<br/><br/>";
  118. performance_helper::format_log();
  119. $sqls = Log::sql_log();
  120. echo "sql count = " . count($sqls) . "<br/><br/>";
  121. foreach ($sqls as $sql) {
  122. echo "{$sql}<br/>";
  123. }
  124. }
  125. }
  126. }
  127. class mobileHomeControl extends mobileControl
  128. {
  129. public function __construct()
  130. {
  131. parent::__construct();
  132. }
  133. }
  134. /**
  135. * Class mbMemberControl
  136. */
  137. class mbMemberControl extends mobileControl
  138. {
  139. public $err_code = errcode::Success;
  140. public function __construct()
  141. {
  142. parent::__construct();
  143. if ($_SESSION['is_login'] != 1) {
  144. throw new UnloginException();
  145. }
  146. }
  147. }