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

@ -59,11 +59,13 @@ class Auth extends BaseController
{ {
public function test() public function test()
{ {
echo '11';exit; echo '11';
exit;
$order = StoreOrder::getDB()->where('order_id', 64)->find()->toArray(); $order = StoreOrder::getDB()->where('order_id', 64)->find()->toArray();
$job = new OrderPartnerJob(); $job = new OrderPartnerJob();
$res = $job->fire($order); $res = $job->fire($order);
print_r($res);exit; print_r($res);
exit;
// $data = [ // $data = [
// 'tempId' => '', // 'tempId' => '',
// 'id' => '', // 'id' => '',
@ -575,8 +577,6 @@ class Auth extends BaseController
{ {
$auth = $this->request->param('auth'); $auth = $this->request->param('auth');
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1'); $users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
if (!$users) if (!$users)
@ -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::post('logout', 'api.Auth/logout');
//用户信息 //用户信息
Route::get('user', 'api.Auth/userInfo'); Route::get('user', 'api.Auth/userInfo');
Route::get('spreadStatistics', 'api.Auth/spreadStatistics');
//绑定推荐人 //绑定推荐人
Route::post('user/spread', 'api.Auth/spread'); Route::post('user/spread', 'api.Auth/spread');

Loading…
Cancel
Save