From 4c6cb24a24628f4c9a7f9e13266e8e7de2f8ef35 Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Tue, 6 Feb 2024 19:25:54 +0800 Subject: [PATCH] update --- app/controller/api/Auth.php | 42 ++++++++++++++++++++------------ app/controller/api/user/User.php | 3 +++ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 2b29547..c30e8e2 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -48,6 +48,7 @@ use think\facade\Queue; use crmeb\jobs\SendSmsJob; use crmeb\jobs\OrderPartnerJob; use app\common\model\store\order\StoreOrder; +use think\helper\Arr; /** * Class Auth @@ -776,30 +777,41 @@ class Auth extends BaseController ->select() ->toArray(); - $spreads = userModel::getDB()->order("uid asc") + $data = 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); + foreach ($data as &$item) { + $item['invites'] = $this->countSpInvites($users, $item['uid']); + $item['referrals'] = $this->countSpReferrals($users, $item['tid'], 'spread_count'); } - return app("json")->success(['data' => $data]); + + return app("json")->success($data); } public function fansStatistics() { $userInfo = $this->request->userInfo(); $data = userModel::getDB()->order("uid desc") - ->field("uid,phone,nickname,create_time,community_level,pay_count") + ->field("uid,phone,nickname,create_time,community_level,pay_count,spread_uid as sid,spread_uid2 as tid") ->where("spread_uid2", $userInfo->uid) - ->select()->toArray(); + ->select() + ->toArray(); + + $users = userModel::getDB()->order("uid asc") + ->field("uid,spread_uid as sid,spread_uid2 as tid,spread_count,spread_pay_price") + ->select() + ->toArray(); + + $level = Arr::pluck(config('partner.community_level') ?? [], 'level_name', 'id'); + foreach ($data as &$item) { + $item['community_level'] = $level[$item['community_level']] ?? ''; + $item['invites'] = $this->countSpInvites($users, $item['uid']); + $item['referrals'] = $this->countSpReferrals($users, $item['tid'], 'spread_count'); + $item['amount'] = $this->countSpReferrals($users, $item['tid'], 'spread_pay_price'); + } return app("json")->success($data); @@ -824,7 +836,7 @@ class Auth extends BaseController return $count; } - public function countSpReferrals($nodes, $parentId, &$visited = []) + public function countSpReferrals($nodes, $parentId, $field, &$visited = []) { if (in_array($parentId, $visited)) { return 0; @@ -834,10 +846,10 @@ class Auth extends BaseController $visited[] = $parentId; // 将当前节点标记为已访问 foreach ($nodes as $node) { - if ($node['sid'] == $parentId && $node['spread_count'] > 0) { - $count += $node['spread_count']; + if ($node['sid'] == $parentId && $node[$field] > 0) { + $count += $node[$field]; - $count += $this->countSpReferrals($nodes, $node['uid'], $visited); + $count += $this->countSpReferrals($nodes, $node['uid'], $field, $visited); } } diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index f523516..c1589ef 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -338,6 +338,9 @@ class User extends BaseController $data['spread_uid'] = $user->spread_uid ?? ''; $data['real_name'] = $user->real_name ?? ''; $data['spread_uid2'] = $user->spread_uid2 ?? ''; + $data['uid'] = $user->uid; + $data['nickname'] = $user->nickname; + $data['phone'] = $user->phone; $b = ''; if(!empty($data['spread_uid'])){