<?php

namespace App\Models\Appearance;

use App\Models\User\UserModel;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Appearance\AppearanceVoteModel
 *
 * @property int $id
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 更新时间
 * @property int $uid 用户
 * @property int $type 类型:1=学校
 * 2=用户
 * @property int $partner_id 卡片
 * @property string $school 学校
 * @property string $media_id 公众号
 * @property-read \App\Models\User\UserModel $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel today()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereMediaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel wherePartnerId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereSchool($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Appearance\AppearanceVoteModel whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class AppearanceVoteModel extends Model
{
    //
    protected $table = 'fpdx_appearance_votes';

    protected $dateFormat = 'U';

    protected $fillable = ['uid', 'type', 'partner_id', 'school', 'media_id'];


    public function scopeToday($query)
    {
        return $query->whereBetween('created_at', [mktime(0, 0, 0), mktime(23, 59, 59)]);
    }


    public function user()
    {
        return $this->belongsTo(UserModel::class, 'uid', 'uid')->select('nickname', 'headimgurl', 'sex');
    }
}
