main
bruce 10 months ago
parent 334e315486
commit 4c6cb24a24
  1. 42
      app/controller/api/Auth.php
  2. 3
      app/controller/api/user/User.php

@ -48,6 +48,7 @@ use think\facade\Queue;
use crmeb\jobs\SendSmsJob; use crmeb\jobs\SendSmsJob;
use crmeb\jobs\OrderPartnerJob; use crmeb\jobs\OrderPartnerJob;
use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrder;
use think\helper\Arr;
/** /**
* Class Auth * Class Auth
@ -776,30 +777,41 @@ class Auth extends BaseController
->select() ->select()
->toArray(); ->toArray();
$spreads = userModel::getDB()->order("uid asc") $data = userModel::getDB()->order("uid asc")
->field("uid,spread_uid as sid, spread_uid2 as tid") ->field("uid,spread_uid as sid, spread_uid2 as tid")
->where("spread_uid", $userInfo->uid) ->where("spread_uid", $userInfo->uid)
->select() ->select()
->toArray(); ->toArray();
foreach ($data as &$item) {
$data = []; $item['invites'] = $this->countSpInvites($users, $item['uid']);
$res = []; $item['referrals'] = $this->countSpReferrals($users, $item['tid'], 'spread_count');
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]);
return app("json")->success($data);
} }
public function fansStatistics() public function fansStatistics()
{ {
$userInfo = $this->request->userInfo(); $userInfo = $this->request->userInfo();
$data = userModel::getDB()->order("uid desc") $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) ->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); return app("json")->success($data);
@ -824,7 +836,7 @@ class Auth extends BaseController
return $count; return $count;
} }
public function countSpReferrals($nodes, $parentId, &$visited = []) public function countSpReferrals($nodes, $parentId, $field, &$visited = [])
{ {
if (in_array($parentId, $visited)) { if (in_array($parentId, $visited)) {
return 0; return 0;
@ -834,10 +846,10 @@ class Auth extends BaseController
$visited[] = $parentId; // 将当前节点标记为已访问 $visited[] = $parentId; // 将当前节点标记为已访问
foreach ($nodes as $node) { foreach ($nodes as $node) {
if ($node['sid'] == $parentId && $node['spread_count'] > 0) { if ($node['sid'] == $parentId && $node[$field] > 0) {
$count += $node['spread_count']; $count += $node[$field];
$count += $this->countSpReferrals($nodes, $node['uid'], $visited); $count += $this->countSpReferrals($nodes, $node['uid'], $field, $visited);
} }
} }

@ -338,6 +338,9 @@ class User extends BaseController
$data['spread_uid'] = $user->spread_uid ?? ''; $data['spread_uid'] = $user->spread_uid ?? '';
$data['real_name'] = $user->real_name ?? ''; $data['real_name'] = $user->real_name ?? '';
$data['spread_uid2'] = $user->spread_uid2 ?? ''; $data['spread_uid2'] = $user->spread_uid2 ?? '';
$data['uid'] = $user->uid;
$data['nickname'] = $user->nickname;
$data['phone'] = $user->phone;
$b = ''; $b = '';
if(!empty($data['spread_uid'])){ if(!empty($data['spread_uid'])){

Loading…
Cancel
Save