control.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. require_once (BASE_ROOT_PATH . "/helper/session_helper.php");
  11. require_once (BASE_ROOT_PATH . "/helper/bonus_helper.php");
  12. /********************************** 前台control父类 **********************************************/
  13. class mobileControl
  14. {
  15. //客户端类型
  16. private static $stClienTypes = ['android', 'wap', 'wechat', 'ios', 'ajax', 'web','mini'];
  17. //列表默认分页数
  18. protected $page_size;
  19. protected $cur_page;
  20. //任务开始时间
  21. private static $startime = 0;
  22. public function __construct()
  23. {
  24. self::$startime = microtime(true);
  25. Language::read('mobile');
  26. //分页数处理
  27. if (is_numeric($_GET['page']) && intval(trim($_GET['page'])) > 0) {
  28. $this->page_size = intval(trim($_GET['page']));
  29. } else {
  30. $this->page_size = 20;
  31. }
  32. if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
  33. $this->cur_page = intval(trim($_GET['curpage']));
  34. } else {
  35. $this->cur_page = 1;
  36. }
  37. $this->initpage($this->page_size, $this->cur_page);
  38. $this->check_app_type();
  39. $param = $_GET;
  40. $param['client_type'] = $_SESSION['client_type'];
  41. $this->set_relay();
  42. statistics_helper::instance()->add_call($param);
  43. }
  44. private function set_relay()
  45. {
  46. if(isset($_GET['relay_id'])) {
  47. session_helper::set_relay($_GET['relay_id']);
  48. }
  49. elseif (isset($_COOKIE['relay_id'])) {
  50. session_helper::set_relay($_COOKIE['relay_id']);
  51. }
  52. }
  53. protected function initpage($page_size,$cur_page)
  54. {
  55. pagecmd('seteachnum', $page_size);
  56. pagecmd('setnowpage', $cur_page);
  57. }
  58. protected function price_calcer()
  59. {
  60. if(session_helper::logined()) {
  61. return new bonus\account(session_helper::memberid(),true);
  62. } else {
  63. return new bonus\normal_calc();
  64. }
  65. }
  66. public function __destruct()
  67. {
  68. }
  69. protected function android()
  70. {
  71. return $_SESSION['client_type'] == 'android';
  72. }
  73. protected function page_size()
  74. {
  75. return $this->page_size;
  76. }
  77. protected function page_no()
  78. {
  79. return $this->cur_page;
  80. }
  81. protected function pages($count)
  82. {
  83. return intval($count / $this->page_size()) + ($count % $this->page_size() == 0 ? 0 : 1);
  84. }
  85. /**
  86. * @throws UnloginException
  87. */
  88. protected function need_login()
  89. {
  90. if ($_SESSION['is_login'] != 1) {
  91. throw new UnloginException();
  92. }
  93. }
  94. private static function eclipse_time()
  95. {
  96. return (microtime(true) - self::$startime);
  97. }
  98. protected function check_app_type()
  99. {
  100. $client = strtolower(trim($_SERVER['HTTP_CLIENT_TYPE']));
  101. $version = trim($_SERVER['HTTP_CLIENT_VERSION']);
  102. if (empty($client)) {
  103. $client = $_POST['client_type'];
  104. } else {
  105. $_SESSION['is_app'] = true;
  106. }
  107. if (empty($client) || !in_array($client, self::$stClienTypes)) {
  108. $_SESSION['client_type'] = 'wap';
  109. } else {
  110. $_SESSION['client_type'] = $client;
  111. }
  112. if (!empty($version)) {
  113. $_SESSION['client_version'] = $version;
  114. }
  115. $version = intval($version * 100 + 0.5);
  116. if($client == 'ios')
  117. {
  118. $cur_ver = $GLOBALS['setting_config']['mobile_ios_version'];
  119. $lastest_version = intval($cur_ver * 100 + 0.5);
  120. if($version >= $lastest_version) {
  121. $_SESSION['is_lasted'] = true;
  122. } else {
  123. $_SESSION['is_lasted'] = false;
  124. }
  125. }
  126. elseif($client == 'android')
  127. {
  128. $cur_ver = $GLOBALS['setting_config']['mobile_apk_version'];
  129. $lastest_version = intval($cur_ver * 100 + 0.5);
  130. if($version >= $lastest_version) {
  131. $_SESSION['is_lasted'] = true;
  132. } else {
  133. $_SESSION['is_lasted'] = false;
  134. }
  135. }
  136. return true;
  137. }
  138. static public function outerr($code, $msg = '', $page = '',$type = NULL)
  139. {
  140. static $json_clients = ['android', 'ios','mini'];
  141. if(!empty($type)) {
  142. $show_type = $type;
  143. } else {
  144. $show_type = $_SESSION['client_type'];
  145. }
  146. if (in_array($show_type, $json_clients))
  147. {
  148. joutput_error($code, $msg);
  149. }
  150. else if ($show_type == 'wap')
  151. {
  152. Tpl::clear();
  153. Tpl::output("error", $msg);
  154. if (!empty($page)) {
  155. Tpl::showpage($page);
  156. }
  157. }
  158. else if ($show_type == 'ajax')
  159. {
  160. $callback = $_GET['callback'];
  161. if(!isset($callback) || empty($callback)) {
  162. joutput_error($code, $msg);
  163. } else {
  164. echo "{$callback}(";
  165. joutput_error($code, $msg);
  166. echo ");";
  167. }
  168. }
  169. else
  170. {
  171. if(empty($msg)) {
  172. $msg = errcode::msg($code);
  173. }
  174. $start = microtime(true);
  175. echo joutput_error($code, $msg, 'web') . "<br/>";
  176. perfor_period("joutput",$start,"web");
  177. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  178. echo "性能关键统计:<br/><br/>";
  179. performance_helper::format_log();
  180. $sqls = Log::sql_log();
  181. echo "sql count = " . count($sqls) . "<br/><br/>";
  182. foreach ($sqls as $sql) {
  183. echo "{$sql}<br/>";
  184. }
  185. }
  186. return true;
  187. }
  188. static public function outsuccess($data, $page = '',$type = NULL)
  189. {
  190. static $json_clients = ['android', 'ios','mini'];
  191. if(!empty($type)) {
  192. $show_type = $type;
  193. } else {
  194. $show_type = $_SESSION['client_type'];
  195. }
  196. if (in_array($show_type, $json_clients))
  197. {
  198. joutput_data($data);
  199. }
  200. else if ($show_type == 'wap')
  201. {
  202. Tpl::clear();
  203. if (is_array($data)) {
  204. foreach ($data as $key => $val) {
  205. Tpl::output($key, $val);
  206. }
  207. }
  208. if (!empty($page)) {
  209. Tpl::showpage($page);
  210. }
  211. }
  212. else if ($show_type == 'ajax')
  213. {
  214. $callback = $_GET['callback'];
  215. if(!isset($callback) || empty($callback)) {
  216. joutput_data($data);
  217. } else {
  218. echo "{$callback}(";
  219. joutput_data($data);
  220. echo ");";
  221. }
  222. }
  223. else
  224. {
  225. echo 'success: return data=<br/>';
  226. $start = microtime(true);
  227. joutput_data($data, 'web');
  228. perfor_period("joutput",$start,"web");
  229. echo "<br/><br/>";
  230. echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
  231. echo "性能关键统计:<br/><br/>";
  232. performance_helper::format_log();
  233. $sqls = Log::sql_log();
  234. echo "sql count = " . count($sqls) . "<br/><br/>";
  235. foreach ($sqls as $sql) {
  236. echo "{$sql}<br/>";
  237. }
  238. }
  239. return true;
  240. }
  241. public function separate_page($items,&$pages)
  242. {
  243. $arr_items = array_chunk($items,$this->page_size());
  244. $pages = count($arr_items);
  245. $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
  246. return ($arr_items[$page_no - 1]);
  247. }
  248. }
  249. class mobileHomeControl extends mobileControl
  250. {
  251. public function __construct()
  252. {
  253. parent::__construct();
  254. }
  255. }
  256. class mbMemberControl extends mobileControl
  257. {
  258. public $err_code = errcode::Success;
  259. public function __construct()
  260. {
  261. parent::__construct();
  262. if (!session_helper::logined()) {
  263. throw new UnloginException();
  264. }
  265. }
  266. }
  267. function bonus_version()
  268. {
  269. return "v=2018083005";
  270. }
  271. function shop_version()
  272. {
  273. return "v=2018083005";
  274. }