<?php
namespace App\Laravue\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

class Installer extends Authenticatable
{
    use Notifiable, HasRoles, HasApiTokens;
    protected $table = "installer";
    public $timestamps = false;
    //添加装维人员
    public function addinstall($data = []) : string {
        $stringrand = $this->numsigng();
        foreach ($data as $k => $value) {
            if (is_null($k)) {
                return '用户提交表单参数错误';
            }
        }
        $data['addtime'] = time();
        $data['password'] = md5(md5($data['password']) . $stringrand);
        $data['salt'] = $stringrand;
        return $this->insertGetId($data);
    }

    //生成随机字符串
    private function numsigng() : int{
        $code = '';
        for ($i=1;$i<7;$i++) {
            $randcode = mt_rand(0,9);
            $code .= $randcode;
        }
        return (int)$code;
    }
}