control.php 7.5 KB

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