control.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. return $this->page;
  35. }
  36. protected function page_no() {
  37. return $this->cur_page;
  38. }
  39. private static function eclipse_time() {
  40. return (microtime(true) - self::$startime);
  41. }
  42. protected function check_app_type()
  43. {
  44. $client = strtolower(trim($_SERVER['HTTP_CLIENT_TYPE']));
  45. $version = trim($_SERVER['HTTP_CLIENT_VERSION']);
  46. if(empty($client)) {
  47. $client = $_POST['client_type'];
  48. }
  49. if (empty($client)|| !in_array($client, $this->client_type_array)) {
  50. $_SESSION['client_type'] = 'wap';
  51. } else {
  52. $_SESSION['client_type'] = $client;
  53. }
  54. if(!empty($version)) {
  55. $_SESSION['client_version'] = $version;
  56. }
  57. return true;
  58. }
  59. static public function outerr($code,$msg = '',$page = '')
  60. {
  61. static $json_clients = array('android', 'ios','ajax');
  62. if(in_array($_SESSION['client_type'],$json_clients)) {
  63. joutput_error($code,$msg);
  64. }
  65. else if($_SESSION['client_type'] == 'wap')
  66. {
  67. Tpl::output("error",$msg);
  68. if(!empty($page)) {
  69. TPL::showpage($page);
  70. }
  71. }
  72. else {
  73. if(empty($msg)) {
  74. $msg = errcode::msg($code);
  75. }
  76. echo joutput_error($code,$msg,'web') . "<br/>";
  77. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  78. echo "性能关键统计:<br/><br/>";
  79. performance_helper::format_log();
  80. $sqls = Log::sql_log();
  81. echo "sql count = " . count($sqls) . "<br/><br/>";
  82. foreach($sqls as $sql) {
  83. echo "{$sql}<br/>";
  84. }
  85. }
  86. }
  87. static public function outsuccess($data,$page = '')
  88. {
  89. static $json_clients = array('android', 'ios'); //,'ajax'
  90. if(in_array($_SESSION['client_type'],$json_clients)) {
  91. joutput_data($data);
  92. }
  93. else if($_SESSION['client_type'] == 'wap')
  94. {
  95. if(is_array($data)) {
  96. foreach($data as $key => $val) {
  97. TPL::output($key,$val);
  98. }
  99. }
  100. if(!empty($page)) {
  101. TPL::showpage($page);
  102. }
  103. }
  104. else if($_SESSION['client_type'] == 'ajax') {
  105. echo "callback(";
  106. joutput_data($data);
  107. echo ")";
  108. }
  109. else
  110. {
  111. echo 'success: return data=<br/>';
  112. joutput_data($data,'web');
  113. echo "<br/><br/>";
  114. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  115. echo "性能关键统计:<br/><br/>";
  116. performance_helper::format_log();
  117. $sqls = Log::sql_log();
  118. echo "sql count = " . count($sqls) . "<br/><br/>";
  119. foreach($sqls as $sql) {
  120. echo "{$sql}<br/>";
  121. }
  122. }
  123. }
  124. }
  125. class mobileHomeControl extends mobileControl
  126. {
  127. public function __construct()
  128. {
  129. parent::__construct();
  130. }
  131. }
  132. /**
  133. * Class mbMemberControl
  134. */
  135. class mbMemberControl extends mobileControl
  136. {
  137. public $err_code = errcode::Success;
  138. public function __construct()
  139. {
  140. parent::__construct();
  141. if($_SESSION['is_login'] != 1) {
  142. throw new UnloginException();
  143. }
  144. }
  145. }