BookTransformer.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. 'created_at' => getProp($item, 'created_at'),
  96. ];
  97. }
  98. return $result;
  99. }
  100. }