邀请用户记录
This commit is contained in:
@@ -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;
|
||||||
@@ -36,15 +37,16 @@ class Wechat
|
|||||||
*/
|
*/
|
||||||
public function url(): Json
|
public function url(): Json
|
||||||
{
|
{
|
||||||
$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, '?') ? '&' : '?';
|
||||||
|
|||||||
14
app/model/AppUserRelation.php
Normal file
14
app/model/AppUserRelation.php
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user