BookTransformer.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Date: 2017/3/31
  5. * Time: 14:02
  6. */
  7. namespace App\Http\Controllers\Manage\Book\Transformers;
  8. class BookTransformer
  9. {
  10. public function transform($book)
  11. {
  12. return [
  13. 'book_id' => $book->bid,
  14. 'book_name' => $book->book_name,
  15. 'book_summary' => $book->intro,
  16. 'book_author' => $book->author,
  17. 'cover_url' => $book->cover,
  18. 'book_word_count' => $book->size,
  19. 'book_chapter_total' => $book->chapter_count,
  20. 'book_category_id' => $book->category_id,
  21. 'book_category' => $book->category_name,
  22. 'book_end_status' => $book->status,
  23. 'book_published_time' => is_null($book->updated_at) ? '' : $book->updated_at,
  24. 'copyright' => is_null($book->copyright) ? '' : $book->copyright,
  25. 'charge_type' => is_null($book->charge_type) ? '' : $book->charge_type,
  26. 'force_subscribe_chapter_id' => $book->force_subscribe_chapter_seq,
  27. 'update_time' => $book->updated_at,
  28. 'is_on_shelf' => $book->is_on_shelf,
  29. 'book_price' => is_null($book->price) ? 0 : $book->price,
  30. 'keyword' => $book->keyword,
  31. 'roles' => isset($book->roles) ? $book->roles : '',
  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. 'category_array' => [$book->channel_name == '男频' ? 1 : 2, $book->category_id],
  41. 'copyright_limit_data' => is_null($book->copyright_limit_data) ? '' : $book->copyright_limit_data,
  42. 'promotion_domain' => $book->promotion_domain,
  43. 'old_name' => $book->old_name,
  44. 'recommend_text' => $book->recommend_text,
  45. 'book_special_channels' => $book->book_special_channels,
  46. 'is_high_quality' => $book->is_high_quality,
  47. 'is_promotion' => isset($book->is_promotion) ? $book->is_promotion : 0,
  48. 'tags'=>isset($book->tags) ? $book->tags:[]
  49. ];
  50. }
  51. }