6
0
Fork 0

修改价格属性转换

release
李静 2021-11-30 11:19:06 +08:00
parent 54adb39b83
commit 39dc3f7150
1 changed files with 8 additions and 0 deletions

View File

@ -17,6 +17,10 @@ class Price implements CastsAttributes
*/ */
public function get($model, string $key, $value, array $attributes) public function get($model, string $key, $value, array $attributes)
{ {
if ((string) $value === '') {
return null;
}
return bcdiv($value, 100, 2); return bcdiv($value, 100, 2);
} }
@ -31,6 +35,10 @@ class Price implements CastsAttributes
*/ */
public function set($model, string $key, $value, array $attributes) public function set($model, string $key, $value, array $attributes)
{ {
if ((string) $value === '') {
return null;
}
return (int) bcmul($value, 100); return (int) bcmul($value, 100);
} }
} }