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;
}