php生成唯一订单号

编程

<?php

declare(strict_types=1);

use thinkfacadeCache;

use thinkfacadeConfig;

use GodruoyiSnowflakeSnowflake;

use GodruoyiSnowflakeRedisSequenceResolver;

/**

* 获取redis实例

*

* @return Redis

*/

function get_redis(): Redis

{

return Cache::store()->handler();

}

/**

* 生成唯一订单号

*

* @param string $prefix 订单号前缀

* @return string

*/

function build_order_no(string $prefix = ""): string

{

$options = Config::get("cache.stores.redis");

$redis = get_redis();

$snowflake = new Snowflake();

$sequence = new RedisSequenceResolver($redis);

$sequence->setCachePrefix($options["prefix"] . "order_no:");

$snowflake->setSequenceResolver($sequence);

return $prefix . $snowflake->id();

}

以上是 php生成唯一订单号 的全部内容, 来源链接: utcz.com/z/517993.html

回到顶部