fixed عدهف
This commit is contained in:
@@ -137,11 +137,7 @@ class WalletController extends Controller
|
||||
} else {
|
||||
$record->title = ($record->gold > 0 ? self::productBuyTitle($wallet->product->title) : self::productSellTitle($wallet->product->title));
|
||||
}
|
||||
$record->unit = self::productQuantityUnit([
|
||||
'unit' => $wallet->product->unit ?? null,
|
||||
'direct_price' => $wallet->product->direct_price ?? null,
|
||||
'group_type' => $wallet->product->group_type ?? null,
|
||||
]);
|
||||
$record->unit = self::productQuantityUnit(self::productUnitPayload($wallet->product));
|
||||
} else {
|
||||
$record->title = $this->resolveMainWalletTransactionTitle($record);
|
||||
}
|
||||
@@ -560,30 +556,55 @@ class WalletController extends Controller
|
||||
}
|
||||
|
||||
if (!empty($record->wallet?->product)) {
|
||||
$record->unit = self::productQuantityUnit([
|
||||
'unit' => $record->wallet->product->unit ?? null,
|
||||
'direct_price' => $record->wallet->product->direct_price ?? null,
|
||||
'group_type' => $record->wallet->product->group_type ?? null,
|
||||
]);
|
||||
$this->applyProductTransactionUnit($record);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveTransactionProduct($record): ?Product
|
||||
{
|
||||
$partial = $record->wallet->product ?? $record->product ?? null;
|
||||
$productId = (int) ($partial->id ?? $record->product_id ?? 0);
|
||||
|
||||
if ($productId <= 0) {
|
||||
return $partial instanceof Product ? $partial : null;
|
||||
}
|
||||
|
||||
return Product::query()
|
||||
->select([
|
||||
'id',
|
||||
'title',
|
||||
'group_type',
|
||||
'unit',
|
||||
'direct_price',
|
||||
'amount',
|
||||
'trade_by_quantity',
|
||||
'metal_id',
|
||||
])
|
||||
->find($productId) ?? ($partial instanceof Product ? $partial : null);
|
||||
}
|
||||
|
||||
private function applyProductTransactionUnit($record): void
|
||||
{
|
||||
$product = $record->wallet->product ?? $record->product ?? null;
|
||||
$product = $this->resolveTransactionProduct($record);
|
||||
|
||||
if (!$product) {
|
||||
if (!empty($record->gold) && empty($record->wallet?->product)) {
|
||||
if (!empty($record->gold)) {
|
||||
$record->unit = self::tradeWeightUnit();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$record->unit = self::productQuantityUnit([
|
||||
'unit' => $product->unit ?? null,
|
||||
'direct_price' => $product->direct_price ?? null,
|
||||
'group_type' => $product->group_type ?? null,
|
||||
]);
|
||||
$payload = self::productUnitPayload($product);
|
||||
$onMainWallet = empty($record->wallet?->product_id);
|
||||
[$displayGold, $unit] = self::resolveTransactionDisplayGoldAndUnit(
|
||||
$payload,
|
||||
(float) ($record->gold ?? 0),
|
||||
$onMainWallet
|
||||
);
|
||||
|
||||
$record->gold = $displayGold;
|
||||
$record->unit = $unit;
|
||||
}
|
||||
|
||||
private function isProductWalletTransaction($record): bool
|
||||
|
||||
Reference in New Issue
Block a user