Bläddra i källkod

Fixed float data type does not show correctly

BrettonYe 1 år sedan
förälder
incheckning
f9c0b9faa2
4 ändrade filer med 11 tillägg och 11 borttagningar
  1. 3 3
      app/Casts/data_rate.php
  2. 3 3
      app/Casts/money.php
  3. 2 2
      app/Services/PaymentService.php
  4. 3 3
      app/Utils/Helpers.php

+ 3 - 3
app/Casts/data_rate.php

@@ -12,9 +12,9 @@ class data_rate implements CastsAttributes
      *
      * @param  array<string, mixed>  $attributes
      */
-    public function get(Model $model, string $key, mixed $value, array $attributes): int|float
+    public function get(Model $model, string $key, mixed $value, array $attributes): float
     {
-        return $value / Mbps;
+        return round($value / Mbps, 2);
     }
 
     /**
@@ -24,6 +24,6 @@ class data_rate implements CastsAttributes
      */
     public function set(Model $model, string $key, mixed $value, array $attributes): int
     {
-        return $value * Mbps;
+        return (int) round($value * Mbps);
     }
 }

+ 3 - 3
app/Casts/money.php

@@ -12,9 +12,9 @@ class money implements CastsAttributes
      *
      * @param  array<string, mixed>  $attributes
      */
-    public function get(Model $model, string $key, mixed $value, array $attributes): int|float
+    public function get(Model $model, string $key, mixed $value, array $attributes): float
     {
-        return $value / 100;
+        return round($value / 100, 2);
     }
 
     /**
@@ -24,6 +24,6 @@ class money implements CastsAttributes
      */
     public function set(Model $model, string $key, mixed $value, array $attributes): int
     {
-        return $value * 100;
+        return (int) round($value * 100);
     }
 }

+ 2 - 2
app/Services/PaymentService.php

@@ -15,7 +15,7 @@ class PaymentService
         $payment->trade_no = Str::random(8);
         $payment->user_id = $uid;
         $payment->order_id = $oid;
-        $payment->amount = round($amount, 2);
+        $payment->amount = $amount;
         $payment->save();
 
         return $payment;
@@ -31,7 +31,7 @@ class PaymentService
         $log = new PaymentCallback();
         $log->trade_no = $trade_no;
         $log->out_trade_no = $out_trade_no;
-        $log->amount = round($amount, 2);
+        $log->amount = $amount;
 
         return $log->save();
     }

+ 3 - 3
app/Utils/Helpers.php

@@ -182,9 +182,9 @@ class Helpers
         $log = new UserCreditLog();
         $log->user_id = $userId;
         $log->order_id = $orderId;
-        $log->before = round($before, 2);
-        $log->after = round($after, 2);
-        $log->amount = round($amount, 2);
+        $log->before = $before;
+        $log->after = $after;
+        $log->amount = $amount;
         $log->description = $description;
         $log->created_at = date('Y-m-d H:i:s');