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('允许打卡的距离(米)')
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class EmployeeSignService extends BaseService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打卡
|
* 打卡
|
||||||
*
|
*
|
||||||
* @param Employee $user 用户
|
* @param Employee $user 用户
|
||||||
* @param SignTime $time 上班/下班 打卡
|
* @param SignTime $time 上班/下班 打卡
|
||||||
* @param mixed $date 打卡时间
|
* @param mixed $date 打卡时间
|
||||||
|
|
@ -147,28 +147,28 @@ class EmployeeSignService extends BaseService
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算两点之间的距离(千米)
|
* 计算两点之间的距离(米)
|
||||||
*/
|
*/
|
||||||
public function haversineDistance($lat1, $lon1, $lat2, $lon2)
|
public function haversineDistance($lat1, $lon1, $lat2, $lon2)
|
||||||
{
|
{
|
||||||
// 地球半径(千米)
|
// 地球半径(千米)
|
||||||
$R = 6371;
|
$R = 6371;
|
||||||
|
|
||||||
// 将角度转换为弧度
|
// 将角度转换为弧度
|
||||||
$lat1 = deg2rad($lat1);
|
$lat1 = deg2rad($lat1);
|
||||||
$lon1 = deg2rad($lon1);
|
$lon1 = deg2rad($lon1);
|
||||||
$lat2 = deg2rad($lat2);
|
$lat2 = deg2rad($lat2);
|
||||||
$lon2 = deg2rad($lon2);
|
$lon2 = deg2rad($lon2);
|
||||||
|
|
||||||
// 经纬度差值
|
// 经纬度差值
|
||||||
$dlon = $lon2 - $lon1;
|
$dlon = $lon2 - $lon1;
|
||||||
$dlat = $lat2 - $lat1;
|
$dlat = $lat2 - $lat1;
|
||||||
|
|
||||||
// Calculate the Haversine formula
|
// Calculate the Haversine formula
|
||||||
$a = pow(sin($dlat/2), 2) + cos($lat1) * cos($lat2) * pow(sin($dlon/2), 2);
|
$a = pow(sin($dlat/2), 2) + cos($lat1) * cos($lat2) * pow(sin($dlon/2), 2);
|
||||||
$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