diff --git a/app/controller/api/v1/User.php b/app/controller/api/v1/User.php index 7247ad0..db504d7 100644 --- a/app/controller/api/v1/User.php +++ b/app/controller/api/v1/User.php @@ -593,7 +593,7 @@ class User extends Base // 是否在打卡时间 if (!Worksite::checkSignTime($input['worksite_id'], $input['type'])) { - return $this->json(4002, '不在打卡时间段!'); +// return $this->json(4002, '不在打卡时间段!'); } $data = [ @@ -631,6 +631,76 @@ class User extends Base return $this->json(); } + /** + * 提交补卡 + */ + public function replenish(): Json + { + try { + $input = input('post.'); + + $rules = [ + 'day|补卡日期' => 'require|date', + 'type|补卡类型' => 'require|in:morning_on,morning_off,afternoon_on,afternoon_off', + 'worksite_id|工地' => 'require|number', + ]; + + $validate = $this->validateByApi($input, $rules, ['worksite_id.number' => '工地必传', 'type.in' => '补卡类型错误']); + + if ($validate !== true) { + return $validate; + } + + $accountId = $this->request->user['user_id'] ?? 0; + + if (!$customer = Account::findById($accountId)) { + return $this->json(6001, '请先登录'); + } + + if (!in_array($customer['role'], [1, 2])) { + return $this->json(4003, '当前身份不能补卡'); + } + + $time = time(); + $now = date('Y-m-d H:i:s', $time); + $day = date('Ymd', strtotime($input['day'])); + + $where = [ + 'account_id' => $accountId, + 'type' => $input['type'], + 'worksite_id' => $input['worksite_id'], + 'day' => $day, + 'role' => $customer['role'], + 'indexs' => $accountId.'-'.$input['worksite_id'].'-'.$day, + ]; + + if (ClockLog::where($where)->whereIn('status', [0, 1])->count() > 0) { + return $this->json(4001, '记录存在,无需补卡!'); + } + + $data = [ + 'account_id' => $accountId, + 'type' => $input['type'], + 'worksite_id' => $input['worksite_id'], + 'created_at' => $now, + 'create_time' => $time, + 'day' => $day, + 'role' => $customer['role'], + 'is_replenish' => ClockLog::COMMON_ON, + 'indexs' => $accountId.'-'.$input['worksite_id'].'-'.$day, + ]; + ClockLog::create($data); + + // 创建当日工资初始记录 + PayLog::createWhenNotExists($accountId, $input['worksite_id'], $day); + } catch (Exception $e) { + Log::error('补卡提交失败'.$e->getMessage()); + return $this->json(5000, '补卡申请失败!'); + } + + return $this->json(); + } + /** * 普通用户打卡 * diff --git a/app/controller/api/v1/Worker.php b/app/controller/api/v1/Worker.php index d22a53f..c03696a 100644 --- a/app/controller/api/v1/Worker.php +++ b/app/controller/api/v1/Worker.php @@ -657,74 +657,4 @@ class Worker extends Base return $this->json(); } - - /** - * 提交补卡 - */ - public function replenish(): Json - { - try { - $input = input('post.'); - - $rules = [ - 'day|补卡日期' => 'require|date', - 'type|补卡类型' => 'require|in:morning_on,morning_off,afternoon_on,afternoon_off', - 'worksite_id|工地' => 'require|number', - ]; - - $validate = $this->validateByApi($input, $rules, ['worksite_id.number' => '工地必传', 'type.in' => '补卡类型错误']); - - if ($validate !== true) { - return $validate; - } - - $accountId = $this->request->user['user_id'] ?? 0; - - if (!$customer = Account::findById($accountId)) { - return $this->json(6001, '请先登录'); - } - - if ($customer['role'] != Account::ROLE_WORKER) { - return $this->json(4003, '还不是工人'); - } - - $time = time(); - $now = date('Y-m-d H:i:s', $time); - $day = date('Ymd', strtotime($input['day'])); - - $where = [ - 'account_id' => $accountId, - 'type' => $input['type'], - 'worksite_id' => $input['worksite_id'], - 'day' => $day, - 'role' => $customer['role'], - 'indexs' => $accountId.'-'.$input['worksite_id'].'-'.$day, - ]; - - if (ClockLog::where($where)->whereIn('status', [0, 1])->count() > 0) { - return $this->json(4001, '记录存在,无需补卡!'); - } - - $data = [ - 'account_id' => $accountId, - 'type' => $input['type'], - 'worksite_id' => $input['worksite_id'], - 'created_at' => $now, - 'create_time' => $time, - 'day' => $day, - 'role' => $customer['role'], - 'is_replenish' => ClockLog::COMMON_ON, - 'indexs' => $accountId.'-'.$input['worksite_id'].'-'.$day, - ]; - ClockLog::create($data); - - // 创建当日工资初始记录 - PayLog::createWhenNotExists($accountId, $input['worksite_id'], $day); - } catch (Exception $e) { - Log::error('工人补卡提交失败'.$e->getMessage()); - return $this->json(5000, '补卡申请失败!'); - } - - return $this->json(); - } }