'integer', 'create_time' => 'timestamp', 'update_time' => 'timestamp' ]; /** * 根据住院号获取记录 * @param string $zyh * @return array */ public static function getByZyh(string $zyh): array { return self::where('zyh', $zyh)->select()->toArray(); } /** * 根据类型获取记录 * @param string $tag * @return array */ public static function getByTag(string $tag): array { return self::where('tag', $tag)->select()->toArray(); } /** * 根据科室代码获取记录 * @param string $ksdm * @return array */ public static function getByKsdm(string $ksdm): array { return self::where('ksdm', $ksdm)->select()->toArray(); } /** * 根据员工代码获取记录 * @param string $ygdm * @return array */ public static function getByYgdm(string $ygdm): array { return self::where('ygdm', $ygdm)->select()->toArray(); } /** * 添加记录 * @param array $data * @return bool */ public static function addRecord(array $data): bool { $model = new self(); return $model->save($data); } /** * 更新记录 * @param int $id * @param array $data * @return bool */ public static function updateRecord(int $id, array $data): bool { return self::where('id', $id)->update($data); } /** * 删除记录 * @param int $id * @return bool */ public static function deleteRecord(int $id): bool { return self::where('id', $id)->delete(); } /** * 根据住院号和类型更新或插入记录 * @param string $zyh 住院号 * @param string $tag 类型 * @param array $data 更新或插入的数据 * @return bool */ public static function updateOrInsert(string $zyh, string $tag, array $data): bool { // 查找是否存在记录 $record = self::where([ 'zyh' => $zyh, 'tag' => $tag ])->find(); if ($record) { // 存在则更新 return $record->save(array_merge($data, [ 'zyh' => $zyh, 'tag' => $tag ])); } else { // 不存在则插入 $model = new self(); return $model->save(array_merge($data, [ 'zyh' => $zyh, 'tag' => $tag ])); } } }