<?php
/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2018/7/25
 * Time: 16:37
 */

namespace App\Http\Controllers\Channel\Book\Transformers;

use Hashids;

class BookV2Transformer
{
    public function transform($book){
        if($book->recommend_index>=100){
            $score = 'SS级';
        }elseif($book->recommend_index>=95){
            $score = 'S级';
        }elseif($book->recommend_index>=90){
            $score = 'A+级';
        }elseif($book->recommend_index>=85){
            $score = 'A级';
        }elseif($book->recommend_index>=80){
            $score = 'B级';
        }elseif($book->recommend_index>=70){
            $score = 'C级';
        }else{
            $score = 'D级';
        }
        return [
            'book_id'=>Hashids::encode($book->bid),
            'book_name'=>$book->book_name,
            'cover_url'=>$book->cover,
            'book_category'=>$book->category_name,
            'book_end_status'=>$book->status,
            'recommend_index'=> $score,
            'sex_preference'=>$book->channel_name,
            'total_send_order_sum'=>($book->total_send_order_sum && (int)$book->total_send_order_sum != 60)?$book->total_send_order_sum:'尚未派单',
            'week_send_order_sum'=>($book->week_send_order_sum && $book->week_send_order_sum != 60)?$book->week_send_order_sum:'尚未派单',
            'read_deep'=>0,
            'charge_type'=>($book->charge_type == 'BOOK')?'全本购买':'按章购买',
            'channel_send_order_sum'=>$book->channel_send_order_sum?$book->channel_send_order_sum:0,
            'own_score'=>$book->own_score?$book->own_score:'无',
            'word_size'=>$book->size,
            'chapter_type'=>$book->size>200000?'长篇':'短篇',
            'on_shelf_time'=>$book->created_at->format('Y-m-d H:i:s'),
            'first_chapter_id'=>$book->first_cid,
            'first_chapter_name'=>$book->first_chapter_name,
            'editor_recommend_msg'=>$book->editor_recommend,
            'chapter_count'=>$book->chapter_count
            //'week_send_order_bid'=>$book->week_send_order_bid.'_'.$book->bid,
            //'week_send_order'=>$book->week_send_order,
        ];
    }
}