12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Transformer\Book;
- use App\Cache\StatisticCache;
- use App\Consts\BaseConst;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Redis;
- use Vinkla\Hashids\Facades\Hashids;
- class BookTransformer
- {
- // 书籍列表
- public function newBuildBookList($data): array
- {
- return [
- 'meta' => getMeta($data),
- 'list' => $this->newEachBookList($data),
- ];
- }
- private function newEachBookList($list): array
- {
- $result = [];
- if (empty($list)) return $result;
- foreach ($list as $item) {
- $result[] = [
- 'bid' => getProp($item, 'bid'),
- 'book_name' => getProp($item, 'book_name'),
- 'origin_book_name' => getProp($item, 'origin_book_name') ? getProp($item, 'origin_book_name') : getProp($item, 'book_name'),
- 'status' => getProp($item, 'status'),
- 'status_info' => getProp($item, 'status') == 1 ? '已完结' : '连载中',
- 'version_count' => getProp($item, 'version_count'),
- ];
- }
- return $result;
- }
- // 章节列表
- public function newBuildChapterList($data): array
- {
- return [
- 'meta' => getMeta($data['list']),
- 'header' => $data['header'],
- 'list' => $this->newEachChapterList($data['list']),
- ];
- }
- private function newEachChapterList($list): array
- {
- $result = [];
- if (empty($list)) return $result;
- foreach ($list as $item) {
- $result[] = [
- 'cid' => getProp($item, 'cid'),
- 'chapter_name' => getProp($item, 'chapter_name'),
- 'sequence' => getProp($item, 'sequence'),
- 'size' => getProp($item, 'size'),
- 'generate_status' => getProp($item, 'generate_status'),
- 'audio_url' => getProp($item, 'audio_url'),
- 'remark' => getProp($item, 'remark'),
- ];
- }
- return $result;
- }
- // 版本列表
- public function newBuildVersionList($data): array
- {
- return [
- 'meta' => getMeta($data),
- 'list' => $this->newEachVersionList($data),
- ];
- }
- private function newEachVersionList($list): array
- {
- $result = [];
- if (empty($list)) return $result;
- foreach ($list as $item) {
- $result[] = [
- 'version_id' => getProp($item, 'id'),
- 'version_name' => getProp($item, 'version_name'),
- 'bid' => getProp($item, 'bid'),
- 'book_name' => getProp($item, 'book_name'),
- 'created_at' => getProp($item, 'created_at'),
- ];
- }
- return $result;
- }
- }
|