<?php

namespace addons\webman\model;

use addons\webman\traits\DataPermissions;
use addons\webman\traits\HasDateTimeFormatter;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Class PlayerPromoter
 * @property int id 主键
 * @property int batch_id 批次ID
 * @property string verify_code 验证码
 * @property string tag_code 标识码
 * @property int score 积分值
 * @property int scan_user_id 扫码人
 * @property string scan_nickname 扫码人昵称
 * @property int brand_id 
 * @property string scan_phone 扫码人电话
 * @property string scan_time 扫码时间
 * @property int status 状态
 * @property string created_at 创建时间
 * @property string updated_at 修改时间
 *
 * @property Player player
 * @property Qrcode parent_promoter
 * @package addons\webman\model
 */
class Qrcode extends Model
{
    use HasDateTimeFormatter, DataPermissions;

    protected $fillable = ['batch_id', 'verify_code', 'tag_code', 'score', 'brand_id'];
    /**
     * 时间转换
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setTable(plugin()->webman->config('database.qrcode_table'));
    }

    public function qrcode_batch(): BelongsTo
    {
        return $this->belongsTo(plugin()->webman->config('database.qrcode_batch_model'), 'batch_id', 'id');
    }

}
