WalletService.php 772 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Services\Client;
  3. use App\Models\MemberUser;
  4. use App\Models\WalletTransRecord;
  5. use Illuminate\Support\Facades\Auth;
  6. class WalletService
  7. {
  8. /**
  9. * 获取钱包明细
  10. */
  11. public function getWalletRecords()
  12. {
  13. // 获取当前用户
  14. $userId = Auth::id();
  15. $user = MemberUser::findOrFail($userId);
  16. // 检查用户状态
  17. if ($user->state !== 'enable') {
  18. throw new \Exception('用户状态异常');
  19. }
  20. // 获取钱包交易记录
  21. $records = WalletTransRecord::where('wallet_id', $user->wallet->id)
  22. ->where('state', 'enable')
  23. ->orderBy('created_at', 'desc')
  24. ->paginate(10);
  25. return $records;
  26. }
  27. }