diff --git a/app/controller/api/UserController.php b/app/controller/api/UserController.php index 29060cf..dfd027b 100644 --- a/app/controller/api/UserController.php +++ b/app/controller/api/UserController.php @@ -15,6 +15,8 @@ use App\dao\UserDao; use app\dao\UserPhoneLogDao; use app\dao\UserRewardDao; use app\model\Recommend; +use app\model\Reward; +use app\model\UserPhone; use app\model\UserReward; use hg\apidoc\annotation as Apidoc; @@ -193,7 +195,30 @@ class UserController { $today = date('Y-m-d'); $user_id = $request->data['id']; - $activeUsers = ActiveUsers::where('user_id', $user_id)->where('created_at', '>=', $today . " 00:00:00")->where('created_at', '<=', $today . " 23:59:59")->get(); - return ApiResponseApp::success($activeUsers); + + // 获取所有用户 + $Users = User::where('f_id', $user_id)->orWhere('ff_id', $user_id)->pluck('id'); + + // 获取这些用户的手机号 + $phones = UserPhone::whereIn('user_id', $Users)->pluck('phone'); + + // 获取奖励并按手机号分组,计算每个手机号的 money 总和 + $Reward = UserReward::where('user_id', $user_id) + ->where('created_at', '>=', $today . " 00:00:00") + ->where('created_at', '<=', $today . " 23:59:59") + ->whereIn('phone', $phones) + ->get() + ->groupBy('phone') // 按 phone 分组 + ->map(function ($group) { + return $group->sum('money'); // 求和每个分组中的 money 字段 + }); + + // 格式化结果,返回每个 phone 和对应的 income + $result = $Reward->map(function ($income, $phone) { + return ['phone' => $phone, 'income' => $income]; + })->values()->toArray(); + + // 返回响应 + return ApiResponseApp::success($result); } } diff --git a/app/dao/UserRewardDao.php b/app/dao/UserRewardDao.php index 0d0b1ef..22db7f4 100644 --- a/app/dao/UserRewardDao.php +++ b/app/dao/UserRewardDao.php @@ -21,9 +21,9 @@ class UserRewardDao /** * 挂机获得的奖励 */ - public static function Onhookincome($userid, $money) + public static function Onhookincome($userid, $money,$phone) { - self::f_bounty($userid, 6, $money, '挂机收益'); + self::f_bounty($userid, 6, $money, '挂机收益',$phone); } /** * 加粉赏金奖励 @@ -80,11 +80,33 @@ class UserRewardDao $user->save(); $UserReward->save(); } + /** + * 转账函数 记录手机号 活跃列表的佣金 + */ + public static function base_phone($userid, $status, $money, $memo,$phone) + { + $UserReward = new UserReward(); + $user = User::find($userid); + $UserReward->user_id = $user->id; + $UserReward->username = $user->username; + $UserReward->uu_id = $user->invite_code; + $UserReward->status = $status; + $UserReward->money = $money; + $UserReward->before = $user->money; + $UserReward->after = $user->money + $money; + $UserReward->memo = $memo; + $UserReward->memo = $memo; + $UserReward->createtime2 = date('Y-m-d H:i:s'); + $UserReward->phone = $phone; + $user->money = $UserReward->after; + $user->save(); + $UserReward->save(); + } /** * 父级 父父级分红 * 函数 */ - public static function f_bounty($userid, $status, $money, $memo) + public static function f_bounty($userid, $status, $money, $memo,$phone) { //父分红 $f_dividend = floor($money * 0.2); @@ -94,10 +116,10 @@ class UserRewardDao //分红大于0才会记录 这里还有类型 有些类型需要分红吗 if ($user->f_id != 0&&$money>0&&$f_dividend>0&&$ff_dividend>0) { $f = User::find($user->f_id); - self::base($f->id, 5, $f_dividend, '加粉赏金'); + self::base_phone($f->id, 5, $f_dividend, '加粉赏金',$phone); if ($user->ff_id != 0) { $ff = User::find($user->ff_id); - self::base($ff->id, 5, $ff_dividend, '加粉赏金'); + self::base_phone($ff->id, 5, $ff_dividend, '加粉赏金',$phone); } } self::base($userid, $status, $money, $memo); diff --git a/app/model/Reward.php b/app/model/Reward.php deleted file mode 100644 index 972c53d..0000000 --- a/app/model/Reward.php +++ /dev/null @@ -1,32 +0,0 @@ -time = $remainingTime; // 保存用户收益到 UserReward 表 - UserRewardDao::Onhookincome($value->user_id, $score); + UserRewardDao::Onhookincome($value->user_id, $score,$value->phone); } // 计算新的在线时长