Index.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\index\controller;
  11. use app\Controller;
  12. use app\model\goods\Goods as GoodsModel;
  13. use app\model\web\Config as ConfigModel;
  14. use app\model\shop\Shop as ShopModel;
  15. use app\model\web\DiyView as DiyViewModel;
  16. use app\shop\controller\Goods;
  17. class Index extends Controller
  18. {
  19. /**
  20. * 域名默认跳转 测试提交
  21. *
  22. * @return void
  23. */
  24. public function index()
  25. {
  26. $config_model = new ConfigModel();
  27. $domain = $config_model->getDomainJumpConfig();
  28. $jump_type = $domain[ 'data' ][ 'value' ][ 'jump_type' ];
  29. // 用户前台
  30. if ($jump_type == 1) {
  31. if ($this->isMobile()) {
  32. $domain_name_h5 = $config_model->getH5DomainName();
  33. $url = $domain_name_h5[ 'data' ][ 'value' ][ 'domain_name_h5' ];
  34. } else {
  35. // 检测插件是否存在
  36. if (addon_is_exit('pc') == 1) {
  37. $domain_name_pc = $config_model->getPcDomainName();
  38. $url = $domain_name_pc[ 'data' ][ 'value' ][ 'domain_name_pc' ];
  39. } else {
  40. $domain_name_h5 = $config_model->getH5DomainName();
  41. $url = $domain_name_h5[ 'data' ][ 'value' ][ 'domain_name_h5' ];
  42. }
  43. }
  44. $this->redirect($url);
  45. } elseif ($jump_type == 2) {
  46. // 商家管理端
  47. $this->redirect(url("shop/index/index"));
  48. } elseif ($jump_type == 3) {
  49. // 引导页
  50. return $this->center();
  51. }
  52. }
  53. /**
  54. * 端口展示中心页面
  55. */
  56. private function center()
  57. {
  58. $config_model = new ConfigModel();
  59. $domain_name_h5 = $config_model->getH5DomainName();
  60. $domain_name_pc = $config_model->getPcDomainName();
  61. $copy = $config_model->getCopyright();
  62. $this->assign("h5_url", $domain_name_h5[ 'data' ][ 'value' ][ 'domain_name_h5' ]);
  63. $this->assign("pc_url", $domain_name_pc[ 'data' ][ 'value' ][ 'domain_name_pc' ]);
  64. $this->assign("copy", $copy[ 'data' ][ 'value' ]);
  65. $this->assign("shop_url", url("shop/index/index"));
  66. return $this->fetch("index/center");
  67. }
  68. private function isMobile()
  69. {
  70. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  71. if (isset($_SERVER[ 'HTTP_X_WAP_PROFILE' ])) {
  72. return true;
  73. }
  74. // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  75. if (isset($_SERVER[ 'HTTP_VIA' ])) {
  76. // 找不到为flase,否则为true
  77. return stristr($_SERVER[ 'HTTP_VIA' ], "wap") ? true : false;
  78. }
  79. // 脑残法,判断手机发送的客户端标志,兼容性有待提高
  80. if (isset($_SERVER[ 'HTTP_USER_AGENT' ])) {
  81. $clientkeywords = array (
  82. 'nokia',
  83. 'sony',
  84. 'ericsson',
  85. 'mot',
  86. 'samsung',
  87. 'htc',
  88. 'sgh',
  89. 'lg',
  90. 'sharp',
  91. 'sie-',
  92. 'philips',
  93. 'panasonic',
  94. 'alcatel',
  95. 'lenovo',
  96. 'iphone',
  97. 'ipod',
  98. 'blackberry',
  99. 'meizu',
  100. 'android',
  101. 'netfront',
  102. 'symbian',
  103. 'ucweb',
  104. 'windowsce',
  105. 'palm',
  106. 'operamini',
  107. 'operamobi',
  108. 'openwave',
  109. 'nexusone',
  110. 'cldc',
  111. 'midp',
  112. 'wap',
  113. 'mobile'
  114. );
  115. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  116. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER[ 'HTTP_USER_AGENT' ]))) {
  117. return true;
  118. }
  119. }
  120. // 协议法,因为有可能不准确,放到最后判断
  121. if (isset($_SERVER[ 'HTTP_ACCEPT' ])) {
  122. // 如果只支持wml并且不支持html那一定是移动设备
  123. // 如果支持wml和html但是wml在html之前则是移动设备
  124. if (( strpos($_SERVER[ 'HTTP_ACCEPT' ], 'vnd.wap.wml') !== false ) && ( strpos($_SERVER[ 'HTTP_ACCEPT' ], 'text/html') === false || ( strpos($_SERVER[ 'HTTP_ACCEPT' ], 'vnd.wap.wml') < strpos($_SERVER[ 'HTTP_ACCEPT' ], 'text/html') ) )) {
  125. return true;
  126. }
  127. }
  128. return false;
  129. }
  130. /**
  131. * 店铺推广
  132. * return
  133. */
  134. public function shopUrl()
  135. {
  136. //获取商品sku_id
  137. $shop_model = new ShopModel();
  138. $res = $shop_model->qrcode(1);
  139. // dump($res);exit;
  140. return $res;
  141. }
  142. /**
  143. * 手机端预览
  144. */
  145. public function h5Preview()
  146. {
  147. $id = input('id', 0);
  148. $type = input('type', '');
  149. if ($type == 'page') {
  150. $diy_view = new DiyViewModel();
  151. $res = $diy_view->qrcode([
  152. 'site_id' => 1,
  153. 'id' => $id,
  154. 'app_type' => 'h5'
  155. ])[ 'data' ][ 'path' ][ 'h5' ];
  156. } elseif ($type == 'goods') {
  157. $goods_model = new GoodsModel();
  158. $res = $goods_model->qrcode($id, '', 1)[ 'data' ][ 'path' ][ 'h5' ];
  159. } else {
  160. $shop_model = new ShopModel();
  161. $res = $shop_model->qrcode(1)[ 'data' ][ 'path' ][ 'h5' ];
  162. }
  163. $this->assign('h5_data', $res);
  164. $this->assign('is_mobile', isMobile());
  165. return $this->fetch("index/h5_preview");
  166. }
  167. }