wesmiler 3 лет назад
Родитель
Сommit
b9d16e8371
2 измененных файлов с 26 добавлено и 1 удалено
  1. 25 0
      app/Helpers/function.php
  2. 1 1
      app/Services/Api/MemberService.php

+ 25 - 0
app/Helpers/function.php

@@ -31,3 +31,28 @@ if (!function_exists('isPhone')) {
         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, '.', '');
+}

+ 1 - 1
app/Services/Api/MemberService.php

@@ -61,7 +61,7 @@ class MemberService extends BaseService
         }else{
             $info = $this->model->getInfo((int)$where);
         }
-
+        $info['utc_num'] = isset($info['utc_num'])? moneyFormat($info['utc_num']) : '0.00';
         return $info;
     }