<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\TicketModel
 *
 * @property int $id
 * @property string $name 名称
 * @property string $description 说明
 * @property string $code 兑换码
 * @property int $type 类型=6超级会员72h解锁卡
 * @property int|null $uid 所属用户
 * @property int $state 状态
 * @property int $get_time 领取时间
 * @property int $create_time 生成时间
 * @property int|null $validity_time 有效期
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 修改时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereCreateTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereGetTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereState($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TicketModel whereValidityTime($value)
 * @mixin \Eloquent
 * @deprecated
 */
class TicketModel extends Model
{
    protected $table = "kdgx_partner_charge_user_ticket";

    protected $dateFormat = 'U';

    public $fillable = [
        'name',
        'description',
        'code',
        'type',
        'uid',
        'state',
        'get_time',
        'create_time',
        'validity_time'
    ];

    public function getUseableByUid(int $uid, array $types)
    {
        $tickets = $this->where([
            ['uid', $uid],
            ['state', 0],
            ['validity_time', '>', time()]
        ])->whereIn('type', $types)->orderBy('get_time', 'desc')->get();
        return $tickets;
    }
}
