<?php

namespace App\Models;

use App\Casts\DelimiterCast;
use App\Casts\HttpToHttps;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\ProductHot
 *
 * @property int $id
 * @property int $type 1- 普通用户 2-vip客户/设计师
 * @property string|null $product_id 产品列表
 * @property int $sort 排序越大越靠前
 * @property int $is_opened 是否启用 0-否 1-是
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot newQuery()
 * @method static \Illuminate\Database\Query\Builder|ProductHot onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot query()
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereIsOpened($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|ProductHot withTrashed()
 * @method static \Illuminate\Database\Query\Builder|ProductHot withoutTrashed()
 * @mixin \Eloquent
 * @property string $cover_img 爆款图片
 * @property-write mixed $products
 * @method static \Illuminate\Database\Eloquent\Builder|ProductHot whereCoverImg($value)
 */
class ProductHot extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'product_hots';

    protected $casts = [
        'cover_img' =>HttpToHttps::class,
        'product_id' => DelimiterCast::class
    ];

    public function setProductsAttribute(array $product_ids)
    {
        $products = Product::whereIn('id', $product_ids);
        $this->attributes['products'] = $products;
    }

}
