main
bruce 10 months ago
parent 684098c336
commit 334e315486
  1. 102
      app/controller/api/Auth.php
  2. 1
      route/api.php

@ -59,11 +59,13 @@ class Auth extends BaseController
{
public function test()
{
echo '11';exit;
echo '11';
exit;
$order = StoreOrder::getDB()->where('order_id', 64)->find()->toArray();
$job = new OrderPartnerJob();
$res = $job->fire($order);
print_r($res);exit;
print_r($res);
exit;
// $data = [
// 'tempId' => '',
// 'id' => '',
@ -108,7 +110,7 @@ class Auth extends BaseController
}
$user = $repository->mainUser($user);
$pid = $this->request->param('spread', 0);
$repository->bindSpread($user, intval($pid),1);
$repository->bindSpread($user, intval($pid), 1);
$tokenInfo = $repository->createToken($user);
$repository->loginAfter($user);
@ -161,10 +163,10 @@ class Auth extends BaseController
$data['extension_status'] = systemConfig('extension_status');
$brokeragePrice = User::SumBrokeragePrice();
if($brokeragePrice > 0) {
if ($brokeragePrice > 0) {
$data['point_price'] = bcdiv(systemConfig('all_award'), $brokeragePrice, 2);
}
$data['asset_price'] = bcmul($data['point_price'], $this->request->userInfo()->brokerage_price ?? 0,2);
$data['asset_price'] = bcmul($data['point_price'], $this->request->userInfo()->brokerage_price ?? 0, 2);
if (systemConfig('member_status'))
$data['member_icon'] = $this->request->userInfo()->member->brokerage_icon ?? '';
@ -237,7 +239,7 @@ class Auth extends BaseController
$pid = $this->request->param('spread', 0);
$userRepository->bindSpread($user[1], intval($pid),1);
$userRepository->bindSpread($user[1], intval($pid), 1);
$tokenInfo = $userRepository->createToken($user[1]);
$userRepository->loginAfter($user[1]);
@ -309,7 +311,7 @@ class Auth extends BaseController
if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) {
$data['spread_spid'] = $info['third_id'];
}
$userRepository->bindSpread($user[1], intval($data['spread_spid']),1);
$userRepository->bindSpread($user[1], intval($data['spread_spid']), 1);
$tokenInfo = $userRepository->createToken($user[1]);
$userRepository->loginAfter($user[1]);
@ -384,7 +386,7 @@ class Auth extends BaseController
$repository->syncBaseAuth($auth, $user);
}
$user = $repository->mainUser($user);
$repository->bindSpread($user, intval($data['spread']),1);
$repository->bindSpread($user, intval($data['spread']), 1);
$tokenInfo = $repository->createToken($user);
$repository->loginAfter($user);
@ -442,7 +444,7 @@ class Auth extends BaseController
$repository->syncBaseAuth($auth, $user);
}
$user = $repository->mainUser($user);
$repository->bindSpread($user, intval($data['spread']),1);
$repository->bindSpread($user, intval($data['spread']), 1);
$tokenInfo = $repository->createToken($user);
$repository->loginAfter($user);
@ -575,8 +577,6 @@ class Auth extends BaseController
{
$auth = $this->request->param('auth');
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
if (!$users)
@ -597,7 +597,7 @@ class Auth extends BaseController
}
if ($auth['auth']['spread'] ?? 0) {
$userRepository->bindSpread($user, (int)($auth['auth']['spread']),1);
$userRepository->bindSpread($user, (int)($auth['auth']['spread']), 1);
}
$tokenInfo = $userRepository->createToken($user);
$userRepository->loginAfter($user);
@ -732,7 +732,7 @@ class Auth extends BaseController
$user->account = $phone;
$user->save();
if ($auth['spread']) {
$userRepository->bindSpread($user, $auth['spread'],1);
$userRepository->bindSpread($user, $auth['spread'], 1);
}
}
$tokenInfo = $userRepository->createToken($user);
@ -768,4 +768,80 @@ class Auth extends BaseController
}
}
public function spreadStatistics()
{
$userInfo = $this->request->userInfo();
$users = userModel::getDB()->order("uid asc")
->field("uid,spread_uid as sid,spread_uid2 as tid,spread_count ")
->select()
->toArray();
$spreads = userModel::getDB()->order("uid asc")
->field("uid,spread_uid as sid, spread_uid2 as tid")
->where("spread_uid", $userInfo->uid)
->select()
->toArray();
$data = [];
$res = [];
foreach ($spreads as $item) {
$res['invites'] = $this->countSpInvites($users, $item['uid']);
$res['referrals'] = $this->countSpReferrals($users, $item['tid']);
array_push($data, $res);
}
return app("json")->success(['data' => $data]);
}
public function fansStatistics()
{
$userInfo = $this->request->userInfo();
$data = userModel::getDB()->order("uid desc")
->field("uid,phone,nickname,create_time,community_level,pay_count")
->where("spread_uid2", $userInfo->uid)
->select()->toArray();
return app("json")->success($data);
}
public function countSpInvites($nodes, $parentId, &$visited = [])
{
if (in_array($parentId, $visited)) {
return 0;
}
$count = 1;
$visited[] = $parentId;
foreach ($nodes as $node) {
if ($node['sid'] == $parentId) {
$count += $this->countSpInvites($nodes, $node['uid'], $visited);
}
}
return $count;
}
public function countSpReferrals($nodes, $parentId, &$visited = [])
{
if (in_array($parentId, $visited)) {
return 0;
}
$count = 0;
$visited[] = $parentId; // 将当前节点标记为已访问
foreach ($nodes as $node) {
if ($node['sid'] == $parentId && $node['spread_count'] > 0) {
$count += $node['spread_count'];
$count += $this->countSpReferrals($nodes, $node['uid'], $visited);
}
}
return $count;
}
}

@ -35,6 +35,7 @@ Route::group('api/', function () {
Route::post('logout', 'api.Auth/logout');
//用户信息
Route::get('user', 'api.Auth/userInfo');
Route::get('spreadStatistics', 'api.Auth/spreadStatistics');
//绑定推荐人
Route::post('user/spread', 'api.Auth/spread');

Loading…
Cancel
Save