<?php

declare(strict_types=1);

namespace app\admin\model;

use support\think\Model;

class UserRule extends Model
{
    protected string $table = 'user_rule';
    protected string $pk = 'id';
    protected bool $autoWriteTimestamp = true;

    protected static function onAfterInsert($model): void
    {
        $pk = $model->getPk();
        $model->where($pk, $model[$pk])->update(['weigh' => $model[$pk]]);
    }

    public function setComponentAttr($value)
    {
        if ($value) $value = str_replace('\\', '/', $value);
        return $value;
    }
}
