BookTransformer.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Date: 2017/3/31
  5. * Time: 14:02
  6. */
  7. namespace App\Http\Controllers\QuickApp\Book\Transformers;
  8. use Hashids;
  9. class BookTransformer
  10. {
  11. public function transform($book)
  12. {
  13. return [
  14. 'book_id' => Hashids::encode($book->bid),
  15. 'book_name' => $book->book_name,
  16. 'book_summary' => $book->intro,
  17. 'book_author' => $book->author,
  18. 'cover_url' => $book->cover,
  19. 'book_word_count' => $book->size,
  20. 'book_chapter_total' => $book->chapter_count,
  21. 'book_category_id' => $book->category_id,
  22. 'book_category' => $book->category_name,
  23. 'book_end_status' => $book->status,
  24. 'book_published_time' => $book->updated_at ?? '',
  25. 'copyright' => $book->copyright ?? '',
  26. 'charge_type' => $book->charge_type ?? '',
  27. 'force_subscribe_chapter_id' => $book->force_subscribe_chapter_seq,
  28. 'update_time' => $book->updated_at ?? '',
  29. 'is_on_shelf' => $book->is_on_shelf ?? 0,
  30. 'book_price' => $book->price ?? 0,
  31. 'keyword' => $book->keyword,
  32. 'recommend_index' => $book->recommend_index,
  33. 'is_show_index_content' => $book->is_show_index_content,
  34. 'click_count' => $book->click_count,
  35. 'product_id' => $book->product_id,
  36. 'sex_preference' => $book->channel_name,
  37. 'last_cid' => $book->last_cid,
  38. 'last_chapter' => $book->last_chapter,
  39. 'first_cid' => $book->first_cid,
  40. 'is_on_user_shelf' => $book->is_on_user_shelf,
  41. 'last_chapter_is_vip' => $book->last_chapter_is_vip ?? 0,
  42. 'is_need_charge' => $book->is_need_charge ? 1 : 0,
  43. 'record_chapter_id' => $book->record_chapter_id ?? 0,
  44. 'record_chapter_name' => $book->record_chapter_name ?? '',
  45. ];
  46. }
  47. }