TimbreTransformer.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace App\Transformer\Timbre;
  3. class TimbreTransformer
  4. {
  5. // 分类列表
  6. public function newBuildCategoryList($data): array
  7. {
  8. return [
  9. 'meta' => getMeta($data),
  10. 'list' => $this->newEachCategoryList($data),
  11. ];
  12. }
  13. private function newEachCategoryList($list): array
  14. {
  15. $result = [];
  16. if (empty($list)) return $result;
  17. foreach ($list as $item) {
  18. $result[] = [
  19. 'category_id' => getProp($item, 'id'),
  20. 'category_name' => getProp($item, 'category_name'),
  21. 'created_at' => transDate(getProp($item, 'created_at')),
  22. ];
  23. }
  24. return $result;
  25. }
  26. // 书籍列表
  27. public function newBuildTimbreList($data): array
  28. {
  29. return [
  30. 'meta' => getMeta($data),
  31. 'list' => $this->newEachTimbreList($data),
  32. ];
  33. }
  34. private function newEachTimbreList($list): array
  35. {
  36. $result = [];
  37. if (empty($list)) return $result;
  38. foreach ($list as $item) {
  39. $result[] = [
  40. 'voice_id' => getProp($item, 'id'),
  41. 'voice_name' => str_replace('(多情感)', '', getProp($item, 'timbre_name')),
  42. 'voice_type' => getProp($item, 'timbre_type'),
  43. 'timbre_url' => getProp($item, 'timbre_url'),
  44. 'language' => getProp($item, 'language'),
  45. 'dialect' => getProp($item, 'dialect'),
  46. 'emotion' => getProp($item, 'emotion'),
  47. 'first_category_id' => getProp($item, 'first_category_id'),
  48. 'first_category_name' => getProp($item, 'first_category_name'),
  49. 'second_category_id' => getProp($item, 'second_category_id'),
  50. 'second_category_name' => getProp($item, 'second_category_name'),
  51. 'third_category_id' => getProp($item, 'third_category_id'),
  52. 'third_category_name' => getProp($item, 'third_category_name'),
  53. 'audio_url' => getProp($item, 'audio_url'),
  54. 'label' => getProp($item, 'label'),
  55. 'created_at' => transDate(getProp($item, 'created_at')),
  56. ];
  57. }
  58. return $result;
  59. }
  60. // 章节列表
  61. public function newBuildChapterList($data): array
  62. {
  63. return [
  64. 'meta' => getMeta($data['list']),
  65. 'header' => $data['header'],
  66. 'list' => $this->newEachChapterList($data['list']),
  67. ];
  68. }
  69. private function newEachChapterList($list): array
  70. {
  71. $result = [];
  72. if (empty($list)) return $result;
  73. foreach ($list as $item) {
  74. $result[] = [
  75. 'cid' => getProp($item, 'cid'),
  76. 'chapter_name' => getProp($item, 'chapter_name'),
  77. 'sequence' => getProp($item, 'sequence'),
  78. 'size' => getProp($item, 'size'),
  79. 'generate_status' => getProp($item, 'generate_status'),
  80. 'audio_url' => getProp($item, 'audio_url'),
  81. 'remark' => getProp($item, 'remark'),
  82. ];
  83. }
  84. return $result;
  85. }
  86. // 分类列表
  87. public function newBuildTimbreGroupList($data): array
  88. {
  89. return [
  90. 'meta' => getMeta($data),
  91. 'list' => $this->newEachTimbreGroupList($data),
  92. ];
  93. }
  94. private function newEachTimbreGroupList($list): array
  95. {
  96. $result = [];
  97. if (empty($list)) return $result;
  98. foreach ($list as $item) {
  99. $result[] = [
  100. 'group_id' => getProp($item, 'id'),
  101. 'group_name' => getProp($item, 'group_name'),
  102. 'label' => getProp($item, 'label'),
  103. 'male_lead_voice_name' => getProp($item, 'male_lead_voice_name'),
  104. 'male_lead_voice_type' => getProp($item, 'male_lead_voice_type'),
  105. 'female_lead_voice_name' => getProp($item, 'female_lead_voice_name'),
  106. 'female_lead_voice_type' => getProp($item, 'female_lead_voice_type'),
  107. 'narration_voice_name' => getProp($item, 'narration_voice_name'),
  108. 'narration_voice_type' => getProp($item, 'narration_voice_type'),
  109. 'other_roles' => getProp($item, 'other_roles') ? json_decode(getProp($item, 'other_roles'), true) : [],
  110. 'created_at' => transDate(getProp($item, 'created_at')),
  111. ];
  112. }
  113. return $result;
  114. }
  115. }