| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- if (!function_exists('getValidatorError')) {
- /**
- * 错误验证
- * @param $error
- * @return mixed
- */
- function getValidatorError($validator)
- {
- $errors = $validator->errors()->all();
- return isset($errors[0]) ? $errors[0] : 1013;
- }
- }
- /**
- * 是否是手机号码
- */
- if (!function_exists('isPhone')) {
- function isPhone($mobile)
- {
- return preg_match("/^1[3-9][0-9]]{9}/", $mobile);
- }
- }
- /**
- * 金钱格式化小数点
- * @param $money
- * @param int $decimal 小数点位数,默认系统配置2位
- * @return float
- */
- function moneyFormat($money, $decimal=null){
- $formatConfig = [];
- $charset = !empty($formatConfig['charset'])? trim($formatConfig['charset']) : 'utf-8';
- if($decimal === null){
- $decimal = isset($formatConfig['moneyDecimal'])? intval($formatConfig['moneyDecimal']): 2;
- }
- $money = round($money, $decimal+1);
- $data = explode('.', $money);
- $money = isset($data[0])? $data[0] : 0;
- $float = isset($data[1])? $data[1] : '';
- $len = $float? mb_strlen($float, $charset) : 0;
- $decimal = $decimal>=0? intval($decimal) : 2;
- $num1 = isset($data[1])? $data[1] : '';
- $float = $len>=$decimal? mb_substr($num1, 0, $decimal, $charset) : $float.str_repeat('0', $decimal-$len);
- $money = $money.'.'.$float;
- return number_format($money, $decimal, '.', '');
- }
|