<?php

namespace App\Modules\User\Models;

use Illuminate\Database\Eloquent\Model;

class UserDeepReadTag extends Model
{
    protected $table = 'user_deep_read_tags';
    protected $fillable = ['uid','bid','book_name','category_id','category_name','sex_preference','distribution_channel_id','send_order_id'];

    public static function addTag($data){
    	return self::create($data);
    }

    public static function isAddTag($uid,$bid){
    	return self::where('uid',$uid)->where('bid',$bid)->count();
    }

    public static function getUserTags($uid){
    	$category_ids = self::where('uid',$uid)->select('category_id')->distinct()->get();
    	$data = [];
        foreach ($category_ids as $v){
            array_push($data,$v->category_id);
        }
        return self::where('uid',$uid)->whereIn('category_id',$data)->orderBy('id','desc')->select('category_name','category_id')->limit(4)->get();
    }	
}
