BookTransformer.php 5.6 KB

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