extra('IGNORE')->insert([ 'request_key' => $key, 'actor_id' => $actorId, 'request_hash' => $hash, 'prescription_id' => 0, 'created_at' => time(), ]); } $row = Db::name('prescription_ai_request')->where('request_key', $key)->lock($reserve)->find(); if (!$row) { return null; } if ((int) $row['actor_id'] !== $actorId || !hash_equals($row['request_hash'], $hash)) { throw new DomainException('请求标识已用于其他处方内容,请重新保存'); } if ((int) $row['prescription_id'] > 0) { $exists = Db::name('tcm_prescription')->where('id', $row['prescription_id']) ->where('creator_id', $actorId)->whereNull('delete_time')->count(); if (!$exists) { throw new DomainException('此保存请求对应处方已删除,请重新开方'); } return (int) $row['prescription_id']; } return null; } public static function complete(array $params, int $actorId, int $prescriptionId): void { $key = self::key($params, $actorId); if ($key !== null) { Db::name('prescription_ai_request')->where('request_key', $key)->update(['prescription_id' => $prescriptionId]); } } }