BaseMall.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 公共用户可以访问的类(不需要登录)
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. /**
  8. * ============================================================================
  9. *
  10. * ============================================================================
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class BaseMall extends BaseHome {
  18. public function initialize() {
  19. parent::initialize();
  20. if(request()->isMobile() && config('ds_config.h5_force_redirect')){
  21. $this->isHomeUrl();
  22. }
  23. $this->template_dir = 'default/mall/'. strtolower(request()->controller()).'/';
  24. }
  25. /**
  26. * 手机端访问自动跳转
  27. */
  28. protected function isHomeUrl(){
  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'));exit;//其它页面跳转到首页
  54. }
  55. }
  56. }