fix(wallet): allow discharging leftover fractional count-product gold
Admin charge can now wipe the exact remaining balance when a count product has a leftover decimal amount. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -560,10 +560,6 @@ class WalletController extends Controller
|
||||
$deposit = $value > 0;
|
||||
|
||||
$payload = Controller::productUnitPayload($product);
|
||||
if (Controller::isCountBasedProduct($payload) && abs($value - round($value)) > 0.000001) {
|
||||
throw new UnprocessableEntityHttpException('برای محصول تعدادی فقط عدد صحیح مجاز است');
|
||||
}
|
||||
|
||||
$isMainWalletProduct = Controller::isMainWalletProduct($productId);
|
||||
if (!$deposit && $isMainWalletProduct) {
|
||||
$this->consolidateOrphanedMainWalletGold((int) $customer->id, (int) $customer->type);
|
||||
@@ -577,6 +573,18 @@ class WalletController extends Controller
|
||||
$effectiveProductId
|
||||
);
|
||||
$wallet = $wallet_interface->wallet;
|
||||
$availableGold = is_null($wallet) ? 0.0 : (float) $wallet->gold;
|
||||
$wipingRemainder = !$deposit
|
||||
&& $availableGold > 0
|
||||
&& abs($availableGold - abs($value)) <= 1e-6;
|
||||
|
||||
if (
|
||||
Controller::isCountBasedProduct($payload)
|
||||
&& abs($value - round($value)) > 0.000001
|
||||
&& ! $wipingRemainder
|
||||
) {
|
||||
throw new UnprocessableEntityHttpException('برای محصول تعدادی فقط عدد صحیح مجاز است');
|
||||
}
|
||||
|
||||
if (!$deposit) {
|
||||
$available = is_null($wallet) ? 0.0 : (float) $wallet->gold;
|
||||
|
||||
Reference in New Issue
Block a user