BookTransformer.php 5.9 KB

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