邀请用户记录

This commit is contained in:
2022-09-16 14:14:25 +08:00
parent 1050a87759
commit 385c0144cc
2 changed files with 27 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
namespace app\controller; namespace app\controller;
use app\model\AppUser; use app\model\AppUser;
use app\model\AppUserRelation;
use app\model\Payment; use app\model\Payment;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application; use EasyWeChat\OfficialAccount\Application;
@@ -38,13 +39,14 @@ class Wechat
{ {
$url = $GLOBALS['data']['data']['url']; $url = $GLOBALS['data']['data']['url'];
/// 来源用户, /// 来源用户,
$fromUid = $GLOBALS['data']['data']['from_uid'] ?? null; $fromUid = $GLOBALS['data']['data']['from_uid'] ?? 0;
if ($fromUid) { if ($fromUid) {
AppUser::where('id', $fromUid)->inc('share_times')->update(); AppUser::where('id', $fromUid)->inc('share_times')->update();
} }
$redirect = Route::buildUrl('wechat/code', ['callback' => $url]) $redirect = Route::buildUrl('wechat/code')
->vars(['callback' => $url, 'parent_id' => $fromUid])
->suffix(false) ->suffix(false)
->domain(true); ->domain(true);
$this->initWechat(); $this->initWechat();
@@ -62,6 +64,7 @@ class Wechat
{ {
$this->initWechat(); $this->initWechat();
$code = Request::get('code'); $code = Request::get('code');
$parent_id = Request::get('parent_id');
$wechatUser = $this->app->oauth->userFromCode($code); $wechatUser = $this->app->oauth->userFromCode($code);
$callback = Request::get('callback'); $callback = Request::get('callback');
@@ -74,7 +77,14 @@ class Wechat
'identity' => 0, 'identity' => 0,
'openid' => $wechatUser->getId(), 'openid' => $wechatUser->getId(),
]); ]);
AppUserRelation::create([
'parent_id' => $parent_id,
'user_id' => $user->id,
]);
} }
$tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)]; $tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)];
$token = authcode(json_encode($tokenData), 'ENCODE'); $token = authcode(json_encode($tokenData), 'ENCODE');
$sep = str_contains($callback, '?') ? '&' : '?'; $sep = str_contains($callback, '?') ? '&' : '?';

View File

@@ -0,0 +1,14 @@
<?php
namespace app\model;
use think\Model;
class AppUserRelation extends Model
{
protected $table = 'fa_app_user_relation';
protected $autoWriteTimestamp = true;
}