product time changed 3
This commit is contained in:
@@ -237,6 +237,7 @@ class SingleOrderController extends Controller
|
||||
$response = [];
|
||||
$config = app(ConfigService::class);
|
||||
$feeFromGold = $config->feeDeductFromGold();
|
||||
$targetCash = $this->resolveTargetCash($data);
|
||||
$data['price'] += $data['difference'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
|
||||
@@ -256,6 +257,14 @@ class SingleOrderController extends Controller
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['amount'] -= $data['service_charge'];
|
||||
}
|
||||
|
||||
if ($targetCash !== null) {
|
||||
$data['payment_amount'] = $targetCash;
|
||||
if (!$feeFromGold) {
|
||||
$data['total_price'] = $targetCash;
|
||||
}
|
||||
}
|
||||
|
||||
if ($wallet->cash < $data['payment_amount']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
@@ -443,6 +452,13 @@ class SingleOrderController extends Controller
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$goldDebit = $data['amount'];
|
||||
}
|
||||
|
||||
$targetCash = $this->resolveTargetCash($data);
|
||||
if ($targetCash !== null) {
|
||||
$data['payment_amount'] = $targetCash;
|
||||
$data['total_price'] = $targetCash;
|
||||
}
|
||||
|
||||
if ($wallet->gold < $goldDebit) {
|
||||
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
|
||||
}
|
||||
@@ -863,6 +879,17 @@ class SingleOrderController extends Controller
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveTargetCash(array $data): ?int
|
||||
{
|
||||
if (!isset($data['target_cash'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$target = (int) round((float) $data['target_cash']);
|
||||
|
||||
return $target > 0 ? $target : null;
|
||||
}
|
||||
|
||||
private function resolveGoldPaymentProductId(array $data): ?int
|
||||
{
|
||||
if (!empty($data['payment_product_id'])) {
|
||||
|
||||
Reference in New Issue
Block a user