|
|
@@ -60,9 +60,58 @@ class UserController
|
|
|
$info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
|
|
|
if ($info['commissionCount'] < 0)
|
|
|
$info['commissionCount'] = 0;
|
|
|
+
|
|
|
+
|
|
|
+ // 1. 添加总收益字段:该用户在user_bill表里category为brokerage_price且pm为1的总收益
|
|
|
+ $total_income = UserBill::where(['uid' => $info['uid'], 'category' => 'brokerage_price', 'pm' => 1])
|
|
|
+ ->sum('number');
|
|
|
+ $info['total_income'] = $total_income > 0 ? $total_income : 0;
|
|
|
+
|
|
|
+ // 2. 添加个人业绩字段:该用户下级推荐人(spread_uid是该用户uid)的所有用户的achievement字段值的总和
|
|
|
+ $directSubordinateUids = User::where('spread_uid', $info['uid'])->column('uid');
|
|
|
+ $personal_achievement = 0;
|
|
|
+ if (!empty($directSubordinateUids)) {
|
|
|
+ $personal_achievement = User::whereIn('uid', $directSubordinateUids)
|
|
|
+ ->sum('achievement');
|
|
|
+ }
|
|
|
+ $info['personal_achievement'] = $personal_achievement > 0 ? $personal_achievement : 0;
|
|
|
+
|
|
|
+ // 3. 添加团队业绩字段:包括下级推荐人的所有下级以及不断延续下去的团队所有用户的achievement字段值的总和
|
|
|
+ $teamUids = $this->getAllTeamMembers($info['uid']);
|
|
|
+ $team_achievement = 0;
|
|
|
+ if (!empty($teamUids)) {
|
|
|
+ $team_achievement = User::whereIn('uid', $teamUids)
|
|
|
+ ->sum('achievement');
|
|
|
+ }
|
|
|
+ $info['team_achievement'] = $team_achievement > 0 ? $team_achievement : 0;
|
|
|
+
|
|
|
return app('json')->success($info);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 递归获取所有团队成员
|
|
|
+ * @param int $uid 用户ID
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function getAllTeamMembers($uid)
|
|
|
+ {
|
|
|
+ static $teamUids = [];
|
|
|
+
|
|
|
+ // 获取直接下级
|
|
|
+ $directSubordinates = User::where('spread_uid', $uid)->column('uid');
|
|
|
+
|
|
|
+ if (!empty($directSubordinates)) {
|
|
|
+ $teamUids = array_merge($teamUids, $directSubordinates);
|
|
|
+
|
|
|
+ // 递归获取下级的下级
|
|
|
+ foreach ($directSubordinates as $subordinateUid) {
|
|
|
+ $this->getAllTeamMembers($subordinateUid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $teamUids;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用户资金统计
|
|
|
* @param Request $request
|