BaseMall.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * 公共用户可以访问的类(不需要登录)
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. /**
  8. *
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * 控制器
  13. */
  14. class BaseMall extends BaseHome
  15. {
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. if (request()->isMobile() && config('ds_config.h5_force_redirect')) {
  20. $this->isHomeUrl();
  21. }
  22. $this->template_dir = 'default/mall/' . strtolower(request()->controller()) . '/';
  23. }
  24. /**
  25. * 手机端访问自动跳转
  26. */
  27. protected function isHomeUrl()
  28. {
  29. $controller = request()->controller(); //取控制器名
  30. $action = request()->action(); //取方法名
  31. $input = request()->param(); //取参数
  32. $param = http_build_query($input); //将参数转换成链接形式
  33. if ($controller == 'Goods' && $action == 'index') { //商品详情
  34. header('Location:' . config('ds_config.h5_site_url') . '/pages/home/goodsdetail/Goodsdetail?' . $param);
  35. exit;
  36. } elseif ($controller == 'Showgroupbuy' && $action == 'index') { //抢购列表
  37. header('Location:' . config('ds_config.h5_site_url') . '/pages/home/groupbuy/GroupBuyList');
  38. exit;
  39. } elseif ($controller == 'Search' && $action == 'index') { //搜索
  40. header('Location:' . config('ds_config.h5_site_url') . '/pages/home/goodslist/Goodslist');
  41. exit;
  42. } elseif ($controller == 'Showgroupbuy' && $action == 'groupbuy_detail') { //抢购详情
  43. $goods_id = model('groupbuy')->getGroupbuyOnlineInfo(array(array('groupbuy_id', '=', $input['group_id'])))['goods_id'];
  44. header('Location:' . config('ds_config.h5_site_url') . '/pages/home/goodsdetail/Goodsdetail?goods_id=' . $goods_id);
  45. exit;
  46. } elseif ($controller == 'Store' && $action == 'goods_all') { //店铺商品列表
  47. header('Location:' . config('ds_config.h5_site_url') . '/pages/home/storegoodslist/Goodslist?' . $param);
  48. exit;
  49. } elseif ($controller == 'Category' && $action == 'goods') { //分类
  50. header('Location:' . config('ds_config.h5_site_url') . '/pages/home/goodsclass/Goodsclass');
  51. exit;
  52. } else {
  53. header('Location:' . config('ds_config.h5_site_url'));
  54. exit; //其它页面跳转到首页
  55. }
  56. }
  57. }