get('page', 1); $pageSize = $request->get('pageSize', 10); $keywords = format_string($request->get('keywords', '')); $rows = SysDept::select('dept_id', 'dept_name', 'dept_addtimes') ->where('dept_category', self::MEDICAL_DEPT_CATEGORY) ->when($keywords != '', function ($query) use ($keywords) { $query->where('dept_name', 'like', '%' . $keywords . '%'); }) ->orderBy('dept_addtimes', 'DESC') ->forPage($page, $pageSize) ->get() ->toArray(); $total = SysDept::where('dept_category', self::MEDICAL_DEPT_CATEGORY) ->when($keywords != '', function ($query) use ($keywords) { $query->where('dept_name', 'like', '%' . $keywords . '%'); })->count(); return json_success('', compact('rows', 'page', 'pageSize', 'total')); } /** * @Desc 医疗团队详情 * @Author Gorden * @Date 2024/2/21 10:35 * * @param $id * @return \support\Response */ public static function deptInfo($id) { $dept = SysDept::find($id); if (!$dept) { return json_fail('医疗团队不存在'); } $dept = $dept->toArray(); return json_success('', $dept); } /** * @Desc 创建医疗团队 * @Author Gorden * @Date 2024/2/21 9:22 * * @param $params * @return \support\Response */ public static function insertDept($params) { try { $data = [ 'dept_category' => self::MEDICAL_DEPT_CATEGORY, 'dept_name' => $params['dept_name'], 'dept_status' => $params['dept_status'] ?? 'ACTIVED', 'dept_addtimes' => time() ]; $deptId = SysDept::insertGetId($data); if (!$deptId) { throw new BusinessException('创建医疗团队失败'); } } catch (BusinessException $e) { return json_fail($e->getMessage()); } catch (\Exception $e) { dump($e->getMessage()); return json_fail('创建医疗团队失败'); } return json_success('医疗团队创建成功'); } /** * @Desc 修改医疗团队 * @Author Gorden * @Date 2024/2/21 10:15 * * @param $id * @param $params * @return \support\Response */ public static function updateDept($id, $params) { $dept = SysDept::where('dept_id', $id)->first(); if (!$dept) { return json_fail('医疗团队不存在'); } try { $data = [ 'dept_name' => $params['dept_name'], ]; // 修改失败,异常 if (!SysDept::where('dept_id', $id)->update($data)) { throw new BusinessException('修改医疗团队失败'); } } catch (BusinessException $e) { return json_fail($e->getMessage()); } catch (\Exception $e) { return json_fail('修改医疗团队失败'); } return json_success('修改医疗团队成功'); } /** * @Desc 修改医疗团队状态 * @Author Gorden * @Date 2024/2/21 10:41 * * @param $id * @param $status * @return \support\Response */ public static function updateStatus($id, $status) { try { if (!SysDept::where('dept_id', $id)->update(['dept_status' => $status])) { throw new \Exception('医疗团队状态修改失败'); } } catch (\Exception $e) { return json_fail('医疗团队状态修改失败'); } return json_success('医疗团队状态修改成功'); } /** * @Desc 删除医疗团队 * @Author Gorden * @Date 2024/2/21 10:48 * * @param $id * @return \support\Response */ public static function delDept(Request $request) { $ids = $request->post('dept_id'); if (!$ids) { return json_fail("数据错误"); } try { if (is_array($ids)) { SysDept::whereIn('dept_id', $ids)->delete(); } else { SysDept::where('dept_id', $ids)->delete(); } } catch (\Exception $e) { return json_fail('删除医疗团队失败'); } return json_success('删除医疗团队成功'); } /** * @Desc 检查医疗团队是否存在 * @Author Gorden * @Date 2024/2/21 13:37 * * @param $deptId * @return bool */ public static function checkDeptExist($deptId) { return SysDept::where('dept_id', $deptId)->exists(); } }