control.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * mobile父类
  4. *
  5. *
  6. */
  7. //use Shopnc\Tpl;
  8. defined('InShopNC') or exit('Access Invalid!');
  9. require_once (BASE_ROOT_PATH . "/helper/statistics_helper.php");
  10. /********************************** 前台control父类 **********************************************/
  11. class mobileControl
  12. {
  13. //客户端类型
  14. private static $stClienTypes = array('android', 'wap', 'wechat', 'ios', 'ajax', 'web');
  15. //列表默认分页数
  16. protected $page_size;
  17. protected $cur_page;
  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_size = intval(trim($_GET['page']));
  27. } else {
  28. $this->page_size = 20;
  29. }
  30. if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
  31. $this->cur_page = intval(trim($_GET['curpage']));
  32. } else {
  33. $this->cur_page = 1;
  34. }
  35. initpage($this->page_size, $this->cur_page);
  36. $this->check_app_type();
  37. statistics_helper::instance()->add_call($_GET);
  38. }
  39. public function __destruct()
  40. {
  41. }
  42. protected function android()
  43. {
  44. return $_SESSION['client_type'] == 'android';
  45. }
  46. protected function page_size()
  47. {
  48. return $this->page_size;
  49. }
  50. protected function page_no()
  51. {
  52. return $this->cur_page;
  53. }
  54. protected function pages($count)
  55. {
  56. return intval($count / $this->page_size()) + ($count % $this->page_size() == 0 ? 0 : 1);
  57. }
  58. private static function eclipse_time()
  59. {
  60. return (microtime(true) - self::$startime);
  61. }
  62. protected function check_app_type()
  63. {
  64. $client = strtolower(trim($_SERVER['HTTP_CLIENT_TYPE']));
  65. $version = trim($_SERVER['HTTP_CLIENT_VERSION']);
  66. if (empty($client)) {
  67. $client = $_POST['client_type'];
  68. } else {
  69. $_SESSION['is_app'] = true;
  70. }
  71. if (empty($client) || !in_array($client, self::$stClienTypes)) {
  72. $_SESSION['client_type'] = 'wap';
  73. } else {
  74. $_SESSION['client_type'] = $client;
  75. }
  76. if (!empty($version)) {
  77. $_SESSION['client_version'] = $version;
  78. }
  79. $version = intval($version * 100 + 0.5);
  80. if($client == 'ios')
  81. {
  82. $lastest_version = 220;
  83. if($version >= $lastest_version) {
  84. $_SESSION['is_lasted'] = true;
  85. } else {
  86. $_SESSION['is_lasted'] = false;
  87. }
  88. }
  89. elseif($client == 'android')
  90. {
  91. $lastest_version = 1400;
  92. if($version >= $lastest_version) {
  93. $_SESSION['is_lasted'] = true;
  94. } else {
  95. $_SESSION['is_lasted'] = false;
  96. }
  97. }
  98. return true;
  99. }
  100. static public function outerr($code, $msg = '', $page = '',$type = NULL)
  101. {
  102. static $json_clients = array('android', 'ios');
  103. if(!empty($type)) {
  104. $show_type = $type;
  105. } else {
  106. $show_type = $_SESSION['client_type'];
  107. }
  108. if (in_array($show_type, $json_clients))
  109. {
  110. joutput_error($code, $msg);
  111. }
  112. else if ($show_type == 'wap')
  113. {
  114. Tpl::clear();
  115. Tpl::output("error", $msg);
  116. if (!empty($page)) {
  117. Tpl::showpage($page);
  118. }
  119. }
  120. else if ($show_type == 'ajax')
  121. {
  122. $callback = $_GET['callback'];
  123. if(!isset($callback) || empty($callback)) {
  124. joutput_error($code, $msg);
  125. } else {
  126. echo "{$callback}(";
  127. joutput_error($code, $msg);
  128. echo ");";
  129. }
  130. }
  131. else
  132. {
  133. if(empty($msg)) {
  134. $msg = errcode::msg($code);
  135. }
  136. $start = microtime(true);
  137. echo joutput_error($code, $msg, 'web') . "<br/>";
  138. perfor_period("joutput",$start,"web");
  139. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  140. echo "性能关键统计:<br/><br/>";
  141. performance_helper::format_log();
  142. $sqls = Log::sql_log();
  143. echo "sql count = " . count($sqls) . "<br/><br/>";
  144. foreach ($sqls as $sql) {
  145. echo "{$sql}<br/>";
  146. }
  147. }
  148. return true;
  149. }
  150. static public function outsuccess($data, $page = '',$type = NULL)
  151. {
  152. static $json_clients = array('android', 'ios');
  153. if(!empty($type)) {
  154. $show_type = $type;
  155. } else {
  156. $show_type = $_SESSION['client_type'];
  157. }
  158. if (in_array($show_type, $json_clients))
  159. {
  160. joutput_data($data);
  161. }
  162. else if ($show_type == 'wap')
  163. {
  164. Tpl::clear();
  165. if (is_array($data)) {
  166. foreach ($data as $key => $val) {
  167. Tpl::output($key, $val);
  168. }
  169. }
  170. if (!empty($page)) {
  171. Tpl::showpage($page);
  172. }
  173. }
  174. else if ($show_type == 'ajax')
  175. {
  176. $callback = $_GET['callback'];
  177. if(!isset($callback) || empty($callback)) {
  178. joutput_data($data);
  179. } else {
  180. echo "{$callback}(";
  181. joutput_data($data);
  182. echo ");";
  183. }
  184. }
  185. else
  186. {
  187. echo 'success: return data=<br/>';
  188. $start = microtime(true);
  189. joutput_data($data, 'web');
  190. perfor_period("joutput",$start,"web");
  191. echo "<br/><br/>";
  192. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  193. echo "性能关键统计:<br/><br/>";
  194. performance_helper::format_log();
  195. $sqls = Log::sql_log();
  196. echo "sql count = " . count($sqls) . "<br/><br/>";
  197. foreach ($sqls as $sql) {
  198. echo "{$sql}<br/>";
  199. }
  200. }
  201. return true;
  202. }
  203. public function separate_page($items,&$pages)
  204. {
  205. $arr_items = array_chunk($items,$this->page_size());
  206. $pages = count($arr_items);
  207. $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
  208. return ($arr_items[$page_no - 1]);
  209. }
  210. }
  211. class mobileHomeControl extends mobileControl
  212. {
  213. public function __construct()
  214. {
  215. parent::__construct();
  216. }
  217. }
  218. /**
  219. * Class mbMemberControl
  220. */
  221. class mbMemberControl extends mobileControl
  222. {
  223. public $err_code = errcode::Success;
  224. public function __construct()
  225. {
  226. parent::__construct();
  227. if ($_SESSION['is_login'] != 1) {
  228. throw new UnloginException();
  229. }
  230. }
  231. }
  232. function bonus_version()
  233. {
  234. return "v=2017061302";
  235. }
  236. function shop_version()
  237. {
  238. return "v=2017061302";
  239. }