account->logs() ->where('type', 'score') ->paginate(); $data = [ 'score' => $user->account->score, 'logs' => new UserAccountLogCollection($logs) ]; return $this->success($data); } /** * Notes:现金账户 * * @Author: 玄尘 * @Date: 2022/8/19 8:37 */ public function balance(): \Illuminate\Http\JsonResponse { $user = Api::user(); $logs = $user->account->logs()->where('type', 'balance')->paginate(); $yesterday = $user->account->logs() ->whereDate('created_at', now()->subDay()->toDateTime()) ->where('type', 'balance') ->where('amount', '>', 0) ->sum('amount') ?? 0; $withdraw = $user->withdraws()->sum('amount') ?? 0; $data = [ 'account' => [ 'balance' => floatval($user->account->balance), 'yesterday' => floatval($yesterday), 'withdraw' => floatval($withdraw), ], 'logs' => new UserAccountLogCollection($logs) ]; return $this->success($data); } }