BookTransformer.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Transformer\Book;
  3. use App\Cache\StatisticCache;
  4. use App\Consts\BaseConst;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Redis;
  7. use Vinkla\Hashids\Facades\Hashids;
  8. class BookTransformer
  9. {
  10. // 书籍列表
  11. public function newBuildBookList($data): array
  12. {
  13. return [
  14. 'meta' => getMeta($data),
  15. 'list' => $this->newEachBookList($data),
  16. ];
  17. }
  18. private function newEachBookList($list): array
  19. {
  20. $result = [];
  21. if (empty($list)) return $result;
  22. foreach ($list as $item) {
  23. $result[] = [
  24. 'bid' => getProp($item, 'bid'),
  25. 'book_name' => getProp($item, 'book_name'),
  26. 'origin_book_name' => getProp($item, 'origin_book_name') ? getProp($item, 'origin_book_name') : getProp($item, 'book_name'),
  27. 'status' => getProp($item, 'status'),
  28. 'status_info' => getProp($item, 'status') == 1 ? '已完结' : '连载中',
  29. 'version_count' => getProp($item, 'version_count'),
  30. ];
  31. }
  32. return $result;
  33. }
  34. // 章节列表
  35. public function newBuildChapterList($data): array
  36. {
  37. return [
  38. 'meta' => getMeta($data['list']),
  39. 'header' => $data['header'],
  40. 'list' => $this->newEachChapterList($data['list']),
  41. ];
  42. }
  43. private function newEachChapterList($list): array
  44. {
  45. $result = [];
  46. if (empty($list)) return $result;
  47. foreach ($list as $item) {
  48. $result[] = [
  49. 'cid' => getProp($item, 'cid'),
  50. 'chapter_name' => getProp($item, 'chapter_name'),
  51. 'sequence' => getProp($item, 'sequence'),
  52. 'size' => getProp($item, 'size'),
  53. 'generate_status' => getProp($item, 'generate_status'),
  54. 'audio_url' => getProp($item, 'audio_url'),
  55. 'remark' => getProp($item, 'remark'),
  56. ];
  57. }
  58. return $result;
  59. }
  60. // 版本列表
  61. public function newBuildVersionList($data): array
  62. {
  63. return [
  64. 'meta' => getMeta($data),
  65. 'list' => $this->newEachVersionList($data),
  66. ];
  67. }
  68. private function newEachVersionList($list): array
  69. {
  70. $result = [];
  71. if (empty($list)) return $result;
  72. foreach ($list as $item) {
  73. $result[] = [
  74. 'version_id' => getProp($item, 'id'),
  75. 'version_name' => getProp($item, 'version_name'),
  76. 'bid' => getProp($item, 'bid'),
  77. 'book_name' => getProp($item, 'book_name'),
  78. 'created_at' => getProp($item, 'created_at'),
  79. ];
  80. }
  81. return $result;
  82. }
  83. // 合成任务列表
  84. public function newBuildTaskList($data): array
  85. {
  86. return [
  87. 'meta' => getMeta($data),
  88. 'list' => $this->newEachTaskList($data),
  89. ];
  90. }
  91. private function newEachTaskList($list): array
  92. {
  93. $result = [];
  94. if (empty($list)) return $result;
  95. foreach ($list as $item) {
  96. $result[] = [
  97. 'task_id' => getProp($item, 'id'),
  98. 'task_name' => getProp($item, 'task_name'),
  99. 'generate_status' => getProp($item, 'generate_status'),
  100. 'created_at' => getProp($item, 'created_at'),
  101. ];
  102. }
  103. return $result;
  104. }
  105. }