product time changed 3
This commit is contained in:
@@ -782,6 +782,9 @@ class WalletController extends Controller
|
||||
$row['type_str'] = 'برداشت طلایی';
|
||||
}
|
||||
|
||||
$this->normalizeApiRelationStsStr($row, 'order', Order::$STS);
|
||||
$this->normalizeApiRelationStsStr($row, 'withdraw', Withdraw::$STS);
|
||||
|
||||
$out[] = $row;
|
||||
}
|
||||
|
||||
@@ -868,4 +871,32 @@ class WalletController extends Controller
|
||||
return $previousTx ? (int) $previousTx->balance_cash : null;
|
||||
}
|
||||
|
||||
private function normalizeApiRelationStsStr(array &$row, string $key, array $stsMap): void
|
||||
{
|
||||
if (empty($row[$key]) || !is_array($row[$key])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$relation = &$row[$key];
|
||||
$sts = $relation['sts'] ?? null;
|
||||
if ($sts === null && isset($relation['sts_str']) && is_numeric($relation['sts_str'])) {
|
||||
$sts = (int) $relation['sts_str'];
|
||||
}
|
||||
|
||||
if ($sts !== null && isset($stsMap[$sts])) {
|
||||
$relation['sts_str'] = $stsMap[$sts];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$current = trim((string) ($relation['sts_str'] ?? ''));
|
||||
if ($current !== '' && $current !== 'بدون مقدار') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($key === 'order' && (int) ($relation['payment_sts'] ?? 0) === 4) {
|
||||
$relation['sts_str'] = 'موفق';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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