added merge wallet 2
This commit is contained in:
@@ -73,15 +73,54 @@ class CustomerController extends SuperController
|
||||
}
|
||||
public function funds(Request $request,$customer_id)
|
||||
{
|
||||
$mainWalletProductIds = app(\App\Services\ConfigService::class)->mainWalletProductIds();
|
||||
|
||||
// فقط کیف محصولها (نه کیف اصلی) — هر ردیف = موجودی واقعی یک محصول/فلز
|
||||
$query_table = Wallet::with(['product:id,title,metal_id,unit'])
|
||||
->where('owner', $customer_id)
|
||||
->whereNotNull('product_id');
|
||||
if ($mainWalletProductIds !== []) {
|
||||
// کیفهای قدیمیِ محصولات متصل به کیف اصلی نمایش داده نمیشوند
|
||||
$query_table->whereNotIn('product_id', $mainWalletProductIds);
|
||||
}
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select(['id', 'owner', 'cash', 'gold', 'fund_id', 'product_id', 'created_at', 'updated_at'])
|
||||
->export($query_table);
|
||||
|
||||
// محصولات متصل به کیف اصلی: یک ردیف نماینده با موجودی کیف اصلی
|
||||
if ($mainWalletProductIds !== []) {
|
||||
$representative = null;
|
||||
foreach ($mainWalletProductIds as $pid) {
|
||||
$representative = \App\Models\Product::select(['id', 'title', 'metal_id', 'unit'])->find($pid);
|
||||
if ($representative) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$mainWallet = Wallet::where('owner', $customer_id)
|
||||
->whereNull('fund_id')
|
||||
->whereNull('product_id')
|
||||
->first();
|
||||
|
||||
if ($representative && $mainWallet) {
|
||||
$mainRow = [
|
||||
'id' => $mainWallet->id,
|
||||
'owner' => (int) $customer_id,
|
||||
'cash' => 0,
|
||||
'gold' => (float) $mainWallet->gold,
|
||||
'fund_id' => null,
|
||||
'product_id' => (int) $representative->id,
|
||||
'created_at' => $mainWallet->created_at,
|
||||
'updated_at' => $mainWallet->updated_at,
|
||||
'product' => $representative,
|
||||
'is_main_wallet' => true,
|
||||
];
|
||||
$query_table['rows'] = collect($query_table['rows'] ?? [])->prepend($mainRow)->values();
|
||||
$query_table['query']['total'] = (int) ($query_table['query']['total'] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($query_table);
|
||||
}
|
||||
public function archive($id){
|
||||
|
||||
Reference in New Issue
Block a user