diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 87b3a31..cbfcfa5 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -23,6 +23,10 @@ class Transaction extends Model 'paid_at', ]; + protected $casts = [ + 'balance' => 'decimal:2', + ]; + protected $fillable = [ // 交易类型 'type', diff --git a/app/Models/User.php b/app/Models/User.php index b7344d7..64cd3e6 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -113,7 +113,7 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', - 'balance' => 'float', + 'balance' => 'decimal:2', 'banned_at' => 'datetime', ]; @@ -125,9 +125,9 @@ protected static function boot() // balance 四舍五入 - if ($model->isDirty('balance')) { - $model->balance = round($model->balance, 2, PHP_ROUND_HALF_DOWN); - } + // if ($model->isDirty('balance')) { + // $model->balance = round($model->balance, 2, PHP_ROUND_HALF_DOWN); + // } if ($model->isDirty('banned_at')) { if ($model->banned_at) {