$spreadId])) $spreadId = 0; $wechatInfo['nickname'] = filter_emoji($wechatInfo['nickname']); Cookie::set('is_login', 1); if (isset($wechatInfo['unionid']) && $wechatInfo['unionid'] != '' && ($uid = WechatUser::where('unionid', $wechatInfo['unionid'])->value('uid'))) { WechatUser::edit($wechatInfo, $uid, 'uid'); if (!User::be(['uid' => $uid])) { $wechatInfo = WechatUser::where('uid', $uid)->find(); User::setWechatUser($wechatInfo, $spreadId); } else { if ($login_type) $wechatInfo['login_type'] = $login_type; User::updateWechatUser($wechatInfo, $uid); } } else if ($uid = WechatUser::where(['openid' => $wechatInfo['openid']])->value('uid')) { WechatUser::edit($wechatInfo, $uid, 'uid'); if ($login_type) $wechatInfo['login_type'] = $login_type; User::updateWechatUser($wechatInfo, $uid); } else { if (isset($wechatInfo['subscribe_scene'])) unset($wechatInfo['subscribe_scene']); if (isset($wechatInfo['qr_scene'])) unset($wechatInfo['qr_scene']); if (isset($wechatInfo['qr_scene_str'])) unset($wechatInfo['qr_scene_str']); // $isLogin = request()->isLogin(); // $bind = false; // if($isLogin){ // $loginUid = request()->user(); // $isUser = $loginUid ? request()->tokenData()->type === 'user' : false; // $bind = $loginUid && $isUser && !$loginUid->openid && !User::be(['openid' => $wechatInfo['openid']]); // //微信用户绑定 h5用户 // if ($bind) { // $wechatInfo['uid'] = $loginUid->uid; // }; // } $wechatInfo = WechatUser::create($wechatInfo); // if ($isLogin && $bind) // User::where('uid', $wechatInfo['uid']) // ->limit(1)->update(['openid' => $wechatInfo['openid']]); // else User::setWechatUser($wechatInfo, $spreadId); } $uid = WechatUser::openidToUid($openid, 'openid'); // 设置推广关系 User::setSpread($spreadId, $uid); User::where('uid', $uid) ->limit(1)->update(['last_time' => time(), 'last_ip' => app('request')->ip()]); } /** * 用户访问记录 * @param $event */ public function onInitLogin($event) { list($userInfo) = $event; $request = app('request'); User::edit(['last_time' => time(), 'last_ip' => $request->ip()], $userInfo->uid, 'uid'); } /** * 检查是否能成为会员 * @param $event */ public function onUserLevelAfter($event) { list($userUid) = $event; UserLevel::setLevelComplete($userUid); } }