From 739712291788ba747b5ba700d640d3ec12791dfa Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Sun, 9 Jun 2019 13:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E8=8D=90id=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Common.php | 19 +++++++++++++++---- application/service/UserService.php | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/application/index/controller/Common.php b/application/index/controller/Common.php index 74a1dc085..5dac72779 100755 --- a/application/index/controller/Common.php +++ b/application/index/controller/Common.php @@ -41,6 +41,9 @@ class Common extends Controller // 用户信息 protected $user; + // 请求参数 + protected $params; + /** * 构造方法 * @author Devil @@ -186,10 +189,19 @@ class Common extends Controller private function CommonInit() { // 用户数据 - if(session('user') != null) + if(session('user') !== null) { $this->user = UserService::LoginUserInfo(); } + + // 公共参数 + $this->params = input(); + + // 推荐人 + if(!empty($this->params['referrer'])) + { + session('share_referrer_id', intval($this->params['referrer'])); + } } /** @@ -201,9 +213,8 @@ class Common extends Controller */ public function ViewInit() { - // 参数 - $params = input(); - $this->assign('params', $params); + // 公共参数 + $this->assign('params', $this->params); // 商店信息 $this->assign('common_customer_store_tel', MyC('common_customer_store_tel')); diff --git a/application/service/UserService.php b/application/service/UserService.php index f2a35b20d..fb526c1e7 100755 --- a/application/service/UserService.php +++ b/application/service/UserService.php @@ -1086,7 +1086,6 @@ class UserService return DataReturn('验证码错误', -11); } } - // 是否需要审核 $common_register_is_enable_audit = MyC('common_register_is_enable_audit', 0); @@ -1655,9 +1654,28 @@ class UserService return DataReturn('账号已存在', -10); } + // 推荐人id + if(isset($params['referrer'])) + { + $data['referrer'] = intval($params['referrer']); + } else { + $referrer = session('share_referrer_id'); + if($referrer !== null) + { + $data['referrer'] = intval($referrer); + } + } + + // 添加用户 $user_id = Db::name('User')->insertGetId($data); if($user_id > 0) { + // 清除推荐id + if(isset($data['referrer'])) + { + session('share_referrer_id', null); + } + // 返回前端html代码 $body_html = []; @@ -1792,7 +1810,6 @@ class UserService // 不存在添加/则更新 if(empty($temp_user)) { - $data['referrer'] = isset($params['referrer']) ? intval($params['referrer']) : 0; $data['add_time'] = time(); $user_ret = self::UserInsert($data, $params); if($user_ret['code'] == 0)