restore composer.json, add mysqli extension

This commit is contained in:
2026-04-15 17:02:52 +05:00
commit 77cf56a348
4317 changed files with 1397107 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Services\Dashboard\Notification;
class NotificationService
{
// Function to send Firebase Notification
function sendNotificationToTopic($topic, $title, $body)
{
// Firebase server key (replace with your key)
$serverKey = env('FIREBASE_TOKEN');
// The Firebase endpoint for sending messages
$url = 'https://fcm.googleapis.com/fcm/send';
// Notification data
$notification = [
'title' => $title,
'body' => $body,
'sound' => 'default',
];
// Payload data (custom data for your app)
$data = [
'custom_key' => 'custom_value'
];
// The message payload (sending to a topic)
$payload = [
'to' => '/topics/' . $topic, // Send to topic "all"
'notification' => $notification,
'data' => $data,
'priority' => 'high', // Set priority for the notification
];
// Set headers for the POST request
$headers = [
'Authorization: key=' . $serverKey,
'Content-Type: application/json'
];
// Initialize curl
$ch = curl_init();
// Set curl options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For HTTPS
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
// Execute curl and capture response
$response = curl_exec($ch);
// Check for curl errors
if ($response === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close curl
curl_close($ch);
// Return Firebase response
return $response;
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Services\Dashboard\Order;
use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Http\Request;
class OrderFilterService
{
protected $request, $id, $client_phone, $status, $payment_status, $payment_type, $client_type, $delivery_type, $from, $to, $with_didox, $with_installation;
public function __construct(Request $request)
{
$this->id = empty($request->get('id')) ? null : $request->get('id');
$this->client_phone = empty($request->get('client_phone')) ? null : $request->get('client_phone');
$this->status = empty($request->get('order_status')) ? null : $request->get('order_status');
$this->payment_status = empty($request->get('payment_status')) ? null : $request->get('payment_status');
$this->payment_type = empty($request->get('payment_type')) ? null : $request->get('payment_type');
$this->client_type = empty($request->get('client_type')) ? null : $request->get('client_type');
$this->delivery_type = empty($request->get('delivery_type')) ? null : $request->get('delivery_type');
$this->with_didox = $request->get('with_didox');
$this->with_installation = $request->get('with_installation');
$this->from = empty($request->get('from')) ? Carbon::parse('2000-01-01')->format('Y-m-d') : Carbon::parse($request->get('from'))->format('Y-m-d');
$this->to = empty($request->get('to')) ? Carbon::parse('2040-01-01')->format('Y-m-d') : Carbon::parse($request->get('to'))->format('Y-m-d');
}
public function filter()
{
$orders = Order::query()
->when($this->id, function ($query) {
return $query->where('id', $this->id);
})
->when($this->client_phone, function ($query) {
return $query->where('phone', 'like', '%' . $this->formatPhone($this->client_phone) . '%');
})
->when($this->status, function ($query) {
return $query->where('status', $this->status);
})
->when($this->payment_status, function ($query) {
return $query->where('payment_status', $this->payment_status);
})
->when($this->payment_type, function ($query) {
return $query->where('payment_type', $this->payment_type);
})
->when($this->client_type, function ($query) {
return $query->where('client_type', $this->client_type);
})
->when($this->delivery_type, function ($query) {
return $query->where('delivery_type', $this->delivery_type);
})
->when($this->with_didox, function ($query) {
if (in_array('unchecked', $this->with_didox)) {
$query->orWhere('with_didox', 0);
}
if (in_array('checked', $this->with_didox)) {
$query->orWhere('with_didox', 1);
}
return $query;
})
->when($this->with_installation, function ($query) {
if (in_array('unchecked', $this->with_installation)) {
$query->orWhere('with_installation', 0);
}
if (in_array('checked', $this->with_installation)) {
$query->orWhere('with_installation', 1);
}
return $query;
})
->whereBetween('created_at', [$this->from, $this->to])
->paginate(20);
return $orders;
}
private function formatPhone($phone)
{
return preg_replace('/[^0-9]/', '', $phone);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Services\Dashboard\Region;
use App\Models\Region;
class RegionService
{
public static function deliveryPrice(Region $region, $data)
{
$toDelete = $region->deliveryPrice()->whereNotIn('power_id', array_column($data, 'power_id'))->get();
$toDelete->each->delete();
foreach ($data as $item) {
$region->deliveryPrice()->updateOrCreate(
['power_id' => $item['power_id']],
['price' => $item['price']]
);
}
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace App\Services\Dashboard\Stat;
use App\Models\Order;
use App\Models\User;
use Carbon\Carbon;
class StatService
{
private int $numberOfDays = 0;
private $from;
private $to;
public function getLabels($from, $to)
{
$this->from = $from;
$this->to = $to;
// get the number of days between the two dates
$this->numberOfDays = Carbon::parse($from)->diffInDays(Carbon::parse($to));
// Start date
$startDate = Carbon::parse($from);
// End date
$endDate = Carbon::parse($to);
// Calculate the start date as 30 days ago
// $startDate = Carbon::today()->subDays($numberOfDays - 1); // 29 because today is included
// Initialize an array to hold the days
$days = [];
// Loop through each day from the start date to today
for ($date = $startDate; $date->lte($endDate); $date->addDay()) {
// Format each day like '21 August', '22 August', etc.
$days[] = $date->day . ' ' . $date->translatedFormat('F');
}
return $days;
}
public function getStatics($type)
{
if ($type === 'orders') {
return $this->getOrderStatics();
} elseif ($type === 'users') {
return $this->getUserStatics();
} elseif ($type === 'sales') {
return $this->getSalesStatics();
}
}
private function getUserStatics(): array
{
// Step 1: Generate the last 10 days as an array
$days = collect();
for ($i = $this->numberOfDays - 1; $i >= 0; $i--) {
$days->put(Carbon::parse($this->to)->subDays($i)->format('Y-m-d'), 0);
}
// Step 2: Get the user count for each day from the database
$userRegistrations = User::where('created_at', '>=', Carbon::parse($this->to)->subDays($this->numberOfDays))
->selectRaw('DATE(created_at) as date, COUNT(*) as count')
->groupBy('date')
->orderBy('date', 'asc')
->pluck('count', 'date');
// Step 3: Merge the user counts with the list of last 10 days, filling missing days with null
$usersPerDay = $days->merge($userRegistrations)->toArray();
return array_values($usersPerDay);
}
public function getOrderStatics(): array
{
// Step 1: Generate the last 10 days as an array
$days = collect();
for ($i = $this->numberOfDays - 1; $i >= 0; $i--) {
$days->put(Carbon::parse($this->to)->subDays($i)->format('Y-m-d'), 0);
}
// Step 2: Get the user count for each day from the database
$orders = Order::where('created_at', '>=', Carbon::parse($this->to)->subDays($this->numberOfDays))
->selectRaw('DATE(created_at) as date, COUNT(*) as count')
->groupBy('date')
->orderBy('date', 'asc')
->pluck('count', 'date');
// Step 3: Merge the order counts with the list of last 10 days, filling missing days with null
$ordersPerDay = $days->merge($orders)->toArray();
return array_values($ordersPerDay);
}
public function getSalesStatics(): array
{
return [20];
}
}