feat(接口): 1.完善公告版本 2.添加提交补卡、补卡列表

master
yin5th 2023-01-12 11:06:28 +08:00
parent 2e2b5bc9fc
commit 2dd1b85729
3 changed files with 133 additions and 2 deletions

View File

@ -898,4 +898,79 @@ class Manager extends Base
]); ]);
return $this->json(); return $this->json();
} }
// 补卡记录
public function replenishList(): Json
{
$page = input('page/d', 1);
$size = input('size/d', 20);
$status = input('status/d', 0);//状态 0=待审核 1=已审核包含1通过 -1不通过
$accountId = $this->request->user['user_id'] ?? 0;
if (!$account = Account::findById($accountId, ['id, role'])) {
return $this->json(6001, '请先登录');
}
if ($account['role'] <= Account::COMMON_ON) {
return $this->json(4003, '无权限');
}
$where = [];
if ($status == 0) {
$where[] = ['cl.status', '=', 0];
} else {
$where[] = ['cl.status', 'in', [1, -1]];
}
// 负责工地
$worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id');
$where[] = ['cl.worksite_id', 'in', $worksiteIds];
$where[] = ['cl.is_replenish', '=', ClockLog::COMMON_ON];
$query = \app\model\ClockLog::alias('cl')
->leftJoin('account a', 'a.id = cl.account_id')
->leftJoin('worksite w', 'w.id = cl.worksite_id')
->field('cl.*,w.name as worksite_name,a.real_name as worker_name')
->where($where);
$total = $query->count();
$res = [
'total' => $total,
'current' => $page ?: 1,
'size' => $size ?: 20,
'list' => new Collection(),
];
if ($total > 0) {
$res['list'] = $query->page($page, $size)->order('cl.id', 'desc')->select();
$res['list']->each(function ($item) {
switch ($item->status) {
case 0:
$item->status_text = '待确认';
break;
case 1:
$item->status_text = '已确认';
break;
case -1:
$item->status_text = '不通过';
break;
}
$item->create_time = date('Y年m月d日 H:i:s', $item->create_time);
unset($item->check_by);
unset($item->check_at);
unset($item->account_id);
unset($item->created_at);
unset($item->type);
unset($item->day);
unset($item->day_text);
unset($item->worksite_id);
});
$res['list'] = arrayNullToString($res['list']->toArray());
}
return $this->json(0, 'success', $res);
}
} }

View File

@ -760,4 +760,60 @@ class Worker extends Base
return $this->json(); 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']));
$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();
}
} }

View File

@ -158,7 +158,7 @@ class Config extends Base
if ($this->request->isPost()) { if ($this->request->isPost()) {
try { try {
$data = input("post."); $data = input("post.");
if ($data['content'] != $oldData['content']) { if (!isset($oldData['version']) || empty($oldData['version']) || $data['content'] != $oldData['content']) {
$data['version'] = time(); $data['version'] = time();
} }
$php = var_export($data, true); $php = var_export($data, true);