From f2a13e01e8843302dfb2e80fe18edec3a4ba137f Mon Sep 17 00:00:00 2001 From: YM <479443481@qq.com> Date: 星期一, 10 三月 2025 00:58:19 +0800 Subject: [PATCH] 考勤组的增加已经表单逻辑 --- app/user/controller/Attendance.php | 249 ++++++++++++++++++++++++++++++++----------------- 1 files changed, 162 insertions(+), 87 deletions(-) diff --git a/app/user/controller/Attendance.php b/app/user/controller/Attendance.php index 7bf1907..0222bab 100644 --- a/app/user/controller/Attendance.php +++ b/app/user/controller/Attendance.php @@ -1,11 +1,11 @@ <?php -declare (strict_types = 1); +declare(strict_types=1); namespace app\user\controller; use app\base\BaseController; -// use app\user\validate\PositionCheck; +use app\user\validate\AttendanceCheck; use think\exception\ValidateException; use think\facade\Db; use think\facade\View; @@ -15,16 +15,17 @@ public function index() { if (request()->isAjax()) { - $list = Db::name('Position')->where('status', '>=', 0)->order('create_time asc')->select()->toArray(); - foreach ($list as &$val) { - $groupId = Db::name('PositionGroup')->where(['pid' => $val['id']])->column('group_id'); - $groupName = Db::name('AdminGroup')->where('id', 'in', $groupId)->column('title'); - $val['groupName'] = implode(',', $groupName); - } + $list = Db::name('AttendanceGroup')->where('is_del', '=', 0)->order('create_time asc')->select()->toArray(); + // var_dump($list); + // foreach ($list as &$val) { + // $groupId = Db::name('PositionGroup')->where(['pid' => $val['id']])->column('group_id'); + // $groupName = Db::name('AdminGroup')->where('id', 'in', $groupId)->column('title'); + // $val['groupName'] = implode(',', $groupName); + // } $res['data'] = $list; return table_assign(0, '', $res); } else { - return view(); + return view(); } } @@ -33,87 +34,161 @@ { $param = get_params(); if (request()->isAjax()) { - // if (!empty($param['id']) && $param['id'] > 0) { - // if($param['id']==1){ - // return to_assign(1, '瓒呯骇绠$悊鍛樹笉鑳界紪杈�'); - // } - // try { - // validate(PositionCheck::class)->scene('edit')->check($param); - // } catch (ValidateException $e) { - // // 楠岃瘉澶辫触 杈撳嚭閿欒淇℃伅 - // return to_assign(1, $e->getError()); - // } - // // 鍚姩浜嬪姟 - // Db::startTrans(); - // try { - // Db::name('Position')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); - // Db::name('PositionGroup')->where(['pid' => $param['id']])->delete(); - // foreach ($param['group_id'] as $k => $v) { - // $data[$k] = [ - // 'pid' => $param['id'], - // 'group_id' => $v, - // 'create_time' => time(), - // ]; - // } - // Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data); - // add_log('edit', $param['id'], $param); - // //娓呴櫎鑿滃崟\鏉冮檺缂撳瓨 - // clear_cache('adminMenu'); - // clear_cache('adminRules'); - // // 鎻愪氦浜嬪姟 - // Db::commit(); - // } catch (\Exception $e) { - // // 鍥炴粴浜嬪姟 - // Db::rollback(); - // return to_assign(1, '鎻愪氦澶辫触:' . $e->getMessage()); - // } - // } else { - // try { - // validate(PositionCheck::class)->scene('add')->check($param); - // } catch (ValidateException $e) { - // // 楠岃瘉澶辫触 杈撳嚭閿欒淇℃伅 - // return to_assign(1, $e->getError()); - // } - // // 鍚姩浜嬪姟 - // Db::startTrans(); - // try { - // $uid = Db::name('Position')->strict(false)->field(true)->insertGetId($param); - // foreach ($param['group_id'] as $k => $v) { - // $data[$k] = [ - // 'pid' => $uid, - // 'group_id' => $v, - // 'create_time' => time(), - // ]; - // } - // Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data); - // add_log('add', $uid, $param); - // // 鎻愪氦浜嬪姟 - // Db::commit(); - // } catch (\Exception $e) { - // // 鍥炴粴浜嬪姟 - // Db::rollback(); - // return to_assign(1, '鎻愪氦澶辫触:' . $e->getMessage()); - // } - // } + if (!empty($param['id']) && $param['id'] > 0) { + try { + validate(AttendanceCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 楠岃瘉澶辫触 杈撳嚭閿欒淇℃伅 + return to_assign(1, $e->getError()); + } + // 鍚姩浜嬪姟 + Db::startTrans(); + try { + Db::name('AttendanceGroup')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); + // Db::name('PositionGroup')->where(['pid' => $param['id']])->delete(); + // foreach ($param['group_id'] as $k => $v) { + // $data[$k] = [ + // 'pid' => $param['id'], + // 'group_id' => $v, + // 'create_time' => time(), + // ]; + // } + // Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data); + add_log('edit', $param['id'], $param); + //娓呴櫎鑿滃崟\鏉冮檺缂撳瓨 + // clear_cache('adminMenu'); + // clear_cache('adminRules'); + // 鎻愪氦浜嬪姟 + Db::commit(); + } catch (\Exception $e) { + // 鍥炴粴浜嬪姟 + Db::rollback(); + return to_assign(1, '鎻愪氦澶辫触:' . $e->getMessage()); + } + } else { + try { + validate(AttendanceCheck::class)->scene('add')->check($param); + } catch (ValidateException $e) { + // 楠岃瘉澶辫触 杈撳嚭閿欒淇℃伅 + return to_assign(1, $e->getError()); + } + // 鍚姩浜嬪姟 + Db::startTrans(); + try { + // 鎻掑叆鑰冨嫟缁勮〃 + $setData = [ + 'name' => $param['name'], + 'type' => $param['type'], + 'is_del' => 0, + 'create_time' => time(), + 'mon_work_plan_id' => isset($param['work1']) && $param['work1'] == "on" && isset($param['work_plan_id1']) ? intval($param['work_plan_id1']) : 0, + 'tue_work_plan_id' => isset($param['work2']) && $param['work2'] == "on" && isset($param['work_plan_id2']) ? intval($param['work_plan_id1']) : 0, + 'wed_work_plan_id' => isset($param['work3']) && $param['work3'] == "on" && isset($param['work_plan_id3']) ? intval($param['work_plan_id1']) : 0, + 'thur_work_plan_id' => isset($param['work4']) && $param['work4'] == "on" && isset($param['work_plan_id4']) ? intval($param['work_plan_id1']) : 0, + 'fri_work_plan_id' => isset($param['work5']) && $param['work5'] == "on" && isset($param['work_plan_id5']) ? intval($param['work_plan_id1']) : 0, + 'sat_work_plan_id' => isset($param['work6']) && $param['work6'] == "on" && isset($param['work_plan_id6']) ? intval($param['work_plan_id1']) : 0, + 'sun_work_plan_id' => isset($param['work7']) && $param['work7'] == "on" && isset($param['work_plan_id7']) ? intval($param['work_plan_id1']) : 0, + ]; + $uid = Db::name('AttendanceGroup')->strict(false)->field(true)->insertGetId($setData); + // 鎻掑叆鐢ㄦ埛鍏宠仈琛� + $attendance_participants_ids = explode(",", $param['attendance_participants_id']); + $attendance_not_participants_id = explode(",", $param['attendance_not_participants_id']); + foreach ($attendance_participants_ids as $key => $value) { + if ($value != '') { + $mappingData[$key] = [ + 'group_id' => $uid, + 'user_id' => intval($value), + 'type' => "1", + ]; + Db::name('AttendanceUserLink')->strict(false)->field(true)->insertAll($mappingData); + } + } + foreach ($attendance_not_participants_id as $key => $value) { + if ($value != '') { + $mappingData[$key] = [ + 'group_id' => $uid, + 'user_id' => intval($value), + 'type' => "2", + ]; + Db::name('AttendanceUserLink')->strict(false)->field(true)->insertAll($mappingData); + } + } + + // 鎻掑叆鏃堕棿琛� + for ($i = 0; $i < count($param['necessaryTime']); $i++) { + // 鑾峰彇鏃堕棿鏁版嵁 + $timeData1 = [ + 'begin_data' => $param['necessaryTime'][$i] . " 00:00:00", + 'end_data' => $param['necessaryTime'][$i] . " 23:59:59", + 'type' => "1", + ]; + // 鎻掑叆鏃堕棿鏁版嵁 + $timeIds1[$i] = Db::name('AttendanceSpecialDate')->strict(false)->field(true)->insertGetId($timeData1); + } + + foreach ($timeIds1 as $key => $value) { + $mappingData1[$key] = [ + 'group_id' => $uid, + 'special_date_id' => $value, + ]; + } + Db::name('AttendanceGroupSpecialDateLink')->strict(false)->field(true)->insertAll($mappingData1); + + + for ($i = 0; $i < count($param['unNecessaryTime']); $i++) { + // 鑾峰彇鏃堕棿鏁版嵁 + $timeData2 = [ + 'begin_data' => $param['unNecessaryTime'][$i] . " 00:00:00", + 'end_data' => $param['unNecessaryTime'][$i] . " 23:59:59", + 'type' => "2", + ]; + // 鎻掑叆鏃堕棿鏁版嵁 + $timeIds2[$i] = Db::name('AttendanceSpecialDate')->strict(false)->field(true)->insertGetId($timeData2); + } + + foreach ($timeIds2 as $key => $value) { + $mappingData2[$key] = [ + 'group_id' => $uid, + 'special_date_id' => $value, + ]; + } + Db::name('AttendanceGroupSpecialDateLink')->strict(false)->field(true)->insertAll($mappingData2); + + // foreach ($param['group_id'] as $k => $v) { + // $data[$k] = [ + // 'pid' => $uid, + // 'group_id' => $v, + // 'create_time' => time(), + // ]; + // } + // Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data); + add_log('add', $uid, $param); + // 鎻愪氦浜嬪姟 + Db::commit(); + } catch (\Exception $e) { + // 鍥炴粴浜嬪姟 + Db::rollback(); + return to_assign(1, '鎻愪氦澶辫触:' . $e->getMessage()); + } + } return to_assign(); - } - else{ - // $id = isset($param['id']) ? $param['id'] : 0; + } else { + $id = isset($param['id']) ? $param['id'] : 0; // $group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray(); - // if ($id > 0) { - // $detail = Db::name('Position')->where(['id' => $id])->find(); - // $detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id'); - // foreach ($group as &$val) { - // if (in_array($val['id'], $detail['group_id'])) { - // $val['checked'] = 1; - // } else { - // $val['checked'] = 0; - // } - // } - // View::assign('detail', $detail); - // } + if ($id > 0) { + $detail = Db::name('AttendanceGroup')->where(['id' => $id])->find(); + // $detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id'); + // foreach ($group as &$val) { + // if (in_array($val['id'], $detail['group_id'])) { + // $val['checked'] = 1; + // } else { + // $val['checked'] = 0; + // } + // } + View::assign('detail', $detail); + } // View::assign('group', $group); - // View::assign('id', $id); + View::assign('id', $id); return view(); } } -- Gitblit v1.9.1