fixed product title
This commit is contained in:
@@ -402,17 +402,12 @@ class WalletController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$productId = $this->resolveAbshodeProductId($record);
|
||||
if (!$productId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = $record->product->title
|
||||
?? Product::query()->whereKey($productId)->value('title');
|
||||
if (!$productTitle) {
|
||||
$product = $this->resolveTransactionProduct($record);
|
||||
if (!$product || trim((string) $product->title) === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = trim((string) $product->title);
|
||||
$direction = (int) ($record->order->direction ?? 0);
|
||||
if ($direction === 1 || ($direction === 0 && (float) ($record->gold ?? 0) > 0)) {
|
||||
$record->title = self::productBuyTitle($productTitle);
|
||||
@@ -430,9 +425,14 @@ class WalletController extends Controller
|
||||
return (int) $record->product_id;
|
||||
}
|
||||
|
||||
$note = (string) ($record->note ?? '');
|
||||
if ($note !== '' && preg_match('/(?:^|;)product_id:(\d+)/', $note, $matches)) {
|
||||
return (int) $matches[1];
|
||||
$noteProductId = $this->productIdFromTransactionNote($record->note ?? null);
|
||||
if ($noteProductId) {
|
||||
return $noteProductId;
|
||||
}
|
||||
|
||||
$wallet = $this->resolveTransactionWallet($record);
|
||||
if ($wallet && !empty($wallet->product_id)) {
|
||||
return (int) $wallet->product_id;
|
||||
}
|
||||
|
||||
if (empty($record->order_id)) {
|
||||
@@ -445,7 +445,33 @@ class WalletController extends Controller
|
||||
->where('product_id', '>', 0)
|
||||
->value('product_id');
|
||||
|
||||
return $siblingProductId ? (int) $siblingProductId : null;
|
||||
if ($siblingProductId) {
|
||||
return (int) $siblingProductId;
|
||||
}
|
||||
|
||||
$siblingNotes = Transaction::query()
|
||||
->where('order_id', $record->order_id)
|
||||
->whereNotNull('note')
|
||||
->pluck('note');
|
||||
|
||||
foreach ($siblingNotes as $note) {
|
||||
$productId = $this->productIdFromTransactionNote($note);
|
||||
if ($productId) {
|
||||
return $productId;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function productIdFromTransactionNote(?string $note): ?int
|
||||
{
|
||||
$note = (string) ($note ?? '');
|
||||
if ($note === '' || !preg_match('/(?:^|;)product_id:(\d+)/', $note, $matches)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $matches[1];
|
||||
}
|
||||
|
||||
private function applyMetalTypeTransactionTitle($record): void
|
||||
@@ -458,7 +484,7 @@ class WalletController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$wallet = $record->wallet ?? null;
|
||||
$wallet = $this->resolveTransactionWallet($record);
|
||||
if ($wallet && !empty($wallet->product)) {
|
||||
return;
|
||||
}
|
||||
@@ -488,18 +514,12 @@ class WalletController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$productId = $this->resolveAbshodeProductId($record);
|
||||
if (!$productId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = $record->product->title
|
||||
?? $record->wallet->product->title
|
||||
?? Product::query()->whereKey($productId)->value('title');
|
||||
if (!$productTitle) {
|
||||
$product = $this->resolveTransactionProduct($record);
|
||||
if (!$product || trim((string) $product->title) === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = trim((string) $product->title);
|
||||
$expectedBuy = self::productBuyTitle($productTitle);
|
||||
$expectedSell = self::productSellTitle($productTitle);
|
||||
|
||||
@@ -515,11 +535,28 @@ class WalletController extends Controller
|
||||
|
||||
if ($direction === 2 || ($direction === 0 && (float) ($record->gold ?? 0) < 0)) {
|
||||
$record->title = $expectedSell;
|
||||
return;
|
||||
}
|
||||
|
||||
if (self::isGenericMetalTransactionTitle($record->title)) {
|
||||
$record->title = $expectedBuy;
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveMainWalletTransactionTitle($record): string
|
||||
{
|
||||
$product = $this->resolveTransactionProduct($record);
|
||||
if ($product && trim((string) $product->title) !== '') {
|
||||
$productTitle = trim((string) $product->title);
|
||||
if ((int) $record->type === 1) {
|
||||
return self::productBuyTitle($productTitle);
|
||||
}
|
||||
|
||||
if ((int) $record->type === 2) {
|
||||
return self::productSellTitle($productTitle);
|
||||
}
|
||||
}
|
||||
|
||||
if ((int) $record->type === 1) {
|
||||
return self::meltedGoldBuyTitle();
|
||||
}
|
||||
@@ -560,15 +597,39 @@ class WalletController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveTransactionWallet($record): ?Wallet
|
||||
{
|
||||
if ($record instanceof Transaction) {
|
||||
$relation = $record->getRelationValue('wallet');
|
||||
if ($relation instanceof Wallet) {
|
||||
return $relation;
|
||||
}
|
||||
}
|
||||
|
||||
$walletId = (int) ($record->getAttributes()['wallet'] ?? 0);
|
||||
if ($walletId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Wallet::with('product')->find($walletId);
|
||||
}
|
||||
|
||||
private function resolveTransactionProduct($record): ?Product
|
||||
{
|
||||
$partial = $record->wallet->product ?? $record->product ?? null;
|
||||
$productId = (int) ($partial->id ?? $record->product_id ?? 0);
|
||||
$productId = $this->resolveAbshodeProductId($record) ?? 0;
|
||||
$wallet = $this->resolveTransactionWallet($record);
|
||||
|
||||
if ($productId <= 0) {
|
||||
$partial = $wallet?->product ?? $record->product ?? null;
|
||||
|
||||
return $partial instanceof Product ? $partial : null;
|
||||
}
|
||||
|
||||
$partial = $record->product ?? $wallet?->product ?? null;
|
||||
if ($partial instanceof Product && (int) $partial->id === $productId && trim((string) $partial->title) !== '') {
|
||||
return $partial;
|
||||
}
|
||||
|
||||
return Product::query()
|
||||
->select([
|
||||
'id',
|
||||
@@ -609,7 +670,9 @@ class WalletController extends Controller
|
||||
|
||||
private function isProductWalletTransaction($record): bool
|
||||
{
|
||||
return !empty($record->wallet?->product);
|
||||
$wallet = $this->resolveTransactionWallet($record);
|
||||
|
||||
return !empty($wallet?->product);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user