<?php

namespace App\Models\Fpdx;

use App\Models\Model;

/**
 * App\Models\Fpdx\MasterModel
 *
 * @property int $id 主键
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 更新时间
 * @property int $uid 房主id
 * @property int $thumbs 点赞数
 * @property int $cps cp数
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel whereCps($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel whereThumbs($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\MasterModel whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class MasterModel extends Model
{
    public $table = "kdgx_fpdx_masters";

    public $dateFormat = 'U';

    protected $fillable = ["id", 'uid', 'thumbs', 'cps'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(\App\Models\User\UserModel::class, 'uid', 'uid');
    }

    /**
     * @param  int  $uid
     * @return MasterModel|\Illuminate\Database\Eloquent\Model|null|object
     */
    public function getMaster(int $uid)
    {
        $master = $this->firstOrCreate(['uid' => $uid]);
        return $master;
    }
}
