<?php
/**
 * Created by PhpStorm.
 * User: congli
 * Date: 2020/2/28
 * Time: 1:42 PM
 */
namespace common\helpers\snowflake;

use yii\base\BaseObject;
use yii\base\StaticInstanceTrait;

class SnowFake extends BaseObject
{
    use StaticInstanceTrait;

    public $snowFlakeService;

    public function init()
    {
        parent::init();

        $this->snowFlakeService = new \Godruoyi\Snowflake\Snowflake($expiresIn = \Yii::$app->params['snowFake']['dataCenterId'], $expiresIn = \Yii::$app->params['snowFake']['workerId']);
    }

    /**
     * 获取service
     * @return mixed
     */
    public function getService() {
        return $this->snowFlakeService;
    }

    /**
     * @return mixed
     */
    public function generateId() {
        return $this->snowFlakeService->id();
    }
}