NASER add taskززطزSQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION montask.ST_SetSRID does not exist (Connection: mysql, SQL: update ttendances set ip_exit = 51.684726144224, distance_exit = 850, exited_at = 2026-04-23 13:59:46, exit_location = ST_SetSRID(ST_Point(51.684726144224, 32.652053279154), 4326), duration = 04:59:46, ttendances.updated_at = 2026-04-23 13:59:46 where id = 937)
This commit is contained in:
Notes:
mobinesaghi
2026-04-23 14:42:21 +03:30
NASER add task functions undepended
@@ -82,8 +82,7 @@ class AttendanceController extends Controller
|
||||
? 'admin/'
|
||||
: 'attendance/';
|
||||
$now = Carbon::now()->format('Y-m-d 00:00:00');
|
||||
$existed = $Attendance->whereNull('exited_at')->where('entered_at', '>=', $now)->first();
|
||||
|
||||
$existed = $Attendance->whereNull('exited_at')->where('entered_at', '>=', now()->format('Y-m-d 00:00:00'))->where('entered_at', '<=', now()->format('Y-m-d 23:59:59'))->first();
|
||||
|
||||
$user = User::where('user_name', $_COOKIE['user_identity'])->first();
|
||||
$until_now = null;
|
||||
@@ -321,7 +320,7 @@ class AttendanceController extends Controller
|
||||
$attendance->duration = $duration;
|
||||
$attendance->save();
|
||||
|
||||
send_tel($user->name, $attendance, 'attendance');
|
||||
$this->send($user->name, $attendance, 'attendance');
|
||||
|
||||
return redirect()->back()->with('message', [
|
||||
'color' => '#3b82f6',
|
||||
@@ -340,7 +339,7 @@ class AttendanceController extends Controller
|
||||
$attendance->office_location = ['lat' => $officeLat, 'lng' => $officeLng];
|
||||
$attendance->save();
|
||||
|
||||
send_tel($user->name, $attendance, 'attendance');
|
||||
$this->send($user->name, $attendance, 'attendance');
|
||||
|
||||
return redirect()->back()->with('message', [
|
||||
'color' => '#22c55e',
|
||||
@@ -354,15 +353,15 @@ class AttendanceController extends Controller
|
||||
if (!$user) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$attendance = Attendance::where('user_identity', $user->user_name)
|
||||
->whereNull('exited_at')
|
||||
->latest('entered_at')
|
||||
->where('entered_at', '>=', now()->format('Y-m-d 00:00:00'))->where('entered_at', '<=', now()->format('Y-m-d 23:59:59'))
|
||||
->first();
|
||||
|
||||
$today = Carbon::now()->format('Y-m-d');
|
||||
$day = Carbon::parse($attendance->entered_at)->format('Y-m-d');
|
||||
|
||||
if ($today !== $day || !$attendance) {
|
||||
if (!$attendance) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'color' => '#C30004',
|
||||
@@ -386,7 +385,7 @@ class AttendanceController extends Controller
|
||||
'duration' => $durationSeconds
|
||||
]);
|
||||
|
||||
dd(send_tel($user->name, $break, 'break'));
|
||||
// dd($this->send($user->name, $break, 'break'));
|
||||
return response()->json([
|
||||
"break_status" => 'ended',
|
||||
'duration' => $durationSeconds
|
||||
@@ -398,7 +397,7 @@ class AttendanceController extends Controller
|
||||
'break_start' => $now,
|
||||
]);
|
||||
|
||||
dd(send_tel($user->name, $break, 'break'));
|
||||
// dd($this->send($user->name, $break, 'break'));
|
||||
|
||||
$user->update([
|
||||
'break' => 1
|
||||
@@ -486,7 +485,7 @@ class AttendanceController extends Controller
|
||||
|
||||
$status = 'request';
|
||||
$d = "ایجاد روز کاری";
|
||||
send_tel($user->name, $d, $status);
|
||||
$this->send($user->name, $d, $status);
|
||||
$user->req_counts += 1;
|
||||
$user->save();
|
||||
return redirect('/')->with('message', [
|
||||
@@ -517,7 +516,7 @@ class AttendanceController extends Controller
|
||||
$att->save();
|
||||
$status = 'request';
|
||||
$d = "تغییر ساعت کاری";
|
||||
send_tel($user->name, $d, $status);
|
||||
$this->send($user->name, $d, $status);
|
||||
$user->req_counts += 1;
|
||||
$user->save();
|
||||
return redirect('/')->with('message', [
|
||||
@@ -564,7 +563,7 @@ class AttendanceController extends Controller
|
||||
$attendance->save();
|
||||
$status = 'request';
|
||||
$d = "حذف روز کاری";
|
||||
send_tel($user->name, $d, $status);
|
||||
$this->send($user->name, $d, $status);
|
||||
$user->req_counts += 1;
|
||||
$user->save();
|
||||
return redirect()->back()->with('message', [
|
||||
@@ -643,122 +642,46 @@ class AttendanceController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function send_tel($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');
|
||||
if (!$data->break_end)
|
||||
$message = "تاریخ: {$date}\n {$user} در ساعت {$start} شروع به استراحت کرد.";
|
||||
else
|
||||
$message = "تاریخ: {$date}\n {$user} در ساعت {$end} به استراحت پایان داد.";
|
||||
}
|
||||
|
||||
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 {
|
||||
$response = Http::post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
|
||||
"chat_id" => $admin->bale,
|
||||
'text' => $message,
|
||||
]);
|
||||
}catch (\Exception $e){}
|
||||
}
|
||||
Log::create([
|
||||
'error' => $response->body(),
|
||||
'user' => "کاربر: $user
|
||||
ادمین: {$admin->user_name}",
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
try {
|
||||
$response = Http::post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
|
||||
"chat_id" => '985309723',
|
||||
'text' => $message,
|
||||
]);
|
||||
}catch (\Exception $e){}
|
||||
}
|
||||
// return $message;
|
||||
}
|
||||
|
||||
function auto_break($user_id, $force_method = null)
|
||||
{
|
||||
$user = User::where('user_name', $user_id)->first();
|
||||
if (!$attendances = Attendance::whereNull('exited_at')->latest('entered_at')->where('user_identity', $user_id)->first()) {
|
||||
throw new UnprocessableEntityHttpException('attendance not found');
|
||||
}
|
||||
$break = "start";
|
||||
if ($AttendanceBreak = AttendanceBreak::where('attendance_id', $attendances->id)->whereNull('break_end')->first()) {
|
||||
$break = "end";
|
||||
|
||||
}
|
||||
if ($force_method) {
|
||||
$break = $force_method;
|
||||
}
|
||||
|
||||
if ($break == "end") {
|
||||
$start = Carbon::parse($break->break_start)->format('H:i:s');
|
||||
$end = Carbon::parse($break->break_end)->format('H:i:s');
|
||||
$status = 'ended';
|
||||
$att = new Attendance();
|
||||
$break->break_end = now();
|
||||
$break->duration = $att->duration($start, $end);
|
||||
$break->save();
|
||||
$time = Carbon::parse($break->break_end)->format('H:i:s');
|
||||
sendbot($user->chatid, "پایان استراحت: $time");
|
||||
|
||||
} elseif ($break == "start" and empty($AttendanceBreak)) {
|
||||
$status = 'started';
|
||||
$break = new AttendanceBreak();
|
||||
$break->attendance_id = $attendances->id;
|
||||
$break->break_start = now();
|
||||
$break->save();
|
||||
$time = Carbon::parse($break->break_start)->format('H:i:s');
|
||||
|
||||
sendbot($user->chatid, "شروع استراحت: $time");
|
||||
|
||||
}
|
||||
return $status ?? $break;
|
||||
}
|
||||
//function auto_break($user_id, $force_method = null)
|
||||
//{
|
||||
// $user = User::where('user_name', $user_id)->first();
|
||||
// if (!$attendances = Attendance::whereNull('exited_at')->latest('entered_at')->where('user_identity', $user_id)->first()) {
|
||||
// throw new UnprocessableEntityHttpException('attendance not found');
|
||||
// }
|
||||
// $break = "start";
|
||||
// if ($AttendanceBreak = AttendanceBreak::where('attendance_id', $attendances->id)->whereNull('break_end')->first()) {
|
||||
// $break = "end";
|
||||
//
|
||||
// }
|
||||
// if ($force_method) {
|
||||
// $break = $force_method;
|
||||
// }
|
||||
//
|
||||
// if ($break == "end") {
|
||||
// $start = Carbon::parse($break->break_start)->format('H:i:s');
|
||||
// $end = Carbon::parse($break->break_end)->format('H:i:s');
|
||||
// $status = 'ended';
|
||||
// $att = new Attendance();
|
||||
// $break->break_end = now();
|
||||
// $break->duration = $att->duration($start, $end);
|
||||
// $break->save();
|
||||
// $time = Carbon::parse($break->break_end)->format('H:i:s');
|
||||
// sendbot($user->chatid, "پایان استراحت: $time");
|
||||
//
|
||||
// } elseif ($break == "start" and empty($AttendanceBreak)) {
|
||||
// $status = 'started';
|
||||
// $break = new AttendanceBreak();
|
||||
// $break->attendance_id = $attendances->id;
|
||||
// $break->break_start = now();
|
||||
// $break->save();
|
||||
// $time = Carbon::parse($break->break_start)->format('H:i:s');
|
||||
//
|
||||
// sendbot($user->chatid, "شروع استراحت: $time");
|
||||
//
|
||||
// }
|
||||
// return $status ?? $break;
|
||||
//}
|
||||
Reference in New Issue
Block a user