Files
freeu-project/app/Http/Controllers/Admin/ManageSellerProfileController.php

88 lines
3.7 KiB
PHP
Raw Normal View History

2024-03-28 14:52:40 +05:30
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\MarketplaceAlternativeInvestmentFundSeller;
use App\Models\MarketplaceFractionalRealEstateSeller;
use App\Models\MarketplaceOtherProductsSeller;
use App\Models\MarketplaceSellerForm;
use App\Models\MarketplaceBuyerForm;
use Illuminate\Http\Request;
class ManageSellerProfileController extends Controller
{
public function index()
{
$sellerProfile = MarketplaceSellerForm::query()
->with('users')
->withCount(['aif','fre','op'])
->latest()
->get();
return view('Admin.Pages.pre_owned_investment.manage_seller_profile', compact('sellerProfile'));
}
public function sellerDetails($id)
{
$sellerProfile = MarketplaceSellerForm::findOrFail($id);
$freListing = MarketplaceFractionalRealEstateSeller::where('seller_forms_id', $id)->get();
$aifListing = MarketplaceAlternativeInvestmentFundSeller::where('seller_forms_id', $id)->get();
$opListing = MarketplaceOtherProductsSeller::where('seller_forms_id', $id)->get();
$id = $id;
$productsSold = $this->productsSold($sellerProfile);
return view('Admin.Pages.pre_owned_investment.manage_investors', compact('sellerProfile', 'aifListing', 'freListing', 'opListing','id','productsSold'));
}
public function productsSold($sellerProfile){
$sellerId = $sellerProfile->id;
$productsSold = array();
$marketplaceAIFPRoducts = MarketplaceAlternativeInvestmentFundSeller::where('seller_forms_id', $sellerId)->get();
foreach ($marketplaceAIFPRoducts as $data) {
$buyers = MarketplaceBuyerForm::where(['table' => 'marketplace_aif_sellers', 'status' => 'Sold', 'associated_id' => $data->id])->get();
foreach($buyers as $buyerData){
$buyerArr = array();
$buyerArr['product_name'] = $data->property_name;
$buyerArr['buyer'] = $buyerData->name;
array_push($productsSold,$buyerArr);
}
}
$marketplaceFREPRoducts = MarketplaceFractionalRealEstateSeller::where('seller_forms_id', $sellerId)->get();
foreach ($marketplaceFREPRoducts as $data) {
$buyers = MarketplaceBuyerForm::where(['table' => 'marketplace_fre_sellers', 'status' => 'Sold', 'associated_id' => $data->id])->get();
foreach($buyers as $buyerData){
$buyerArr = array();
$buyerArr['product_name'] = $data->property_name;
$buyerArr['buyer'] = $buyerData->name;
array_push($productsSold,$buyerArr);
}
}
$marketplaceOPPRoducts = MarketplaceOtherProductsSeller::where('seller_forms_id', $sellerId)->get();
foreach ($marketplaceOPPRoducts as $data) {
$buyers = MarketplaceBuyerForm::where(['table' => 'marketplace_op_sellers', 'status' => 'Sold', 'associated_id' => $data->id])->get();
foreach($buyers as $buyerData){
$buyerArr = array();
$buyerArr['product_name'] = $data->property_name;
$buyerArr['buyer'] = $buyerData->name;
array_push($productsSold,$buyerArr);
}
}
return $productsSold;
}
public function changeStatus(Request $request)
{
$changeStatus = MarketplaceSellerForm::where('id', $request->id)->update([
'status' => $request->status == 0 ? 1 : 0,
]);
if ($changeStatus) {
return response()->json(['status' => 200, 'message' => 'Status Changed']);
}
return response()->json(['status' => 400, 'message' => 'Error Changing Status']);
}
}