feat(接口): 添加 1.工人离职申请 2负责人离职审核 3负责人离职申请列表
parent
5b1f5280c9
commit
34805d76d6
|
@ -4,6 +4,7 @@ namespace app\controller\api\v1;
|
|||
|
||||
use app\controller\api\Base;
|
||||
use app\model\Account;
|
||||
use app\model\AccountDimission;
|
||||
use app\model\AccountStar;
|
||||
use app\model\AccountWorksite;
|
||||
use app\model\CheckLog;
|
||||
|
@ -442,7 +443,7 @@ class Manager extends Base
|
|||
OvertimeLog::whereIn('id', $ids)->where('status', ClockLog::COMMON_OFF)->update([
|
||||
'status' => $type == 1 ? 1 : -1,
|
||||
'check_at' => date('Y-m-d H:i:s'),
|
||||
'check_by' => $accountId
|
||||
'check_by' => $accountId,
|
||||
]);
|
||||
return $this->json();
|
||||
} catch (Exception $e) {
|
||||
|
@ -450,7 +451,7 @@ class Manager extends Base
|
|||
}
|
||||
}
|
||||
|
||||
// 工资记录
|
||||
// 工资记录MOCK
|
||||
public function payListMock(): Json
|
||||
{
|
||||
$page = input('page/d', 1);
|
||||
|
@ -744,4 +745,117 @@ class Manager extends Base
|
|||
return $this->json(5000, '评定失败'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核离职 支持批量
|
||||
*
|
||||
* @return Json
|
||||
*/
|
||||
public function checkDimission(): Json
|
||||
{
|
||||
try {
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$reason = input('reason/s', '');
|
||||
$type = input('type/d', 1);//类型 1=通过 0=不通过
|
||||
$ids = input('id/s');//待审核记录ID 多个用逗号分割
|
||||
$ids = explode(',', $ids);
|
||||
$ids = array_filter($ids);
|
||||
|
||||
if (!in_array($type, [0, 1])) {
|
||||
return $this->json(4001, '审核参数错误');
|
||||
}
|
||||
|
||||
if (!$account = Account::findById($accountId, ['id, role'])) {
|
||||
return $this->json(6001, '请先登录');
|
||||
}
|
||||
|
||||
if ($account['role'] <= Account::COMMON_ON) {
|
||||
// 工地负责人才能操作
|
||||
return $this->json(4003, '无此权限');
|
||||
}
|
||||
|
||||
$worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id');
|
||||
if (AccountDimission::whereIn('id', $ids)->whereNotIn('worksite_id', $worksiteIds)->count() > 0) {
|
||||
return $this->json(4003, '部分记录不在您权限操作的范围');
|
||||
}
|
||||
|
||||
AccountDimission::whereIn('id', $ids)->where('status', AccountDimission::COMMON_OFF)->update([
|
||||
'status' => $type == 1 ? 1 : -1,
|
||||
'operated_at' => date('Y-m-d H:i:s'),
|
||||
'operated_by' => $accountId,
|
||||
'refuse_reason' => $reason,
|
||||
]);
|
||||
|
||||
// 账号更新
|
||||
$accountIds = AccountDimission::whereIn('id', $ids)->column('account_id');
|
||||
Account::whereIn('id', $accountIds)->where('role', Account::ROLE_WORKER)->update([
|
||||
'role' => Account::ROLE_NORMAL,
|
||||
'worksite_id' => Account::COMMON_OFF,
|
||||
]);
|
||||
return $this->json();
|
||||
} catch (Exception $e) {
|
||||
return $this->json(5000, '审核失败'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 离职审核列表
|
||||
public function dimissionCheckList(): Json
|
||||
{
|
||||
$page = input('page/d', 1);
|
||||
$size = input('size/d', 20);
|
||||
$keyword = input('keyword/s');
|
||||
// $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 (!empty($keyword)) {
|
||||
$where[] = ['cl.real_name|cl.mobile', 'like', '%'.$keyword.'%'];
|
||||
}
|
||||
|
||||
// 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];
|
||||
|
||||
$query = AccountDimission::alias('cl')
|
||||
->leftJoin('account a', 'a.id = cl.account_id')
|
||||
->leftJoin('worksite w', 'w.id = cl.worksite_id')
|
||||
->leftJoin('position p', 'p.id = a.position')
|
||||
->field('cl.id,a.real_name,cl.status,cl.created_at,p.name as position_name,a.work_at,w.name as worksite_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) {
|
||||
// $item->created_at = date('Y年m月d日 H:i:s', strtotime($item->created_at));
|
||||
// });
|
||||
$res['list'] = arrayNullToString($res['list']->toArray());
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', $res);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -400,4 +400,46 @@ class User extends Base
|
|||
return $this->json(4000, '检查账号是否微信授权是不'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 月度打卡记录
|
||||
public function monthSignLog(): Json
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$date = input('date/d', date('Y-m'));
|
||||
$ym = str_replace('-', '', $date);
|
||||
|
||||
$list = [];
|
||||
|
||||
if ($accountId > 0) {
|
||||
$where = [];
|
||||
|
||||
$where[] = ['cl.day', 'like', $ym.'%'];
|
||||
$where[] = ['cl.account_id', '=', $accountId];
|
||||
$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;
|
||||
}
|
||||
$item->time = date('H:i:s', $item->create_time);
|
||||
});
|
||||
$list = $list->toArray();
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', ['list' => $list]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use app\controller\api\Base;
|
|||
use app\controller\manager\Clock;
|
||||
use app\exception\RepositoryException;
|
||||
use app\model\Account;
|
||||
use app\model\AccountDimission;
|
||||
use app\model\AccountRecord;
|
||||
use app\model\AccountWorksite;
|
||||
use app\model\CheckLog;
|
||||
|
@ -75,6 +76,10 @@ class Worker extends Base
|
|||
'card_number|身份证' => 'require|max:20|min:15',
|
||||
'position|岗位' => 'require|number',
|
||||
'worksite_id|工地' => 'require|number',
|
||||
'bank_card_img|银行卡拍照' => 'require',
|
||||
'id_front|身份证正面' => 'require',
|
||||
'id_back|身份证反面' => 'require',
|
||||
'address_now|现住址' => 'require',
|
||||
];
|
||||
|
||||
$message = [
|
||||
|
@ -90,7 +95,8 @@ class Worker extends Base
|
|||
|
||||
$fields = [
|
||||
'real_name', 'mobile', 'pay', 'emergency_contact', 'emergency_phone', 'bank_card_name', 'bank_card_number',
|
||||
'bank_name', 'card_number', 'position', 'worksite_id'
|
||||
'bank_name', 'card_number', 'position', 'worksite_id', 'certificate', 'address_now', 'province', 'city', 'area',
|
||||
'id_front', 'id_back', 'bank_card_img'
|
||||
];
|
||||
$post = array_filter($post, function ($item, $key) use ($fields) {
|
||||
return in_array($key, $fields);
|
||||
|
@ -674,4 +680,39 @@ class Worker extends Base
|
|||
|
||||
return $this->json(0, 'success', $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请离职
|
||||
*/
|
||||
public function dimission(): Json
|
||||
{
|
||||
try {
|
||||
$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, '不是工人');
|
||||
}
|
||||
|
||||
if (AccountDimission::where('account_id', $accountId)->where('worksite_id', $customer['worksite_id'])->where('status', 0)->count() > 0) {
|
||||
return $this->json(4001, '审核中请勿重复提交');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$now = date('Y-m-d H:i:s', $time);
|
||||
AccountDimission::create([
|
||||
'account_id' => $accountId,
|
||||
'worksite_id' => $customer['worksite_id'],
|
||||
'created_at' => $now,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error('申请离职提交失败'.$e->getMessage());
|
||||
return $this->json(5000, '申请离职提交失败!');
|
||||
}
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ class Worksite extends Base
|
|||
'worksite_id' => $item->id,
|
||||
'account_id' => $input['manager_id'],
|
||||
]);
|
||||
Account::where('id', $input['manager_id'])->save(['role' => Account::ROLE_MANAGER]);
|
||||
Account::where('id', $input['manager_id'])->save(['role' => Account::ROLE_MANAGER, 'worksite_id' => $item->id]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,7 +158,7 @@ class Worksite extends Base
|
|||
'account_id' => $input['manager_id'],
|
||||
]);
|
||||
|
||||
Account::where('id', $input['manager_id'])->save(['role' => Account::ROLE_MANAGER]);
|
||||
Account::where('id', $input['manager_id'])->save(['role' => Account::ROLE_MANAGER, 'worksite_id' => $id]);
|
||||
}
|
||||
|
||||
$item->save([
|
||||
|
|
|
@ -86,7 +86,7 @@ class Account extends Base
|
|||
{
|
||||
return [
|
||||
'real_name', 'mobile', 'position', 'pay', 'emergency_contact', 'emergency_phone', 'bank_card_name', 'bank_card_number',
|
||||
'bank_name', 'card_number'
|
||||
'bank_name', 'card_number', 'bank_card_img', 'id_front', 'id_back', 'certificate'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\model\relation\HasOne;
|
||||
|
||||
/**
|
||||
* 离职日志
|
||||
*
|
||||
* Class OvertimeLog
|
||||
* @package app\model
|
||||
*/
|
||||
class AccountDimission extends Base
|
||||
{
|
||||
public const STATUS_NORMAL = 0;//待审核
|
||||
public const STATUS_YES = 1;//通过
|
||||
public const STATUS_NO = -1;//拒绝
|
||||
|
||||
public function account(): HasOne
|
||||
{
|
||||
return $this->hasOne(Account::class, 'id', 'account_id');
|
||||
}
|
||||
|
||||
public function worksite(): HasOne
|
||||
{
|
||||
return $this->hasOne(Worksite::class, 'id', 'worksite_id');
|
||||
}
|
||||
}
|
|
@ -179,6 +179,13 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">证书</label>
|
||||
<div class="layui-input-block editor-text">
|
||||
<textarea name="certificate" class="layui-textarea">{$item.certificate ?? ''}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">现住地址-省</label>
|
||||
<div class="layui-input-block">
|
||||
|
|
Loading…
Reference in New Issue