RecordService.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Services;
  3. //战绩相关服务
  4. use App\Models\RoomUser;
  5. class RecordService
  6. {
  7. public function getList($chatId, $firstName, $messageId = null, $page = 1, $limit = 4)
  8. {
  9. $list = RoomUser::where('status', 4)
  10. ->where('member_id', $chatId)
  11. ->with('room:room_id,game_name,base_score,participants,rounds')
  12. ->forPage($page, $limit)
  13. ->orderBy('updated_at', 'desc')
  14. ->get();
  15. $count = RoomUser::where('status', 4)
  16. ->where('member_id', $chatId)
  17. ->count();
  18. $test = "👤 {$firstName} 战绩记录\n\n";
  19. foreach ($list as $item) {
  20. $test .= "游戏:{$item->room->game_name} {$item->room->participants}人 {$item->room->rounds}局 房间号:{$item->room_id}\n";
  21. $test .= "底分:{$item->room->base_score} USDT\n";
  22. $test .= "得分:{$item->score}\n";
  23. $temp = floatval($item->real_score);
  24. $test .= "盈亏:{$temp} USDT\n";
  25. $temp = floatval($item->brokerage);
  26. if ($temp > 0) $test .= "抽佣:{$temp} USDT\n";
  27. $test .= "日期:{$item->updated_at}\n";
  28. $test .= "-----------------------------------------\n";
  29. }
  30. if ($page > 1) {
  31. $keyboard[] = [
  32. ['text' => "👆上一页", 'callback_data' => "recordNextPage@@" . ($page - 1)]
  33. ];
  34. }
  35. $allPage = ceil($count / $limit);
  36. if ($allPage > $page) {
  37. if ($page > 1) {
  38. $keyboard[count($keyboard) - 1][] = ['text' => "👇下一页", 'callback_data' => "recordNextPage@@" . ($page + 1)];
  39. } else {
  40. $keyboard[] = [
  41. ['text' => "👇下一页", 'callback_data' => "recordNextPage@@" . ($page + 1)]
  42. ];
  43. }
  44. }
  45. $keyboard[] = [
  46. ['text' => "返回", 'callback_data' => "message@@close"]
  47. ];
  48. return [
  49. 'chat_id' => $chatId,
  50. 'text' => $test,
  51. 'message_id' => $messageId,
  52. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
  53. ];
  54. }
  55. }