Mobile.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * 官网的公共控制器类
  4. *
  5. */
  6. namespace app\mobile\controller;
  7. use app\common\controller\Base;
  8. use think\Db;
  9. use think\Config;
  10. class Mobile extends Base
  11. {
  12. // 不验证权限的action
  13. protected $noCheckAuth = [];
  14. protected $current_node;
  15. // 登录返回上一页,需跳过的页面url
  16. protected $noPreviousPage = [];
  17. // 登录返回上一页,默认url
  18. protected $defaultPage = MOBILE_SITE_DOMAIN;
  19. /**
  20. * 初始化操作
  21. */
  22. protected function _initialize()
  23. {
  24. $this->noPreviousPage = [MOBILE_SITE_DOMAIN.'/login/',MOBILE_SITE_DOMAIN.'/register/',MOBILE_SITE_DOMAIN.'/forgotpwd.html',MOBILE_SITE_DOMAIN.'/forgotpwd/check.html',MOBILE_SITE_DOMAIN.'/forgotpwd/resetpwd.html',MOBILE_SITE_DOMAIN.'/csc/resetpwdresult.html',MOBILE_SITE_DOMAIN.'/csc/resetpwdresult/suc/1.html'];
  25. // 麻花网络app下载链接
  26. $link = model('Setting')->cache(Config::get('QUERY_RESULT_CACHE_TIME'))->where('name','APP_LINK')->value('value');
  27. // 用户昵称
  28. $userinfo = '';
  29. if (session('front_userid')){
  30. $userinfo = model('members')->field('nickname,avatar,username,id,amount')->where('id',session('front_userid'))->find();
  31. }
  32. $this->assign('link',$link);
  33. $this->assign('userinfo',$userinfo);
  34. }
  35. /**
  36. * 判断用户是否登录,未登录跳转登录页面
  37. */
  38. protected function _isLogin(){
  39. if (!session('?front_userid')){
  40. $this->redirect('Mobile/member/login');
  41. exit;
  42. }
  43. }
  44. /**
  45. * 返回json数据到H5
  46. * @param array $data
  47. * @param int $code
  48. * @param string $msg
  49. * @return \think\response\Json
  50. */
  51. public function json($data = [], $code = 0, $msg = '')
  52. {
  53. return json(['data' => $data, 'code' => $code, 'msg' => $msg]);
  54. }
  55. /**
  56. * 返回 json
  57. * @access protected
  58. * @param mixed $data 要返回的数据
  59. * @param int $code 返回的 code
  60. * @param mixed $msg 提示信息
  61. * @return void
  62. * @throws HttpResponseException
  63. */
  64. public function jsonResult($data, $code = 0, $msg = '')
  65. {
  66. $this->result($data, $code, $msg, 'json');
  67. }
  68. /**
  69. * 获取上一页的URL (有过滤)
  70. * @param bool $toUrl url是否转完整地址
  71. * @return string
  72. */
  73. public function getPrePageUrl(){
  74. $pre_page = session('HTTP_REFERER_URL');
  75. if (!$pre_page || session('has404')){
  76. session('has404',null);
  77. return $this->defaultPage;
  78. }
  79. return $pre_page;
  80. }
  81. protected function setPreUrl(){
  82. if (session('front_userid')) return false;
  83. $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
  84. if (!empty($url) && !in_array($url,$this->noPreviousPage)) {
  85. session('HTTP_REFERER_URL' , $url);
  86. return true;
  87. }
  88. return false;
  89. }
  90. /**
  91. * 验证手机号是否正确
  92. *
  93. * @author honfei
  94. * @param number $mobile
  95. */
  96. function isMobile($mobile) {
  97. if (!is_numeric($mobile)) {
  98. return false;
  99. }
  100. return preg_match('#^1[\d]{10}$#', $mobile) ? true : false;
  101. }
  102. /**
  103. * 正则表达式验证email格式
  104. *
  105. * @param string $str 所要验证的邮箱地址
  106. * @return boolean
  107. */
  108. function isEmail($str) {
  109. if (!$str) {
  110. return false;
  111. }
  112. return preg_match('/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i', $str) ? true : false;
  113. }
  114. /**
  115. * 页面404输出
  116. */
  117. public function _abort404(){
  118. session('has404',true);
  119. abort(404);
  120. }
  121. /**
  122. * 更新用户信息缓存
  123. * @param $arr ['字段名'=> 值]
  124. */
  125. /* public function _updateUserInfo($arr = []){
  126. if (empty($arr)) return false;
  127. $info = session('front_info');
  128. foreach ($arr as $filed=>$value){
  129. $info[$filed] = $value;
  130. }
  131. session('front_info',$info);
  132. return true;
  133. }*/
  134. }