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