<?php
/**
 * @author 林海涛
 * @date ${DATA}
 */

namespace app\common\model\master_worker;

use app\common\model\BaseModel;
use app\common\model\MasterWorkerRegister;

/**
 * 师傅表
 * Class MasterWorker
 * @package app\common\model
 */
class MasterWorker extends BaseModel
{
    protected $name = 'master_worker';
    public static function createUserSn($prefix = '', $length = 8)
    {
        $rand_str = '';
        for ($i = 0; $i < $length; $i++) {
            $rand_str .= mt_rand(1, 9);
        }
        $sn = $prefix . $rand_str;
        if (MasterWorker::where(['sn' => $sn])->find()) {
            return self::createUserSn($prefix, $length);
        }
        return $sn;
    }

    public function workerRegister()
    {
        return $this->hasOne(MasterWorkerRegister::class, 'worker_id', 'id');
    }

}