feat(接口): 添加月度打卡信息 2完善打卡逻辑
parent
37c146a4e0
commit
48045f0701
|
@ -350,13 +350,22 @@ class User extends Base
|
|||
return $this->json(0, 'success', ['info' => $info]);
|
||||
}
|
||||
|
||||
// 今日打卡记录
|
||||
/**
|
||||
* 今日打卡记录
|
||||
*
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function signToday(): Json
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
$list = [];
|
||||
|
||||
$buttonColor = 'gray';
|
||||
|
||||
if ($accountId > 0) {
|
||||
if (!$account = Account::findById($accountId)) {
|
||||
return $this->json(6001, '请先登录');
|
||||
|
@ -377,6 +386,40 @@ class User extends Base
|
|||
->order('cl.id', 'desc')
|
||||
->select();
|
||||
|
||||
|
||||
/**
|
||||
* 打卡按钮颜色 gray=灰色 orange=橙色 绿色=green
|
||||
* 普通人 只有灰色 和 绿色 未打卡灰色 打卡>0为绿色
|
||||
* 工人和负责人
|
||||
* 灰色: 未打卡、(中途休息期间如12~14 未判断此条件)
|
||||
* 橙色:上班卡数量>下班卡数量且>0
|
||||
* 绿色:1. 下班卡数量>= 上班卡数量 且下班卡数量>=1 或 2.下午下班卡打了后
|
||||
*/
|
||||
if ($account['role'] == Account::ROLE_NORMAL) {
|
||||
$buttonColor = $list->count() > 0 ? 'green' : 'gray';
|
||||
} else {
|
||||
$array = $list->whereIn('status', [0, 1])->column('type');
|
||||
$onCount = 0;//上班卡数量
|
||||
$offCount = 0;//下班卡数量
|
||||
foreach ($array as $sign) {
|
||||
if (strpos($sign, '_on')) {
|
||||
$onCount++;
|
||||
}
|
||||
|
||||
if (strpos($sign, '_off')) {
|
||||
$offCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array('afternoon_off', $array) || ($offCount >= $onCount && $offCount >= 1)) {
|
||||
$buttonColor = 'green';
|
||||
}
|
||||
|
||||
if (($offCount >= $onCount && $offCount >= 1) || $onCount > 0) {
|
||||
$buttonColor = 'orange';
|
||||
}
|
||||
}
|
||||
|
||||
$list->each(function ($item) {
|
||||
$item->type_text = ClockLog::typeText()[$item->type];
|
||||
switch ($item->status) {
|
||||
|
@ -395,7 +438,7 @@ class User extends Base
|
|||
$list = $list->toArray();
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', ['list' => $list]);
|
||||
return $this->json(0, 'success', ['buttonColor' => $buttonColor, 'list' => $list]);
|
||||
}
|
||||
|
||||
public function checkActive(): Json
|
||||
|
@ -414,46 +457,77 @@ class User extends Base
|
|||
}
|
||||
}
|
||||
|
||||
// 月度打卡记录
|
||||
/**
|
||||
* 月度打卡记录
|
||||
* {
|
||||
* 'ok':[2,5,6,8,12],
|
||||
* 'add':[4,7,11,22],
|
||||
* 'no':[19,28]
|
||||
* }
|
||||
*
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function monthSignLog(): Json
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$date = input('date/d', date('Y-m'));
|
||||
$date = input('date/s', '');
|
||||
$date = $date ?: date('Y-m');
|
||||
$ym = str_replace('-', '', $date);
|
||||
|
||||
$list = [];
|
||||
$res = [
|
||||
'ok' => [], //正常打卡:普通用户当天有打卡=正常 工人和负责人:打满4次=正常
|
||||
'add' => [],// 补打卡:仅限工人和负责人 当天存在补卡
|
||||
'no' => [],// 非正常打卡:仅限工人和负责人 4>打卡次数>0
|
||||
];
|
||||
|
||||
if ($accountId > 0) {
|
||||
$where = [];
|
||||
if (!$account = Account::findById($accountId)) {
|
||||
return $this->json(6001, '请先登录');
|
||||
}
|
||||
|
||||
$where = [];
|
||||
$where[] = ['cl.day', 'like', $ym.'%'];
|
||||
$where[] = ['cl.account_id', '=', $accountId];
|
||||
$where[] = ['cl.role', '=', $account['role']];
|
||||
$list = \app\model\ClockLog::alias('cl')
|
||||
->leftJoin('worksite w', 'w.id = cl.worksite_id')
|
||||
->field('cl.*,w.name as worksite_name')
|
||||
->where($where)
|
||||
->order('cl.id', 'desc')
|
||||
->select();
|
||||
|
||||
$list->each(function ($item) {
|
||||
$item->type_text = $item->type == 'in' ? '上班' : '下班';
|
||||
switch ($item->status) {
|
||||
case 0:
|
||||
$item->status_text = '待确认';
|
||||
break;
|
||||
case 1:
|
||||
$item->status_text = '已确认';
|
||||
break;
|
||||
case -1:
|
||||
$item->status_text = '不通过';
|
||||
break;
|
||||
$signNum = [];//每日打卡次数
|
||||
foreach ($list as $item) {
|
||||
$day = (int) substr($item['day'], -2);
|
||||
if (!isset($signNum[$day])) {
|
||||
$signNum[$day] = 0;
|
||||
}
|
||||
$item->time = date('H:i:s', $item->create_time);
|
||||
});
|
||||
$list = $list->toArray();
|
||||
$signNum[$day]++;
|
||||
if ($item['is_replenish'] == ClockLog::COMMON_ON) {
|
||||
$res['add'][] = $day;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($signNum as $day => $count) {
|
||||
if ($account['role'] == Account::ROLE_NORMAL) {
|
||||
if ($count >= 1) {
|
||||
$res['ok'][] = $day;
|
||||
}
|
||||
} else {
|
||||
if ($count == 4) {
|
||||
$res['ok'][] = $day;
|
||||
} else {
|
||||
$res['no'][] = $day;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res['ok'] = array_unique($res['ok']);
|
||||
$res['add'] = array_unique($res['add']);
|
||||
$res['no'] = array_unique($res['no']);
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', ['list' => $list]);
|
||||
return $this->json(0, 'success', $res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,6 +82,7 @@ class ClockLog extends Base
|
|||
return self::where('account_id', $accountId)
|
||||
->where('type', $type)
|
||||
->where('worksite_id', $worksiteId)
|
||||
->where('status', '<>', -1)
|
||||
->where('create_time', '>=', strtotime(date('Y-m-d')))
|
||||
->where('create_time', '<=', strtotime(date('Y-m-d 23:59:59')))
|
||||
->count() > 0;
|
||||
|
|
Loading…
Reference in New Issue