generated from liutk/owl-admin-base
api sign.position
parent
30c217a6d2
commit
3d7646ef6a
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Enums;
|
||||
|
||||
/**
|
||||
* 打卡时机
|
||||
* 打卡时机(上班打卡/下班打卡)
|
||||
*/
|
||||
enum SignTime: int
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,24 +44,28 @@ class SignController extends Controller
|
|||
{
|
||||
$user = $this->guard()->user();
|
||||
$store = $user->store;
|
||||
if (!$store) {
|
||||
throw new RuntimeException('没有绑定门店');
|
||||
}
|
||||
$date = now();
|
||||
// 是否允许打卡
|
||||
$enable = true;
|
||||
$enable = false;
|
||||
// 上班/下班 打卡, 当天是否打卡
|
||||
$time = EmployeeSignLog::filter(['date' => $date->format('Y-m-d')])->exists() ? SignTime::Afternoon : SignTime::Morning;
|
||||
|
||||
// 根据定位的距离判断, 是否外勤
|
||||
$maxDistance = AdminSettingService::make()->arrayGet('sign', 'distance');
|
||||
$maxDistance = AdminSettingService::make()->arrayGet('sign', 'distance', 0);
|
||||
$type = SignType::Outside;
|
||||
$distance = null;
|
||||
$description = '当前位置不在考勤范围内,请选择外勤打卡';
|
||||
if ($request->filled(['lon', 'lat']) && $store && $maxDistance) {
|
||||
$description = '请打开手机定位, 并给予APP获取位置信息权限';
|
||||
if ($request->filled(['lon', 'lat'])) {
|
||||
$distance = $service->haversineDistance($request->input('lat'), $request->input('lon'), $store->lat, $store->lon);
|
||||
if ($distance <= $maxDistance) {
|
||||
$enable = true;
|
||||
$description = '已进入考勤范围: ' . $store->title;
|
||||
$type = SignType::Normal;
|
||||
} else {
|
||||
$enable = false;
|
||||
$description = '当前位置不在考勤范围内, 请选择外勤打卡';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,16 +75,30 @@ class SignController extends Controller
|
|||
public function store(Request $request, EmployeeSignService $service)
|
||||
{
|
||||
$request->validate([
|
||||
'type' => ['required'],
|
||||
'time' => ['required'],
|
||||
'type' => ['required', Rule::enum(SignType::class)],
|
||||
'time' => ['required', Rule::enum(SignTime::class)],
|
||||
'position' => ['required'],
|
||||
'position.lon' => ['required'],
|
||||
'position.lat' => ['required'],
|
||||
], [
|
||||
'type.required' => __('employee_sign_log.sign_type') . '必填',
|
||||
'time.required' => __('employee_sign_log.sign_time') . '必填',
|
||||
'position.required' => __('employee_sign_log.position') . '必填',
|
||||
'position.*.required' => __('employee_sign_log.position') . '必填',
|
||||
]);
|
||||
$user = $this->guard()->user();
|
||||
$store = $user->store;
|
||||
if (!$store) {
|
||||
throw new RuntimeException('没有绑定门店');
|
||||
}
|
||||
$time = SignTime::from($request->input('time'));
|
||||
$type = SignType::from($request->input('type'));
|
||||
|
||||
// 没有定位坐标, 必须是外勤打卡
|
||||
if (!$request->filled('position') && $type == SignType::Normal) {
|
||||
|
||||
// 根据定位的距离判断, 是否需要外勤打卡
|
||||
$maxDistance = AdminSettingService::make()->arrayGet('sign', 'distance', 0);
|
||||
$distance = $service->haversineDistance($request->input('position.lat'), $request->input('position.lon'), $store->lat, $store->lon);
|
||||
if ($distance > $maxDistance && $type == SignType::Normal) {
|
||||
throw new RuntimeException('当前位置不在考勤范围内, 请选择外勤打卡');
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
|
|
|||
Loading…
Reference in New Issue