generated from liutk/owl-admin-base
Update
parent
13f12b9dae
commit
65f923e28d
|
|
@ -48,28 +48,60 @@ class SignController extends Controller
|
||||||
throw new RuntimeException('没有绑定门店');
|
throw new RuntimeException('没有绑定门店');
|
||||||
}
|
}
|
||||||
$date = now();
|
$date = now();
|
||||||
// 是否允许打卡
|
|
||||||
$enable = false;
|
|
||||||
// 上班/下班 打卡, 当天是否打卡
|
|
||||||
$time = EmployeeSignLog::filter(['date' => $date->format('Y-m-d')])->exists() ? SignTime::Afternoon : SignTime::Morning;
|
|
||||||
|
|
||||||
// 根据定位的距离判断, 是否外勤
|
// 上班/下班 打卡, 当天是否打卡
|
||||||
$maxDistance = AdminSettingService::make()->arrayGet('sign', 'distance', 0);
|
$time = SignTime::Morning;
|
||||||
$type = SignType::Outside;
|
if (
|
||||||
$distance = null;
|
EmployeeSignLog::filter([
|
||||||
$description = '请打开手机定位, 并给予APP获取位置信息权限';
|
'employee_id' => $user->id,
|
||||||
if ($request->filled(['lon', 'lat'])) {
|
'date' => $date->format('Y-m-d'),
|
||||||
$distance = $service->haversineDistance($request->input('lat'), $request->input('lon'), $store->lat, $store->lon);
|
])->exists()
|
||||||
if ($distance <= $maxDistance) {
|
) {
|
||||||
$enable = true;
|
$time = SignTime::Afternoon;
|
||||||
$description = '已进入考勤范围: ' . $store->title;
|
|
||||||
$type = SignType::Normal;
|
|
||||||
} else {
|
|
||||||
$description = '当前位置不在考勤范围内, 请选择外勤打卡';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return compact('enable', 'time', 'type', 'description', 'distance', 'maxDistance');
|
// 根据定位的距离判断, 是否外勤
|
||||||
|
$maxDistance = (int) AdminSettingService::make()->arrayGet('sign', 'distance', 0);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'time' => $time,
|
||||||
|
'enable' => true,
|
||||||
|
'type' => SignType::Normal,
|
||||||
|
'distance' => null,
|
||||||
|
'description' => '已进入考勤范围: ' . $store->title,
|
||||||
|
'maxDistance' => $maxDistance,
|
||||||
|
];
|
||||||
|
|
||||||
|
// 如果开启定位
|
||||||
|
if ($request->filled(['lon', 'lat'])) {
|
||||||
|
// 计算距离
|
||||||
|
$distance = $service->haversineDistance(
|
||||||
|
$request->input('lat'),
|
||||||
|
$request->input('lon'),
|
||||||
|
$store->lat,
|
||||||
|
$store->lon,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($maxDistance > 0 && $distance > $maxDistance) {
|
||||||
|
$data = array_merge($data, [
|
||||||
|
'type' => SignType::Outside,
|
||||||
|
'distance' => $distance,
|
||||||
|
'description' => '当前位置不在考勤范围内, 请选择外勤打卡',
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$data = array_merge($data, [
|
||||||
|
'distance' => $distance,
|
||||||
|
'description' => '已进入考勤范围: ' . $store->title,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} elseif ($maxDistance > 0) {
|
||||||
|
$data = array_merge($data, [
|
||||||
|
'enable' => false,
|
||||||
|
'description' => '请打开手机定位, 并给予APP获取位置信息权限',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(Request $request, EmployeeSignService $service)
|
public function store(Request $request, EmployeeSignService $service)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue