fix amount 7
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Address;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Product;
|
||||
use App\Models\User;
|
||||
use App\Models\Withdraw;
|
||||
use App\Models\BankAccount;
|
||||
@@ -75,7 +76,8 @@ class WalletController extends Controller
|
||||
'withdraw' => function ($q) {
|
||||
$q->select(['*', Withdraw::$SELECT_STS_STR]);
|
||||
},
|
||||
'wallet.product'
|
||||
'wallet.product',
|
||||
'product',
|
||||
])->whereIn('wallet', $wallet->pluck('id'))->whereNull('fund_id');
|
||||
|
||||
TableEngine::create($records, $request->all())
|
||||
@@ -88,6 +90,7 @@ class WalletController extends Controller
|
||||
foreach ($records['rows'] as &$record) {
|
||||
if ($this->isShopGoldTransaction($record)) {
|
||||
$this->applyShopTransactionPresentation($record);
|
||||
$this->applyAbshodeProductTransactionTitle($record);
|
||||
$this->applyMetalTypeTransactionTitle($record);
|
||||
$this->applyProductTransactionTitle($record);
|
||||
$this->applyProductOrderDisplayFields($record);
|
||||
@@ -128,6 +131,7 @@ class WalletController extends Controller
|
||||
$record->save();
|
||||
}
|
||||
|
||||
$this->applyAbshodeProductTransactionTitle($record);
|
||||
$this->applyMetalTypeTransactionTitle($record);
|
||||
$this->applyProductTransactionTitle($record);
|
||||
$this->applyProductOrderDisplayFields($record);
|
||||
@@ -357,8 +361,64 @@ class WalletController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function applyAbshodeProductTransactionTitle($record): void
|
||||
{
|
||||
if (self::isCashTransactionTitle($record->title ?? null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productId = $this->resolveAbshodeProductId($record);
|
||||
if (!$productId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = $record->product->title
|
||||
?? Product::query()->whereKey($productId)->value('title');
|
||||
if (!$productTitle) {
|
||||
return;
|
||||
}
|
||||
|
||||
$direction = (int) ($record->order->direction ?? 0);
|
||||
if ($direction === 1 || ($direction === 0 && (float) ($record->gold ?? 0) > 0)) {
|
||||
$record->title = self::productBuyTitle($productTitle);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($direction === 2 || ($direction === 0 && (float) ($record->gold ?? 0) < 0)) {
|
||||
$record->title = self::productSellTitle($productTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveAbshodeProductId($record): ?int
|
||||
{
|
||||
if (!empty($record->product_id)) {
|
||||
return (int) $record->product_id;
|
||||
}
|
||||
|
||||
$note = (string) ($record->note ?? '');
|
||||
if ($note !== '' && preg_match('/(?:^|;)product_id:(\d+)/', $note, $matches)) {
|
||||
return (int) $matches[1];
|
||||
}
|
||||
|
||||
if (empty($record->order_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$siblingProductId = Transaction::query()
|
||||
->where('order_id', $record->order_id)
|
||||
->whereNotNull('product_id')
|
||||
->where('product_id', '>', 0)
|
||||
->value('product_id');
|
||||
|
||||
return $siblingProductId ? (int) $siblingProductId : null;
|
||||
}
|
||||
|
||||
private function applyMetalTypeTransactionTitle($record): void
|
||||
{
|
||||
if ($this->resolveAbshodeProductId($record)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($record->product_id)) {
|
||||
return;
|
||||
}
|
||||
@@ -389,39 +449,36 @@ class WalletController extends Controller
|
||||
|
||||
private function applyProductTransactionTitle($record): void
|
||||
{
|
||||
if (empty($record->product_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self::isCashTransactionTitle($record->title)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = $record->wallet->product->title ?? $record->product->title ?? null;
|
||||
$productId = $this->resolveAbshodeProductId($record);
|
||||
if (!$productId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productTitle = $record->product->title
|
||||
?? $record->wallet->product->title
|
||||
?? Product::query()->whereKey($productId)->value('title');
|
||||
if (!$productTitle) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expectedBuy = self::productBuyTitle($productTitle);
|
||||
$expectedSell = self::productSellTitle($productTitle);
|
||||
$metalBuy = self::mainMetalBuyTitle();
|
||||
$metalSell = self::mainMetalSellTitle();
|
||||
|
||||
if (in_array($record->title, [$expectedBuy, $expectedSell, $metalBuy, $metalSell], true)) {
|
||||
if (in_array($record->title, [$expectedBuy, $expectedSell], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self::isGenericMetalTransactionTitle($record->title)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$direction = $record->order->direction ?? null;
|
||||
if ((int) $direction === 1) {
|
||||
$direction = (int) ($record->order->direction ?? 0);
|
||||
if ($direction === 1 || ($direction === 0 && (float) ($record->gold ?? 0) > 0)) {
|
||||
$record->title = $expectedBuy;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int) $direction === 2) {
|
||||
if ($direction === 2 || ($direction === 0 && (float) ($record->gold ?? 0) < 0)) {
|
||||
$record->title = $expectedSell;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user