BookTransformer.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. $subtitle_info = getProp($item, 'subtitle_info');
  44. if ($subtitle_info) $subtitle_info = json_decode($subtitle_info, true);
  45. else $subtitle_info = [];
  46. $result[] = [
  47. 'audio_id' => getProp($item, 'id'),
  48. 'cid' => getProp($item, 'cid'),
  49. 'chapter_name' => getProp($item, 'chapter_name'),
  50. 'sequence' => getProp($item, 'sequence'),
  51. 'size' => getProp($item, 'size'),
  52. 'generate_status' => getProp($item, 'generate_status'),
  53. 'audio_url' => getProp($item, 'complete_audio_url') ? getProp($item, 'complete_audio_url') : getProp($item, 'audio_url'),
  54. 'audio_effect_status' => getProp($item, 'audio_effect_status'),
  55. 'bgm_status' => getProp($item, 'bgm_status'),
  56. 'remark' => getProp($item, 'remark'),
  57. 'subtitle_info' => $subtitle_info
  58. ];
  59. }
  60. return $result;
  61. }
  62. // 版本列表
  63. public function newBuildVersionList($data): array
  64. {
  65. return [
  66. 'meta' => getMeta($data),
  67. 'list' => $this->newEachVersionList($data),
  68. ];
  69. }
  70. private function newEachVersionList($list): array
  71. {
  72. $result = [];
  73. if (empty($list)) return $result;
  74. foreach ($list as $item) {
  75. $result[] = [
  76. 'version_id' => getProp($item, 'id'),
  77. 'version_name' => getProp($item, 'version_name'),
  78. 'bid' => getProp($item, 'bid'),
  79. 'book_name' => getProp($item, 'book_name'),
  80. 'created_at' => getProp($item, 'created_at'),
  81. ];
  82. }
  83. return $result;
  84. }
  85. // 合成任务列表
  86. public function newBuildTaskList($data): array
  87. {
  88. return [
  89. 'meta' => getMeta($data),
  90. 'list' => $this->newEachTaskList($data),
  91. ];
  92. }
  93. private function newEachTaskList($list): array
  94. {
  95. $result = [];
  96. if (empty($list)) return $result;
  97. foreach ($list as $item) {
  98. $result[] = [
  99. 'task_id' => getProp($item, 'id'),
  100. 'task_name' => getProp($item, 'task_name'),
  101. 'generate_status' => getProp($item, 'generate_status'),
  102. 'bid' => getProp($item, 'bid'),
  103. 'version_id' => getProp($item, 'version_id'),
  104. 'cid' => getProp($item, 'cid'),
  105. 'created_at' => getProp($item, 'created_at'),
  106. ];
  107. }
  108. return $result;
  109. }
  110. // 音效列表
  111. public function newBuildAudioEffectList($data): array
  112. {
  113. return [
  114. 'meta' => getMeta($data),
  115. 'list' => $this->newEachAudioEffectList($data),
  116. ];
  117. }
  118. private function newEachAudioEffectList($list): array
  119. {
  120. $result = [];
  121. if (empty($list)) return $result;
  122. foreach ($list as $item) {
  123. $result[] = [
  124. 'audio_effect_id' => getProp($item, 'id'),
  125. 'audio_effect_name' => getProp($item, 'audio_effect_name'),
  126. 'audio_effect_url' => getProp($item, 'audio_effect_url'),
  127. 'playtime_seconds' => getProp($item, 'playtime_seconds'),
  128. 'created_at' => transDate(getProp($item, 'created_at')),
  129. ];
  130. }
  131. return $result;
  132. }
  133. // bgm列表
  134. public function newBuildBgmList($data): array
  135. {
  136. return [
  137. 'meta' => getMeta($data),
  138. 'list' => $this->newEachBgmList($data),
  139. ];
  140. }
  141. private function newEachBgmList($list): array
  142. {
  143. $result = [];
  144. if (empty($list)) return $result;
  145. foreach ($list as $item) {
  146. $result[] = [
  147. 'bgm_id' => getProp($item, 'id'),
  148. 'bgm_name' => getProp($item, 'bgm_name'),
  149. 'bgm_url' => getProp($item, 'bgm_url'),
  150. 'playtime_seconds' => getProp($item, 'playtime_seconds'),
  151. 'created_at' => transDate(getProp($item, 'created_at')),
  152. ];
  153. }
  154. return $result;
  155. }
  156. }