fix some bugs

This commit is contained in:
2026-07-14 12:35:03 +03:30
parent 277cf31d93
commit 8f3fb35b2b
3 changed files with 32 additions and 11 deletions
@@ -39,8 +39,20 @@ class CustomerController extends SuperController
* @return \Illuminate\Http\JsonResponse
*/
public function listUser(){
$user = Customer::with(['wallet'])->select('id','name','mobile','type')->get();
return response()->json($user);
$balanceService = app(WalletBalanceService::class);
$catalogMetalIds = $balanceService->catalogMetalIds();
$users = Customer::with(['wallet'])->select('id', 'name', 'mobile', 'type')->get()->map(function ($user) use ($balanceService, $catalogMetalIds) {
$wallets = collect($user->wallet ?? []);
$ownerType = (int) $user->type;
$user->wallet_cash = $balanceService->mainWalletCash($wallets, $ownerType);
$metalMap = $balanceService->buildCustomerWalletMetalDisplayMap($wallets, $catalogMetalIds);
$user->wallet_gold = array_sum($metalMap);
return $user;
});
return response()->json($users);
}
public function updateAdmin(Request $request , $id)
{
@@ -147,7 +159,7 @@ class CustomerController extends SuperController
if (isset($query_table['rows'])) {
$query_table['rows'] = collect($query_table['rows'])->map(function ($row) use ($balanceService, $catalogMetalIds) {
$wallets = collect($row['wallet'] ?? []);
$row['wallet_cash'] = $balanceService->mainWalletCash($wallets);
$row['wallet_cash'] = $balanceService->mainWalletCash($wallets, (int) ($row['type'] ?? 0));
$metalMap = $balanceService->buildCustomerWalletMetalDisplayMap($wallets, $catalogMetalIds);
$row['wallet_metal_gold'] = $metalMap;
foreach ($catalogMetalIds as $metalId) {