Merge remote-tracking branch 'origin/master'

This commit is contained in:
knowpia
2022-09-19 08:38:27 +08:00
2 changed files with 27 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
namespace app\controller;
use app\model\AppUser;
use app\model\AppUserRelation;
use app\model\Payment;
use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application;
@@ -36,15 +37,16 @@ class Wechat
*/
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) {
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)
->domain(true);
$this->initWechat();
@@ -62,6 +64,7 @@ class Wechat
{
$this->initWechat();
$code = Request::get('code');
$parent_id = Request::get('parent_id');
$wechatUser = $this->app->oauth->userFromCode($code);
$callback = Request::get('callback');
@@ -74,7 +77,14 @@ class Wechat
'identity' => 0,
'openid' => $wechatUser->getId(),
]);
AppUserRelation::create([
'parent_id' => $parent_id,
'user_id' => $user->id,
]);
}
$tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)];
$token = authcode(json_encode($tokenData), 'ENCODE');
$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;
}