feat(打卡接口): 更新打卡逻辑

master
yin5th 2023-01-11 11:21:47 +08:00
parent a1716ce10a
commit 37c146a4e0
1 changed files with 13 additions and 2 deletions

View File

@ -358,19 +358,27 @@ class User extends Base
$list = [];
if ($accountId > 0) {
if (!$account = Account::findById($accountId)) {
return $this->json(6001, '请先登录');
}
$where = [];
$where[] = ['cl.created_at', '>', date('Y-m-d 00:00:00')];
$where[] = ['cl.created_at', '<', date('Y-m-d 23:59:59')];
$where[] = ['cl.account_id', '=', $accountId];
$where[] = ['cl.role', '=', $account['role']];
$limit = $account['role'] == Account::ROLE_NORMAL ? 4 : 0;//普通用户只展示最新4条 其他不限制
$list = \app\model\ClockLog::alias('cl')
->leftJoin('worksite w', 'w.id = cl.worksite_id')
->field('cl.*,w.name as worksite_name')
->where($where)
->limit($limit)
->order('cl.id', 'desc')
->select();
$list->each(function ($item) {
$item->type_text = $item->type == 'in' ? '上班' : '下班';
$item->type_text = ClockLog::typeText()[$item->type];
switch ($item->status) {
case 0:
$item->status_text = '待确认';
@ -382,7 +390,7 @@ class User extends Base
$item->status_text = '不通过';
break;
}
$item->time = date('H:i:s', $item->create_time);
$item->time = date('H:i', $item->create_time);
});
$list = $list->toArray();
}
@ -506,6 +514,7 @@ class User extends Base
'created_at' => $now,
'create_time' => $time,
'day' => $day,
'role' => $customer['role'],
'indexs' => $accountId.'-'.$input['worksite_id'].'-'.$day,
];
@ -537,6 +546,7 @@ class User extends Base
* 普通用户打卡
*
* @param int $accountId
* @param string $type
* @return bool
* @throws \app\exception\ApiException
* @throws \think\db\exception\DbException
@ -558,6 +568,7 @@ class User extends Base
'created_at' => $now,
'create_time' => $time,
'day' => $day,
'status' => ClockLog::COMMON_ON,
]);
return true;