generated from liutk/owl-admin-base
打卡优化
parent
498a2df89d
commit
655c2fa1d8
|
|
@ -40,7 +40,7 @@ class SettingController extends AdminController
|
||||||
amis()->SwitchControl('oss_config.use_ssl', '开启SSL')->value(false)->visibleOn('${upload_disk == "oss"}'),
|
amis()->SwitchControl('oss_config.use_ssl', '开启SSL')->value(false)->visibleOn('${upload_disk == "oss"}'),
|
||||||
]),
|
]),
|
||||||
Tab::make()->title('打卡设置')->body([
|
Tab::make()->title('打卡设置')->body([
|
||||||
amisMake()->NumberControl()->min(0)->name('sign.distance')->label('允许打卡的距离(公里)')
|
amis()->NumberControl()->min(0)->name('sign.distance')->label('允许打卡的距离(米)')
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ class EmployeeSignService extends BaseService
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算两点之间的距离(千米)
|
* 计算两点之间的距离(米)
|
||||||
*/
|
*/
|
||||||
public function haversineDistance($lat1, $lon1, $lat2, $lon2)
|
public function haversineDistance($lat1, $lon1, $lat2, $lon2)
|
||||||
{
|
{
|
||||||
|
|
@ -169,6 +169,6 @@ class EmployeeSignService extends BaseService
|
||||||
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
|
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
|
||||||
$distance = $R * $c;
|
$distance = $R * $c;
|
||||||
|
|
||||||
return floor($distance * 1000) / 1000;
|
return floor($distance * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,21 @@ class SignController extends Controller
|
||||||
$type = SignType::from($request->input('type'));
|
$type = SignType::from($request->input('type'));
|
||||||
|
|
||||||
// 根据定位的距离判断, 是否需要外勤打卡
|
// 根据定位的距离判断, 是否需要外勤打卡
|
||||||
$maxDistance = AdminSettingService::make()->arrayGet('sign', 'distance', 0);
|
$maxDistance = (int) AdminSettingService::make()->arrayGet('sign', 'distance');
|
||||||
$distance = $service->haversineDistance($request->input('position.lat'), $request->input('position.lon'), $store->lat, $store->lon);
|
|
||||||
if ($distance > $maxDistance && $type == SignType::Normal) {
|
if ($maxDistance > 0 && $type == SignType::Normal) {
|
||||||
throw new RuntimeException('当前位置不在考勤范围内, 请选择外勤打卡');
|
$distance = $service->haversineDistance(
|
||||||
|
$request->input('position.lat'),
|
||||||
|
$request->input('position.lon'),
|
||||||
|
$store->lat,
|
||||||
|
$store->lon,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($distance > $maxDistance) {
|
||||||
|
throw new RuntimeException('当前位置不在考勤范围内, 请选择外勤打卡');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
if (!$service->signDay($user, $time, now(), $request->only(['remarks', 'position', 'type']))) {
|
if (!$service->signDay($user, $time, now(), $request->only(['remarks', 'position', 'type']))) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue