2025-07-10 18:23:56 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
2026-04-23 14:00:39 +03:30
|
|
|
|
use App\Models\Log;
|
2026-04-08 07:22:13 +00:00
|
|
|
|
use App\Models\Setting;
|
2026-04-23 14:00:39 +03:30
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2026-04-23 14:27:18 +03:30
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
use Morilog\Jalali\Jalalian;
|
2026-04-23 14:00:39 +03:30
|
|
|
|
|
|
|
|
|
|
abstract class Controller
|
2025-07-10 18:23:56 +00:00
|
|
|
|
{
|
2026-04-08 07:22:13 +00:00
|
|
|
|
public static function Config($name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Setting::where('key',$name)->first()->value ?? false;
|
|
|
|
|
|
}
|
2026-04-23 14:00:39 +03:30
|
|
|
|
|
|
|
|
|
|
public function fa2en_numbers($input)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (is_string($input)) {
|
|
|
|
|
|
$fa_numbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
|
|
|
|
|
$en_numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
|
|
|
|
return str_replace($fa_numbers, $en_numbers, $input);
|
|
|
|
|
|
} elseif (is_array($input)) {
|
|
|
|
|
|
return array_map([$this, __FUNCTION__], $input);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return $input;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function send($user, $data, $status)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($status == 'attendance') {
|
|
|
|
|
|
// dd('hi');
|
|
|
|
|
|
$enter = Carbon::parse($data->entered_at)->format('H:i');
|
|
|
|
|
|
$date = Jalalian::fromCarbon(Carbon::parse($data->entered_at))->format('Y/m/d');
|
|
|
|
|
|
$exit = $data->exited_at ? Carbon::parse($data->exited_at)->format('H:i') : null;
|
|
|
|
|
|
// $user = json_decode($user);
|
|
|
|
|
|
$message = "تاریخ: {$date}\n {$user} در ساعت ";
|
|
|
|
|
|
if (!$exit) {
|
|
|
|
|
|
$message .= "{$enter} وارد شد.";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$message .= "{$exit} خارج شد.";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($status == 'break') {
|
|
|
|
|
|
$date = Jalalian::fromCarbon(Carbon::parse($data->break_start))->format('Y/m/d');
|
|
|
|
|
|
$start = Carbon::parse($data->break_start)->format('H:i');
|
|
|
|
|
|
$end = Carbon::parse($data->break_end)->format('H:i');
|
2026-04-25 11:46:02 +00:00
|
|
|
|
if (!$data->break_end) {
|
2026-04-23 14:00:39 +03:30
|
|
|
|
$message = "تاریخ: {$date}\n {$user} در ساعت {$start} شروع به استراحت کرد.";
|
2026-04-25 11:46:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2026-04-23 14:00:39 +03:30
|
|
|
|
$message = "تاریخ: {$date}\n {$user} در ساعت {$end} به استراحت پایان داد.";
|
2026-04-25 11:46:02 +00:00
|
|
|
|
}
|
2026-04-23 14:00:39 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($status == 'request') {
|
|
|
|
|
|
$message = "{$user} درخواست {$data} ثبت کرد.";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$admins = User::whereIn('is_admin', [1,2])->whereNotNull('chatid')->select('chatid', 'bale', 'user_name')->get();
|
|
|
|
|
|
if ($_COOKIE['user_identity'] !== 'test') {
|
|
|
|
|
|
foreach ($admins as $admin) {
|
|
|
|
|
|
if (!$admin->bale) {continue;}
|
|
|
|
|
|
// dd($admin->chatid);
|
|
|
|
|
|
// Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
|
|
|
|
|
// 'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
|
|
|
|
|
|
// 'chatId' => $admin->chatid,
|
|
|
|
|
|
// 'message' => $message,
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
if ($admin->bale) {
|
|
|
|
|
|
try {
|
2026-04-25 19:45:15 +00:00
|
|
|
|
$response = Http::withoutVerifying()->post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
|
2026-04-23 14:00:39 +03:30
|
|
|
|
"chat_id" => $admin->bale,
|
|
|
|
|
|
'text' => $message,
|
|
|
|
|
|
]);
|
|
|
|
|
|
}catch (\Exception $e){}
|
|
|
|
|
|
}
|
|
|
|
|
|
Log::create([
|
|
|
|
|
|
'error' => $response->body(),
|
|
|
|
|
|
'user' => "کاربر: $user
|
|
|
|
|
|
ادمین: {$admin->user_name}",
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
|
|
try {
|
2026-04-25 19:45:15 +00:00
|
|
|
|
$response = Http::withoutVerifying()->post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
|
2026-04-23 14:00:39 +03:30
|
|
|
|
"chat_id" => '985309723',
|
|
|
|
|
|
'text' => $message,
|
|
|
|
|
|
]);
|
|
|
|
|
|
}catch (\Exception $e){}
|
|
|
|
|
|
}
|
|
|
|
|
|
// return $message;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function send_admins($message)
|
|
|
|
|
|
{
|
|
|
|
|
|
$admins = User::whereNotNull('is_admin')->whereNotNull('bale')->select('bale')->get();
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($admins as $admin) {
|
|
|
|
|
|
try{
|
2026-04-25 19:45:15 +00:00
|
|
|
|
Http::withoutVerifying()->post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
|
2026-04-23 14:00:39 +03:30
|
|
|
|
"chat_id" => $admin->bale,
|
|
|
|
|
|
'text' => $message,
|
|
|
|
|
|
]);
|
|
|
|
|
|
}catch (\Exception $e){}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function send_level1_admins($message)
|
|
|
|
|
|
{
|
|
|
|
|
|
$admins = User::where('is_admin', 1)->whereNotNull('bale')->select('bale')->get();
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($admins as $admin) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Http::withoutVerifying()->post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
|
|
|
|
|
|
"chat_id" => $admin->bale,
|
|
|
|
|
|
'text' => $message,
|
|
|
|
|
|
]);
|
2026-04-25 19:45:15 +00:00
|
|
|
|
} catch (\Exception $e) {}
|
2026-04-23 14:00:39 +03:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|