diff --git a/app/controller/api/v1/Manager.php b/app/controller/api/v1/Manager.php index 3f65a69..15f6ea5 100644 --- a/app/controller/api/v1/Manager.php +++ b/app/controller/api/v1/Manager.php @@ -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; @@ -440,9 +441,9 @@ 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 + 'status' => $type == 1 ? 1 : -1, + 'check_at' => date('Y-m-d H:i:s'), + '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); @@ -682,7 +683,7 @@ class Manager extends Base if ($total > 0) { $list = $query->page($page, $size)->order('a.id', 'desc')->select(); $accountList = $list->column('id'); - $starList = Db::query("SELECT `star`,`account_id` FROM `bee_account_star` WHERE `id` IN (SELECT max(id) FROM `bee_account_star` WHERE FIND_IN_SET(account_id, ?) GROUP BY `account_id`)", [implode(',', $accountList)]); + $starList = Db::query("SELECT `star`,`account_id` FROM `bee_account_star` WHERE `id` IN (SELECT max(id) FROM `bee_account_star` WHERE FIND_IN_SET(account_id, ?) GROUP BY `account_id`)", [implode(',', $accountList)]); $starArr = []; foreach ($starList as $l) { @@ -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); + } } diff --git a/app/controller/api/v1/User.php b/app/controller/api/v1/User.php index 28d4480..7f4b261 100644 --- a/app/controller/api/v1/User.php +++ b/app/controller/api/v1/User.php @@ -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]); + } } diff --git a/app/controller/api/v1/Worker.php b/app/controller/api/v1/Worker.php index 6a2a0e7..ad575f0 100644 --- a/app/controller/api/v1/Worker.php +++ b/app/controller/api/v1/Worker.php @@ -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(); + } } diff --git a/app/controller/manager/Worksite.php b/app/controller/manager/Worksite.php index d293b45..2ff5028 100644 --- a/app/controller/manager/Worksite.php +++ b/app/controller/manager/Worksite.php @@ -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([ diff --git a/app/model/Account.php b/app/model/Account.php index ab509d7..329f0c6 100644 --- a/app/model/Account.php +++ b/app/model/Account.php @@ -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' ]; } } diff --git a/app/model/AccountDimission.php b/app/model/AccountDimission.php new file mode 100644 index 0000000..ba9a29d --- /dev/null +++ b/app/model/AccountDimission.php @@ -0,0 +1,28 @@ +hasOne(Account::class, 'id', 'account_id'); + } + + public function worksite(): HasOne + { + return $this->hasOne(Worksite::class, 'id', 'worksite_id'); + } +} diff --git a/view/manager/account/index/worker.html b/view/manager/account/index/worker.html index 5a5b68c..4c56195 100644 --- a/view/manager/account/index/worker.html +++ b/view/manager/account/index/worker.html @@ -179,6 +179,13 @@ +