BookTransformer.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace App\Transformer\Book;
  3. class BookTransformer
  4. {
  5. // 书籍列表
  6. public function newBuildBookList($data): array
  7. {
  8. return [
  9. 'meta' => getMeta($data),
  10. 'list' => $this->newEachBookList($data),
  11. ];
  12. }
  13. private function newEachBookList($list): array
  14. {
  15. $result = [];
  16. if (empty($list)) return $result;
  17. foreach ($list as $item) {
  18. $result[] = [
  19. 'bid' => getProp($item, 'bid'),
  20. 'book_name' => getProp($item, 'book_name'),
  21. 'origin_book_name' => getProp($item, 'origin_book_name') ? getProp($item, 'origin_book_name') : getProp($item, 'book_name'),
  22. 'status' => getProp($item, 'status'),
  23. 'status_info' => getProp($item, 'status') == 1 ? '已完结' : '连载中',
  24. 'version_count' => getProp($item, 'version_count'),
  25. ];
  26. }
  27. return $result;
  28. }
  29. // 章节列表
  30. public function newBuildChapterList($data): array
  31. {
  32. return [
  33. 'meta' => getMeta($data['list']),
  34. 'header' => $data['header'],
  35. 'list' => $this->newEachChapterList($data['list']),
  36. ];
  37. }
  38. private function newEachChapterList($list): array
  39. {
  40. $result = [];
  41. if (empty($list)) return $result;
  42. foreach ($list as $item) {
  43. $result[] = [
  44. 'cid' => getProp($item, 'cid'),
  45. 'chapter_name' => getProp($item, 'chapter_name'),
  46. 'sequence' => getProp($item, 'sequence'),
  47. 'size' => getProp($item, 'size'),
  48. 'generate_status' => getProp($item, 'generate_status'),
  49. 'audio_url' => getProp($item, 'audio_url'),
  50. 'remark' => getProp($item, 'remark'),
  51. ];
  52. }
  53. return $result;
  54. }
  55. // 版本列表
  56. public function newBuildVersionList($data): array
  57. {
  58. return [
  59. 'meta' => getMeta($data),
  60. 'list' => $this->newEachVersionList($data),
  61. ];
  62. }
  63. private function newEachVersionList($list): array
  64. {
  65. $result = [];
  66. if (empty($list)) return $result;
  67. foreach ($list as $item) {
  68. $result[] = [
  69. 'version_id' => getProp($item, 'id'),
  70. 'version_name' => getProp($item, 'version_name'),
  71. 'bid' => getProp($item, 'bid'),
  72. 'book_name' => getProp($item, 'book_name'),
  73. 'created_at' => getProp($item, 'created_at'),
  74. ];
  75. }
  76. return $result;
  77. }
  78. // 合成任务列表
  79. public function newBuildTaskList($data): array
  80. {
  81. return [
  82. 'meta' => getMeta($data),
  83. 'list' => $this->newEachTaskList($data),
  84. ];
  85. }
  86. private function newEachTaskList($list): array
  87. {
  88. $result = [];
  89. if (empty($list)) return $result;
  90. foreach ($list as $item) {
  91. $result[] = [
  92. 'task_id' => getProp($item, 'id'),
  93. 'task_name' => getProp($item, 'task_name'),
  94. 'generate_status' => getProp($item, 'generate_status'),
  95. 'bid' => getProp($item, 'bid'),
  96. 'version_id' => getProp($item, 'version_id'),
  97. 'cid' => getProp($item, 'cid'),
  98. 'created_at' => getProp($item, 'created_at'),
  99. ];
  100. }
  101. return $result;
  102. }
  103. // 音效列表
  104. public function newBuildAudioEffectList($data): array
  105. {
  106. return [
  107. 'meta' => getMeta($data),
  108. 'list' => $this->newEachAudioEffectList($data),
  109. ];
  110. }
  111. private function newEachAudioEffectList($list): array
  112. {
  113. $result = [];
  114. if (empty($list)) return $result;
  115. foreach ($list as $item) {
  116. $result[] = [
  117. 'audio_effect_id' => getProp($item, 'id'),
  118. 'audio_effect_name' => getProp($item, 'audio_effect_name'),
  119. 'audio_effect_url' => getProp($item, 'audio_effect_url'),
  120. 'playtime_seconds' => getProp($item, 'playtime_seconds'),
  121. 'created_at' => transDate(getProp($item, 'created_at')),
  122. ];
  123. }
  124. return $result;
  125. }
  126. // bgm列表
  127. public function newBuildBgmList($data): array
  128. {
  129. return [
  130. 'meta' => getMeta($data),
  131. 'list' => $this->newEachBgmList($data),
  132. ];
  133. }
  134. private function newEachBgmList($list): array
  135. {
  136. $result = [];
  137. if (empty($list)) return $result;
  138. foreach ($list as $item) {
  139. $result[] = [
  140. 'bgm_id' => getProp($item, 'id'),
  141. 'bgm_name' => getProp($item, 'bgm_name'),
  142. 'bgm_url' => getProp($item, 'bgm_url'),
  143. 'playtime_seconds' => getProp($item, 'playtime_seconds'),
  144. 'created_at' => transDate(getProp($item, 'created_at')),
  145. ];
  146. }
  147. return $result;
  148. }
  149. }