245 lines
9.3 KiB
PHP
245 lines
9.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Frontend;
|
||
|
|
|
||
|
|
// use Mail;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\Lead;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Models\AlternativeInvestmentFund;
|
||
|
|
use App\Models\Bonds;
|
||
|
|
use App\Models\Product;
|
||
|
|
use App\Models\CleanAndGreenAsset;
|
||
|
|
use App\Models\FractionalRealEstate;
|
||
|
|
use App\Models\Fund;
|
||
|
|
use App\Models\Category;
|
||
|
|
use App\Models\HighYieldFinance;
|
||
|
|
use App\Models\InvoiceDiscounting;
|
||
|
|
use App\Models\LeaseBasedFinancing;
|
||
|
|
use App\Models\PeerToPeerLending;
|
||
|
|
use App\Models\SecuritizedDebtInstrument;
|
||
|
|
use App\Models\VentureDebt;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Notifications\UserAdmin;
|
||
|
|
use Illuminate\Support\Facades\Validator;
|
||
|
|
|
||
|
|
class HomeController extends Controller
|
||
|
|
{
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
// dd($this->getAllTopPickProducts());
|
||
|
|
return view('Frontend.Pages.index',[
|
||
|
|
'topPicks' => $this->getAllTopPickProducts()
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getAllTopPickProducts(){
|
||
|
|
$data['data'] = Product::getAllDetails()->where('top_pick',true)->get();
|
||
|
|
// foreach($data['data'] as $row)
|
||
|
|
// {
|
||
|
|
// $category = Category::where('category_name', '=', $row->category_name)->first();
|
||
|
|
// $row['category_id'] = $category->id;
|
||
|
|
// }
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function productFilter(Request $request){
|
||
|
|
$userInput = trim($request->filter[0],'[,]');
|
||
|
|
|
||
|
|
$minimumInvestment = [
|
||
|
|
1 => [
|
||
|
|
// 'symbol' => '>',
|
||
|
|
'less_than' => 0,
|
||
|
|
'greater_than' => 100000.00
|
||
|
|
],
|
||
|
|
2 => [
|
||
|
|
// 'symbol' => '<',
|
||
|
|
'less_than' => 100000.01,
|
||
|
|
'greater_than' => 500000.00
|
||
|
|
],
|
||
|
|
3 => [
|
||
|
|
// 'symbol' => '<',
|
||
|
|
'less_than' => 500000.01,
|
||
|
|
'greater_than' => 2500000.00
|
||
|
|
],
|
||
|
|
4 => [
|
||
|
|
// 'symbol' => '<',
|
||
|
|
'less_than' => 2500000.01,
|
||
|
|
'greater_than' => 5000000.00
|
||
|
|
],
|
||
|
|
5 => [
|
||
|
|
// 'symbol' => '<',
|
||
|
|
'less_than' => 5000000.01,
|
||
|
|
'greater_than' => 500000.00
|
||
|
|
],
|
||
|
|
];
|
||
|
|
|
||
|
|
$key['indian-financial-assets'] = false;
|
||
|
|
$key['indian-real-assets'] = true;
|
||
|
|
$key['global-financial-assets'] = false;
|
||
|
|
$key['global-real-assets'] = true;
|
||
|
|
foreach (explode(',',$userInput) as $filter) {
|
||
|
|
if ($key['indian-financial-assets'] == false) {
|
||
|
|
$key['indian-financial-assets'] = $this->checkIFAFilter($minimumInvestment[$filter]['less_than'], $minimumInvestment[$filter]['greater_than']);
|
||
|
|
}
|
||
|
|
if ($key['global-financial-assets'] == false) {
|
||
|
|
$key['global-financial-assets'] = $this->checkGFAFilter($minimumInvestment[$filter]['less_than'], $minimumInvestment[$filter]['greater_than']);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$data['data'] = $key;
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function checkIFAFilter($lessThan, $greaterThan)
|
||
|
|
{
|
||
|
|
if (FractionalRealEstate::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || AlternativeInvestmentFund::whereBetween('minimum_investment', [$lessThan, $greaterThan])->exists() || CleanAndGreenAsset::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || HighYieldFinance::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || InvoiceDiscounting::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || LeaseBasedFinancing::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || PeerToPeerLending::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || SecuritizedDebtInstrument::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists() || VentureDebt::whereBetween('minimum_investment_in_int', [$lessThan, $greaterThan])->exists()) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function checkGFAFilter($lessThan, $greaterThan)
|
||
|
|
{
|
||
|
|
if (Bonds::whereBetween('minimum_investment', [$lessThan, $greaterThan])->exists() || Fund::whereBetween('minimum_investment', [$lessThan, $greaterThan])->exists()) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function investNow(Request $request)
|
||
|
|
{
|
||
|
|
$validator = Validator::make($request->all(), [
|
||
|
|
'product_id' => 'required',
|
||
|
|
], [
|
||
|
|
'required' => 'Please Select a product!!',
|
||
|
|
]);
|
||
|
|
$validationMessage = $this->validationError($validator);
|
||
|
|
if ($validationMessage) {
|
||
|
|
return response()->json(['status' => 400, 'message' => $validationMessage]);
|
||
|
|
}
|
||
|
|
if (!auth()->guard('users')->check()) {
|
||
|
|
return response()->json(['status' => 201, 'message' => 'Please Login To Invest']);
|
||
|
|
}
|
||
|
|
|
||
|
|
$checkUserBlock = User::where(['id' => auth()->guard('users')->user()->id, 'status' => 1 ])->doesntExist();
|
||
|
|
if($checkUserBlock){
|
||
|
|
return response()->json(['status' => 403, 'message' => "Please contact us"]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$addLead = Lead::create([
|
||
|
|
'users_id' => auth()->guard('users')->user()->id,
|
||
|
|
'lead_owner' => null,
|
||
|
|
'products_id' => $request->product_id,
|
||
|
|
'first_name' => auth()->guard('users')->user()->name,
|
||
|
|
'email' => auth()->guard('users')->user()->email,
|
||
|
|
'mobile' => auth()->guard('users')->user()->contact_number,
|
||
|
|
'lead_status' => 'New'
|
||
|
|
]);
|
||
|
|
|
||
|
|
if ($addLead) {
|
||
|
|
$userName = auth()->guard('users')->user()->name;
|
||
|
|
$notify['message'] = "$userName is interested in a product!";
|
||
|
|
$type = "Buyer Form";
|
||
|
|
$users = User::admins()->get();
|
||
|
|
foreach ($users as $data) {
|
||
|
|
$data->notify(new UserAdmin($notify, $type));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return response()->json(['status' => 200, 'message' => 'Invest Now Successfull']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function investNowAPI(Request $request)
|
||
|
|
{
|
||
|
|
$validator = Validator::make($request->all(), [
|
||
|
|
'product_id' => 'required',
|
||
|
|
], [
|
||
|
|
'required' => 'Please Select a product!!',
|
||
|
|
]);
|
||
|
|
$validationMessage = $this->validationError($validator);
|
||
|
|
if ($validationMessage) {
|
||
|
|
return response()->json(['status' => 400, 'message' => $validationMessage]);
|
||
|
|
}
|
||
|
|
// if (!auth()->guard('users')->check()) {
|
||
|
|
// return response()->json(['status' => 200, 'message' => 'Please Login To Invest']);
|
||
|
|
// }
|
||
|
|
|
||
|
|
$addLead = Lead::create([
|
||
|
|
'users_id' => $request->user()->id,
|
||
|
|
'lead_owner' => null,
|
||
|
|
'products_id' => $request->product_id,
|
||
|
|
'first_name' => $request->user()->name,
|
||
|
|
'email' => $request->user()->email,
|
||
|
|
'mobile' => $request->user()->contact_number,
|
||
|
|
'lead_status' => 'New'
|
||
|
|
]);
|
||
|
|
|
||
|
|
if ($addLead) {
|
||
|
|
$userName = auth()->guard('users')->user()->name;
|
||
|
|
$notify['message'] = "$userName is interested in a product!";
|
||
|
|
$type = "Buyer Form";
|
||
|
|
$users = User::admins()->get();
|
||
|
|
foreach ($users as $data) {
|
||
|
|
$data->notify(new UserAdmin($notify, $type));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['status' => 200, 'message' => 'Invest Now Successfull']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function updateAllNotification()
|
||
|
|
{
|
||
|
|
$user = User::find(auth()->guard('users')->user()->id);
|
||
|
|
$checkNotificationsRead = $user->notifications->markAsRead();
|
||
|
|
return response()->json(['status' => 200, 'message' => 'All Notifications mark as read']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getAllNotificationsApi(Request $request)
|
||
|
|
{
|
||
|
|
$user = User::find($request->user()->id);
|
||
|
|
$dataArray = array();
|
||
|
|
foreach($user->unreadNotifications as $data)
|
||
|
|
{
|
||
|
|
$notify['id'] = $data->id;
|
||
|
|
$notify['message'] = $data->data['message'];
|
||
|
|
$notify['time'] = $data->created_at->diffForHumans();
|
||
|
|
array_push($dataArray,$notify);
|
||
|
|
}
|
||
|
|
// array_push($notificationArray,$dataArray);
|
||
|
|
$notificationArray['data'] = $dataArray;
|
||
|
|
return $notificationArray;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function updateSingleNotification($id){
|
||
|
|
if(!$id){
|
||
|
|
return response()->json(['status' => 400, 'message' => 'Error Marking it as read!'],400);
|
||
|
|
};
|
||
|
|
$user = User::find(request()->user()->id);
|
||
|
|
$user->notifications->where('id', $id)->markAsRead();
|
||
|
|
return response()->json(['status' => 200, 'message' => 'Notification mark as read']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function checkPin(Request $request){
|
||
|
|
if(!$request->pin){
|
||
|
|
return response()->json(['message'=> 'Please Enter Pin!'],400);
|
||
|
|
}
|
||
|
|
$pin = User::find($request->user()->id);
|
||
|
|
if($request->pin == $pin->pin){
|
||
|
|
return response()->json(['message'=> 'Pin Matched!'],200);
|
||
|
|
}
|
||
|
|
return response()->json(['message'=> 'Pin did not matched!'],400);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public function validationError($validator)
|
||
|
|
{
|
||
|
|
if ($validator->fails()) {
|
||
|
|
$errors = $validator->errors();
|
||
|
|
$messages = '';
|
||
|
|
foreach ($errors->all() as $message) {
|
||
|
|
$messages .= $message . '</br>';
|
||
|
|
}
|
||
|
|
return $messages;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|