BookTransformer.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Transformer\Book;
  3. use App\Cache\StatisticCache;
  4. use App\Consts\BaseConst;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Redis;
  7. use Vinkla\Hashids\Facades\Hashids;
  8. class BookTransformer
  9. {
  10. // 书籍列表
  11. public function newBuildBookList($data): array
  12. {
  13. return [
  14. 'meta' => getMeta($data),
  15. 'list' => $this->newEachBookList($data),
  16. ];
  17. }
  18. private function newEachBookList($list): array
  19. {
  20. $result = [];
  21. if (empty($list)) return $result;
  22. foreach ($list as $item) {
  23. $result[] = [
  24. 'bid' => getProp($item, 'bid'),
  25. 'book_name' => getProp($item, 'book_name'),
  26. 'origin_book_name' => getProp($item, 'origin_book_name') ? getProp($item, 'origin_book_name') : getProp($item, 'book_name'),
  27. 'status' => getProp($item, 'status'),
  28. 'status_info' => getProp($item, 'status') == 1 ? '已完结' : '连载中',
  29. 'version_count' => getProp($item, 'version_count'),
  30. ];
  31. }
  32. return $result;
  33. }
  34. // 章节列表
  35. public function newBuildChapterList($data): array
  36. {
  37. return [
  38. 'meta' => getMeta($data['list']),
  39. 'header' => $data['header'],
  40. 'list' => $this->newEachChapterList($data['list']),
  41. ];
  42. }
  43. private function newEachChapterList($list): array
  44. {
  45. $result = [];
  46. if (empty($list)) return $result;
  47. foreach ($list as $item) {
  48. $result[] = [
  49. 'cid' => getProp($item, 'cid'),
  50. 'chapter_name' => getProp($item, 'chapter_name'),
  51. 'sequence' => getProp($item, 'sequence'),
  52. 'size' => getProp($item, 'size'),
  53. 'generate_status' => getProp($item, 'generate_status'),
  54. 'audio_url' => getProp($item, 'audio_url'),
  55. 'remark' => getProp($item, 'remark'),
  56. ];
  57. }
  58. return $result;
  59. }
  60. // 版本列表
  61. public function newBuildVersionList($data): array
  62. {
  63. return [
  64. 'meta' => getMeta($data),
  65. 'list' => $this->newEachVersionList($data),
  66. ];
  67. }
  68. private function newEachVersionList($list): array
  69. {
  70. $result = [];
  71. if (empty($list)) return $result;
  72. foreach ($list as $item) {
  73. $result[] = [
  74. 'version_id' => getProp($item, 'id'),
  75. 'version_name' => getProp($item, 'version_name'),
  76. 'bid' => getProp($item, 'bid'),
  77. 'book_name' => getProp($item, 'book_name'),
  78. 'created_at' => getProp($item, 'created_at'),
  79. ];
  80. }
  81. return $result;
  82. }
  83. }