fix bug 2
This commit is contained in:
@@ -130,13 +130,10 @@ class WalletController extends Controller
|
||||
$customerId = (int) auth('customer')->id();
|
||||
$this->repairMisclassifiedRialTransactions($customerId);
|
||||
|
||||
if (isset($request->wallet_id)){
|
||||
$wallet = Wallet::with('product')->where('id', $request->wallet_id)->where('owner', auth('customer')->id())->get();
|
||||
}else{
|
||||
$wallet = Wallet::with('product')->where('owner', auth('customer')->id())->get();
|
||||
}
|
||||
$mainWalletProductIds = app(ConfigService::class)->mainWalletProductIds();
|
||||
$walletIds = $this->resolveTransactionTableWalletIds($customerId, $request, $mainWalletProductIds);
|
||||
|
||||
if ($wallet->isEmpty()) {
|
||||
if ($walletIds->isEmpty()) {
|
||||
$records = ['query' => ['total' => 0], 'rows' => []];
|
||||
} else {
|
||||
$records = Transaction::with([
|
||||
@@ -148,7 +145,7 @@ class WalletController extends Controller
|
||||
},
|
||||
'wallet.product',
|
||||
'product',
|
||||
])->whereIn('wallet', $wallet->pluck('id'))->whereNull('fund_id');
|
||||
])->whereIn('wallet', $walletIds)->whereNull('fund_id');
|
||||
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
@@ -211,6 +208,81 @@ class WalletController extends Controller
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
/**
|
||||
* کیف(های) مؤثر برای جدول تراکنش.
|
||||
* محصولات main_wallet_products: تراکنشها روی کیف اصلی (+ کیف legacy محصول) ثبت شدهاند.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection<int, int>
|
||||
*/
|
||||
private function resolveTransactionTableWalletIds(
|
||||
int $customerId,
|
||||
Request $request,
|
||||
array $mainWalletProductIds
|
||||
) {
|
||||
$requestedWalletId = $request->input('wallet_id');
|
||||
$requestedProductId = (int) $request->input('product_id');
|
||||
|
||||
if ($requestedWalletId) {
|
||||
$requestedWallet = Wallet::query()
|
||||
->where('id', $requestedWalletId)
|
||||
->where('owner', $customerId)
|
||||
->first();
|
||||
|
||||
if (!$requestedWallet) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
if (
|
||||
$mainWalletProductIds !== []
|
||||
&& (
|
||||
($requestedWallet->product_id && self::isMainWalletProduct((int) $requestedWallet->product_id))
|
||||
|| (
|
||||
$requestedWallet->product_id === null
|
||||
&& $requestedWallet->fund_id === null
|
||||
&& $requestedProductId > 0
|
||||
&& self::isMainWalletProduct($requestedProductId)
|
||||
)
|
||||
)
|
||||
) {
|
||||
return $this->mainWalletProductTransactionWalletIds($customerId, $mainWalletProductIds);
|
||||
}
|
||||
|
||||
return collect([(int) $requestedWallet->id]);
|
||||
}
|
||||
|
||||
if (
|
||||
$mainWalletProductIds !== []
|
||||
&& $requestedProductId > 0
|
||||
&& self::isMainWalletProduct($requestedProductId)
|
||||
) {
|
||||
return $this->mainWalletProductTransactionWalletIds($customerId, $mainWalletProductIds);
|
||||
}
|
||||
|
||||
return Wallet::query()
|
||||
->where('owner', $customerId)
|
||||
->pluck('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* کیف اصلی + کیفهای legacy محصولات متصل به کیف اصلی.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection<int, int>
|
||||
*/
|
||||
private function mainWalletProductTransactionWalletIds(int $customerId, array $mainWalletProductIds)
|
||||
{
|
||||
return Wallet::query()
|
||||
->where('owner', $customerId)
|
||||
->whereNull('fund_id')
|
||||
->where(function ($query) use ($mainWalletProductIds) {
|
||||
$query->whereNull('product_id')
|
||||
->orWhereIn('product_id', $mainWalletProductIds);
|
||||
})
|
||||
->pluck('id')
|
||||
->map(fn ($id) => (int) $id)
|
||||
->unique()
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* دادهٔ قدیمی: type=4 با cash مثبت (واریز ادمین) — قبل از فیلتر جدول اصلاح میشود.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user