wxxcx_learn

本文介绍了如何使用PHP生成32个字符组成的随机字符串,以及一种生成唯一订单号的方法,结合年份、月份、日期、时间戳和随机数确保订单号的唯一性和可读性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


32个字符组成的一组随即字符串
function getRandChar($length){
$str = null;
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol) - 1;

for($i = 0;
$i <$length;
$i++){
$str .= $strPol[rand(0,max)];
}
return $str;
}
闭包构建查询器
public static function getProductDetail($id){
$product = self::with([
'imgs' => function($query){
$query ->with(['imgUrl'])
->order('order','asc');
}])
->with(['properties'])
->find($id);
    return $product;
}

生成订单号
public static function makeOrderNo()
{
$yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
$orderSn =
$yCode[intval(date('Y')) - 2017] . strtoupper(dechex(date('m'))) . date(
'd') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf(
'%02d', rand(0, 99));
return $orderSn;
}

转载于:https://www.cnblogs.com/a276665092/p/11082162.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值